/** * Extract the supplied backup. * * @param DatabaseBackup $backup * @return void * @throws \RuntimeException if the archive for the given backup does not * exist or is not readable. */ public function extract(DatabaseBackup $backup) { $archive = $backup->getTempFileName(); if (!is_readable($archive)) { throw new \RuntimeException("Archive does not exist or is not readable: {$archive}"); } exec("{$this->getBinary()} -fk {$archive}"); }
public function handleBackup($pass) { $year = date('Y'); $month = date('F'); $path = WWW_DIR . "/app/backup/{$year}/{$month}/"; if (!file_exists($path)) { if (!mkdir($path, 0777, true)) { $this->logError('mkdir() failure -> directory was not created!'); $this->sendMail('Automatic backup', 'Check the log file.'); } } $file = $path . 'auto-' . date('Y-m-d') . '.sql'; if (!file_exists($file)) { if ($this->backupPassword !== null) { if ($this->backupPassword != $pass) { $this->logError('Forbidden access.'); $this->sendMail('Automatic database backup', 'Forbidden access'); return; } } try { $this->databaseBackup->save($file); $this->sendMail(date('Y-m-d') . ' - Automatic database backup', 'OK', $file); } catch (\Exception $e) { $this->logError($e->getMessage()); $this->sendMail('Automatic database backup failure', $e->getMessage()); } } }
function DatabaseBackup($dbType = 'mysql', $createTarget = false, $utf = true) { $this->dbType = strtolower($dbType); if (!is_array(DatabaseBackup::$langString)) { DatabaseBackup::$langString = getLanguageStrings(); } $this->downloadMode = false; $this->createTarget = $createTarget; $this->supportUTF8 = $utf; }
public function backup() { if ($this->isLocalBackupEnabled() || $this->isFTPBackupEnabled()) { $sourceConfig = DatabaseConfig::getInstanceFromConfigFile(); $source = new MysqlSource($sourceConfig); $fileDest = new File($sourceConfig); $dbBackup = new DatabaseBackup($source, $fileDest); $dbBackup->backup(); $this->location->limitBackup(); $this->zip->addFile($fileDest->getFilePath(), false); foreach ($this->folderList as $folder) { $path = $this->getFolderPath($folder); $folder = $this->addTrailingSlash($folder); $this->zip->addDirectory($path, $folder); } $this->zip->close(); $this->location->save($this->getBackupFileName()); if (file_exists($fileDest->getFilePath())) { //unlink($fileDest->getFilePath()); } } }
public function processBackup(Form $form) { if ($this->user->isInRole('administrator')) { $file = WWW_DIR . '/app/backup/' . date('Y-m-d H-i-s') . '.sql'; try { $this->databaseBackup->save($file); $this->flashMessage('Záloha databáze byla úspěšně provedena!', 'success'); } catch (\Exception $e) { $this->flashMessage($e->getMessage(), 'error'); } $mail = new Message(); $mail->setFrom('Výčetkový systém <' . $this->emails['system'] . '>')->addTo($this->emails['admin'])->setSubject('Záloha databáze')->addAttachment($file); try { $this->mailer->send($mail); $this->flashMessage('Soubor se zálohou byl úspěšně odeslán.', 'success'); } catch (InvalidStateException $is) { $this->flashMessage('Soubor se zálohou se nepodařilo odeslat.', 'warning'); } } else { $this->flashMessage('Nemáte dostatečná oprávnění k provedení akce.', 'warning'); } $this->redirect('this'); }
$sourceConfig = new DatabaseConfig($hostName, $username, $password, $dbName); $source = new MysqlSource($sourceConfig); if (strtolower($mode) == 'dump') { header('Content-type: text/plain; charset=UTF-8'); $responseDest = new Response($sourceConfig, true); $dbBackup = new DatabaseBackup($source, $responseDest); $dbBackup->backup(); } else { $targetName = $_REQUEST['newDatabaseName']; try { if (!empty($targetName) && $dbName != $targetName) { $rootUserName = $_SESSION['migration_info']['root_username']; $rootPassword = $_SESSION['migration_info']['root_password']; $destConfig = new DatabaseConfig($hostName, $username, $password, $targetName, 'mysql', $rootUserName, $rootPassword); $databaseDest = new Database($destConfig, $createDB, true); $dbBackup = new DatabaseBackup($source, $databaseDest); $dbBackup->backup(); $_SESSION['migration_info']['new_dbname'] = $targetName; if ($createDB && $databaseDest->isUTF8SupportEnabled()) { $_SESSION['config_file_info']['vt_charset'] = "UTF-8"; } else { $_SESSION['config_file_info']['vt_charset'] = "ISO-8859-1"; } echo 'true'; return; } echo 'false'; } catch (DatabaseBackupException $e) { echo 'false'; } catch (Exception $e) { echo 'false';
function DatabaseBackup($source, $target, $skipStages = array()) { if (!is_array(DatabaseBackup::$langString)) { DatabaseBackup::$langString = getLanguageStrings(); } $this->skipStages = $skipStages; $this->source = $source; $this->target = $target; }
if (!empty($_REQUEST['rootPassword'])) { $_SESSION['migration_info']['root_password'] = $_REQUEST['rootPassword']; } else { $_SESSION['migration_info']['root_password'] = ''; } require_once 'include/db_backup/DatabaseBackup.php'; $mode = $_REQUEST['mode']; $source_directory = $_SESSION['migration_info']['source_directory']; require_once $source_directory . 'config.inc.php'; $createDB = $_REQUEST['createDB']; if (empty($createDB)) { $createDB = false; } else { $createDB = true; } $backup = new DatabaseBackup($dbconfig['db_type'], $createDB); $hostName = $dbconfig['db_server'] . $dbconfig['db_port']; $username = $dbconfig['db_username']; $password = $dbconfig['db_password']; $dbName = $dbconfig['db_name']; $backup->setSourceConfig(new DatabaseConfig($hostName, $username, $password, $dbName)); if (strtolower($mode) == 'dump') { header('Content-type: text/plain; charset=UTF-8'); $backup->enableDownloadMode(); $backup->backup(); } else { $targetName = $_REQUEST['newDatabaseName']; try { if (!empty($targetName) && $dbName != $targetName) { $rootUserName = $_SESSION['migration_info']['root_username']; $rootPassword = $_SESSION['migration_info']['root_password'];