{@inheritDoc}
@see \n2n\persistence\meta\Database::createBackuper()
@return Backuper
435857
public function createBackuper(array $metaEnities = null): Backuper {
		return new SqliteBackuper($this->dbh, $this->createDatabase(), $metaEnities);
	}
1026657
public function create(array $options = [])
    {
        $options = $this->resolveOptions($options);

        if (!$options[self::OPTION_ENABLE]) {
            return new NullProfiler();
        }

        if ($options[self::OPTION_ENVIRONMENT] !== null) {
            Profiler::$environment = $options[self::OPTION_ENVIRONMENT];
        }

        $profiler = new Profiler();

        switch ($options[self::OPTION_DATASOURCE_CLASS]) {
            default:
            case File::class:
                $datasource = new File($options[self::OPTION_DATASOURCE_PROFILES_FOLDER]);
                break;
            case Memory::class:
                $datasource = new Memory();
        }

        $profiler->setDataSource($datasource);
        $profiler->registerCollectorClasses($options[self::OPTION_COLLECTORS]);

        $dispatcher = $profiler->getContext()->getProcess()->getDispatcher();
        $className = $options['logger'];
        $logger = new $className();
        $logger->setDispatcher($dispatcher);
        $profiler->setLogger($logger);

        $profiler->setTimeline(new TimelineComponent($dispatcher));

        return $profiler;
    }
355043
public function getBackup($name = null)
    {
        $name = is_null($name) ? 'default' : $name;

        if ( ! $this->backupExists($name)) {
            throw new \Intervention\Image\Exception\RuntimeException(
                "Backup with name ({$name}) not available. Call backup() before reset()."
            );
        }

        return $this->backups[$name];
    }
246877
public function createBackup()
    {
        $this->output->outputLine();

        if ( !file_exists($this->createFilePath([$this->localBackupTarget, 'key'])) ) {
            $this->output->outputLine('<b>You don\'t have a keyfile!</b>');
            $this->output->outputLine();
            $this->output->outputLine('Call \'./flow backup:key\' to to generate it.');
            $this->output->outputLine();
            return;
        }

        $this->output->outputLine('<b>Prepare Backup</b>');
        $this->output->outputLine();

        $this->emitBackupStarted();
        $newVersion = time();

        $stats = array(
            'checked' => 0,
            'added' => 0,
            'updated' => 0,
            'removed' => 0,
        );

        $this->collectSystemSettings();

        $this->dumpDatabase();

        foreach ($this->backupFolders as $folderIndex => $folder) {
            $relativeFolder = $this->getPathByFlowRoot($folder);

            $this->output->outputLine('<b>'.($folderIndex+1).'/'.count($this->backupFolders).' Backup '.$relativeFolder.'</b>');
            $this->output->outputLine();
            $this->output->outputLine('Load Backup Versions..');

            $latestFlatBackup = $this->getFlatBackup($folder);
            $newBackupClean = $this->getBackupActions($folder, $newVersion, $latestFlatBackup);
            $stats['checked'] = $stats['checked'] + count($latestFlatBackup);

            if ( count($newBackupClean)>0 ) {
                // encrypt and create backup..
                $this->files->createDirectoryRecursively($this->createDirectoryPath([$this->localBackupTarget, $newVersion, $relativeFolder]));
                $this->output->outputLine('Backup Files..');
                $this->output->progressStart(count($newBackupClean));
                $i = 0;
                foreach ($newBackupClean as $sha1 => $fileItem) {
                    if ($fileItem['action'] == 'add' || $fileItem['action'] == 'update') {
                        if ($fileItem['action'] == 'add') {
                            $stats['added']++;
                        } else {
                            $stats['updated']++;
                        }

                        $this->cryptService->encryptFileToFile(
                            $this->createFilePath([FLOW_PATH_ROOT, $fileItem['file']]),
                            $this->createFilePath([$this->localBackupTarget, $newVersion, $relativeFolder, $sha1 . '.file']));
                        file_put_contents(
                            $this->createFilePath([$this->localBackupTarget, $newVersion, $relativeFolder, $sha1 . '.meta']),
                            json_encode($fileItem));

                    } else {
                        if ($fileItem['action'] == 'remove') {
                            $stats['removed']++;

                            file_put_contents(
                                $this->createFilePath([$this->localBackupTarget, $newVersion, $relativeFolder, $sha1 . '.meta']),
                                json_encode($fileItem));
                        }
                    }
                    $i++;
                    $this->output->progressSet($i);
                }
                $this->output->progressFinish();
                $this->output->outputLine();
            }
        }

        if ( file_exists($this->createDirectoryPath([$this->localBackupTarget, $newVersion])) ) {
            $this->meta['version'] = $newVersion;
            $now = new \DateTime();
            $this->meta['timestamp'] = $now->getTimestamp();
            $this->meta['stats'] = $stats;
            file_put_contents($this->createFilePath([$this->localBackupTarget, $newVersion, 'info.meta']),
                json_encode($this->meta, JSON_PRETTY_PRINT));
        }

        $this->deleteTempFolders();

        $this->removeOldBackups();

        $this->output->outputLine('<b>Backup Finished</b>');
        $this->output->outputLine(' - Checked: '.$stats['checked']);
        $this->output->outputLine(' - Added:   '.$stats['added']);
        $this->output->outputLine(' - Updated: '.$stats['updated']);
        $this->output->outputLine(' - Removed: '.$stats['removed']);
        $this->output->outputLine();
        $this->emitBackupFinished($this->output, $stats);
        return;
    }
726407
public function createBackuper(array $metaEnities = null): Backuper {
		return new MssqlBackuper($this->dbh, $this->createDatabase(), $metaEnities);
	}
938521
public function createBackup($label, $components)
    {
        if ($this->connector->getURL() === null) {
            return 'Cannot find site URL from configuration.';
        }
        $url = $this->connector->getURL().self::VERSION.$this->connector->getSiteID().'/backup';
        $params = [
            'label' => $label,
            'components' => $components,
        ];

        $response = $this->connector->connecting($url, $params, 'POST');

        // @codingStandardsIgnoreStart
        if (isset($response->task_id)) {
            return $response->task_id;
            // @codingStandardsIgnoreEnd
        }

        return $response;
    }
569064
public static function create()
    {
        $builder = NotifireBuilder::create();

        if (\class_exists('Swift_Mailer')) {
            $transport = new \Swift_SmtpTransport('localhost', 25);
            $mailer = new \Swift_Mailer($transport);

            $handler = new SwiftMailerHandler($mailer, 'default');
            if (\class_exists('Twig_Environment')) {
                $env = new \Twig_Environment(new \Twig_Loader_Filesystem());
                $handler->setTwig($env);
            }

            $builder->addHandler($handler);
            $builder->addNotification('email', Email::class);
        }

        $builder->initialize();
    }
435322
public static function createFrom(
        Storage $persistenceProvider,
        Storage $cacheProvider,
        LoggerInterface $logger = null
    ) {
        /** @var $userAgentHandlerChain \Wurfl\Handlers\Chain\UserAgentHandlerChain */
        $userAgentHandlerChain = $cacheProvider->load('UserAgentHandlerChain');

        if (!($userAgentHandlerChain instanceof UserAgentHandlerChain)) {
            $userAgentHandlerChain = self::init();
            $cacheProvider->save('UserAgentHandlerChain', $userAgentHandlerChain, 3600);
        }

        $userAgentHandlerChain->setLogger($logger);

        foreach ($userAgentHandlerChain->getHandlers() as $handler) {
            /* @var $handler \Wurfl\Handlers\AbstractHandler */
            $handler
                ->setLogger($logger)
                ->setPersistenceProvider($persistenceProvider);
        }

        return $userAgentHandlerChain;
    }
900633
public function backupStructure(): string
	{
		$string = [];

		// Get databases
		$dbs = $this->getDriver()->getDbs();

		foreach($dbs as &$d)
		{
			// Skip built-in dbs
			// @codeCoverageIgnoreStart
			if ($d === 'mysql')
			{
				continue;
			}
			// @codeCoverageIgnoreEnd

			// Get the list of tables
			$tables = $this->getDriver()->driverQuery("SHOW TABLES FROM `{$d}`", TRUE);

			foreach($tables as $table)
			{
				$array = $this->getDriver()->driverQuery("SHOW CREATE TABLE `{$d}`.`{$table}`", FALSE);
				$row = current($array);

				if ( ! isset($row['Create Table']))
				{
					continue;
				}


				$string[] = $row['Create Table'];
			}
		}

		return implode("\n\n", $string);
	}
1295641
public static function slaver()
	{
		static $slaver = null;
		if (is_null($slaver)) $slaver = new SqlSlaver(self::$ds_slaver);
		return $slaver;
	}
1273299
public function backupDatabase(): TempFile
	{
		$this->check();
		$backup = new TempFile('database.sql', true);
		$tables = $this->driver->getTables();

		$backup->write("SET NAMES utf8;\n");
		$backup->write("SET time_zone = '+00:00';\n");
		$backup->write("SET foreign_key_checks = 0;\n");
		$backup->write("SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO';\n\n\n");

		foreach ($tables as $table) {
			if (in_array($table, $this->excludeTables)) {
				continue;
			}
			$backup->write("DROP TABLE IF EXISTS `$table`;\n");

			$createTable = $this->driver->getCreateTable($table);
			$backup->write("$createTable;\n\n");

			$rows = $this->driver->getRows($table);
			$insert = [];
			$columns = null;
			$counter = 0;
			foreach ($rows as $row) {
				$counter++;
				if ($columns === null) {
					$colName = [];
					foreach ($row as $key => $value) {
						$colName[] = "`$key`";
					}
					$columns = implode(', ', $colName);
				}
				$cols = [];
				foreach ($row as $column) {
					if (is_string($column)) {
						$column = addslashes($column);
						$column = preg_replace("/\n/", "\\n", $column);
					} elseif ($column === null) {
						$cols[] = 'NULL';
						continue;
					}
					$cols[] = '"' . $column . '"';
				}
				$insert[] = implode(', ', $cols);

				if ($this->maxRows && $counter >= $this->maxRows) {
					$this->writeInsert($backup, $table, $columns, $insert);
					$counter = 0;
					$insert = [];
				}
			}
			$this->writeInsert($backup, $table, $columns, $insert);
			$backup->write("\n\n");
		}

		return $backup;
	}
172224
public function create() : LoggerInterface
    {
        $loggerType = $this->config['type'] ?? 'null';
        switch ($loggerType) {
            case 'file':
                return new Logger($this->config['path'], $this->config['level']);
            case 'null':
                return new NullLogger;
            default:
                throw new \RuntimeException('Invalid logger type');
        }
    }
361657
public function setBackup($value)
    {
        parent::setBackup($value);
        $this->storage->setBackup($value);

        return $this;
    }
1314319
public function restoreBackup($versionToRestore, $unobtrusive = false)
    {
        $this->output->outputLine();

        if ( !file_exists($this->createFilePath([$this->localBackupTarget, 'key'])) ) {
            $this->output->outputLine('<b>You don\'t have a keyfile!</b>');
            $this->output->outputLine();
            $this->output->outputLine('Call \'./flow backup:key\' to to generate it.');
            $this->output->outputLine();
            return;
        }

        $this->output->outputLine('<b>Check Backup..</b>');
        $this->output->outputLine();

        $this->emitRestoreStarted($versionToRestore);
        $stats = array(
            'restored' => 0,
            'bytes' => 0,
        );

        // DRY RUN FIRST..

        $errors = array();
        foreach ($this->backupFolders as $folder) {
            $relativeFolder = $this->getPathByFlowRoot($folder);

            $this->output->outputLine('Check Backup Versions for ' . $relativeFolder . '..');
            $this->output->outputLine();
            $flatBackup = $this->getFlatBackup($folder, $versionToRestore);

            if ( is_dir($folder) && !is_writable($folder) ) {
                $errors[] = $folder.' is not writable! [1]';
            }else{
                try {
                    $this->files->createDirectoryRecursively($folder);
                    $this->files->removeDirectoryRecursively($folder);
                } catch (Exception $e) {
                    $errors[] = $folder . ' is not writable! [2]';
                }
            }

            $this->output->outputLine('Check Files of '.$relativeFolder.'..');
            $this->output->progressStart(count($flatBackup));
            $i = 0;
            foreach ($flatBackup as $sha1 => $fileItem) {
                try {
                    $content = file_get_contents($this->createFilePath([$this->localBackupTarget, $fileItem['version'], $relativeFolder, $sha1 . '.file']));
                } catch (\Exception $e) {
                    $errors[] = 'file not found '.$this->createFilePath([$this->localBackupTarget, $fileItem['version'], $relativeFolder, $sha1 . '.file']);
                }
                try {
                    $this->cryptService->decrypt($content);
                } catch (\Exception $e) {
                    $errors[] = 'decryption failed for '.$this->createFilePath([$this->localBackupTarget, $fileItem['version'], $relativeFolder, $sha1 . '.file']);
                }

                $i++;
                $this->output->progressSet($i);
            }
            $this->output->progressFinish();
            $this->output->outputLine();
        }

        if (count($errors)>0) {
            $this->output->outputLine('<b>ERROR:</b>');
            foreach ($errors as $error) {
                $this->output->outputLine(' - '.$error);
            }
            $this->output->outputLine();
            $this->output->outputLine('<b>I\'m so sorry!</b>');
            $this->output->outputLine('Hopefully you have another Backup..');
            $this->output->outputLine();
            $this->emitRestoreAborted($this->output);
            return;
        }

        // RUN RESTORE..

        $this->output->outputLine('<b>Restore Backup..</b>');
        $this->output->outputLine();

        foreach ($this->backupFolders as $folder) {
            $relativeFolder = $this->getPathByFlowRoot($folder);

            $this->output->outputLine('Load Backup Versions for ' . $relativeFolder . '..');
            $this->output->outputLine();
            $flatBackup = $this->getFlatBackup($folder, $versionToRestore);

            if ( is_dir($folder) ) {
                $this->files->removeDirectoryRecursively($folder);
            }

            $this->output->outputLine('Restore Files to '.$relativeFolder.'..');
            $this->output->progressStart(count($flatBackup));
            $i = 0;
            foreach ($flatBackup as $sha1 => $fileItem) {
                $this->files->createDirectoryRecursively( dirname($fileItem['file']) );
                $this->cryptService->decryptFileToFile(
                    $this->createFilePath([$this->localBackupTarget, $fileItem['version'], $relativeFolder, $sha1 . '.file']),
                    $this->createFilePath([FLOW_PATH_ROOT, $fileItem['file']]));

                $stats['restored']++;
                $stats['bytes'] = $stats['bytes'] + filesize(FLOW_PATH_ROOT . $fileItem['file']);

                $i++;
                $this->output->progressSet($i);
            }
            $this->output->progressFinish();
            $this->output->outputLine();
        }

        $this->importDatabase();
        $this->restoreSystemSettings();
        $this->deleteTempFolders();

        if ($unobtrusive) {
            $this->output->outputLine('<b>You should execute the following flow commands:</b>');
            $this->output->outputLine();
            $this->output->outputLine(' - composer install');
            $this->output->outputLine(' - ./flow flow:cache:flush');
            $this->output->outputLine(' - ./flow doctrine:migrate');
            $this->output->outputLine(' - ./flow resource:publish');
            $this->output->outputLine(' - ./flow cache:warmup');
        }else {
            $this->output->outputLine('<b>Reinstall..</b>');
            $this->output->outputLine();

            $this->output->outputLine(' - composer install..');
            $this->output->outputLine($this->executeLocalShellCommand('cd ' . FLOW_PATH_ROOT . ' && composer %s',
                ['install']));
            $this->output->outputLine(' - flow:cache:flush..');
            $this->output->outputLine($this->executeLocalShellCommand(FLOW_PATH_ROOT . 'flow flow:cache:flush %s',
                ['--force']));
            $this->output->outputLine(' - doctrine:migrate..');
            $this->output->outputLine($this->executeLocalShellCommand(FLOW_PATH_ROOT . 'flow doctrine:migrate'));
            $this->output->outputLine(' - resource:publish..');
            $this->output->outputLine($this->executeLocalShellCommand(FLOW_PATH_ROOT . 'flow resource:publish'));
            $this->output->outputLine(' - cache:warmup..');
            $this->output->outputLine($this->executeLocalShellCommand(FLOW_PATH_ROOT . 'flow cache:warmup'));
        }

        $this->output->outputLine();
        $this->output->outputLine('<b>Restored ' . $stats['restored'] . ' files</b>');
        $this->output->outputLine(' - with a total of ' . $this->formatBytes($stats['bytes']));
        $this->output->outputLine();

        $this->emitRestoreFinished($this->output, $stats);
        return;
    }
35020
public function getBackup($name = null)
    {
        $name = $name ?? 'default';

        if (!$this->backupExists($name)) {
            throw new \Hail\Image\Exception\RuntimeException(
                "Backup with name ({$name}) not available. Call backup() before reset()."
            );
        }

        return $this->backups[$name];
    }
734289
protected function getDocHelper(): DocHelper
    {
        if ($this->docHelper === null) {
            $this->docHelper = new DocHelper($this->getFile()->getBaseFile(), $this->getStackPos());
        }

        return $this->docHelper;
    }
263483
public function databaseBackup($environmentUuid, $dbName, $backupId)
    {
        return new BackupResponse(
            $this->connector->request(
                'get',
                "/environments/${environmentUuid}/databases/${dbName}/backups/${backupId}",
                $this->query
            )
        );
    }