/** * Run step. * * @param int $step * * @return bool */ public function runStep($step) { // Get settings $settings = $this->getSettings(); // Backup? if ($settings->backup && !$step) { // Do the backup $backup = new DbBackup(); $this->backupFile = $backup->run(); } // Open file $data = craft()->import->data($settings->file); // On start if (!$step) { // Fire an "onImportStart" event $event = new Event($this, array('settings' => $settings)); craft()->import->onImportStart($event); } // Check if row exists if (isset($data[$step])) { // Import row craft()->import->row($step, $data[$step], $settings); } // When finished if ($step == $settings->rows - 1) { // Finish craft()->import->finish($settings, $this->backupFile); // Fire an "onImportFinish" event $event = new Event($this, array('settings' => $settings)); craft()->import->onImportFinish($event); } return true; }
/** * @return bool|string */ public function backup() { $backup = new DbBackup(); if (($backupFile = $backup->run()) !== false) { return $backupFile; } return false; }
/** * Performs a database backup. * * @param array|null $ignoreDataTables If set to an empty array, a full database backup will be performed. If set * to an array or database table names, they will get merged with the default * list of table names whose data is to be ignored during a database backup. * * @return bool|string The file path to the database backup, or false if something went wrong. */ public function backup($ignoreDataTables = null) { $backup = new DbBackup(); if ($ignoreDataTables !== null) { $backup->setIgnoreDataTables($ignoreDataTables); } if (($backupFile = $backup->run()) !== false) { return $backupFile; } return false; }
/** * Rolls back any changes made to the DB during the update process. * * @param $backupPath * * @return null */ public static function rollBackDatabaseChanges($backupPath) { $dbBackup = new DbBackup(); $fileName = $backupPath . '.sql'; $fullBackupPath = craft()->path->getDbBackupPath() . $fileName; if (PathHelper::ensurePathIsContained($fileName)) { $dbBackup->restore($fullBackupPath); } else { Craft::log('Someone tried to restore a database from outside of the Craft backups folder: ' . $fullBackupPath, LogLevel::Warning); } }
/** * Performs a database backup. * * @param array|null $ignoreDataTables If set to an empty array, a full database backup will be performed. If set * to an array or database table names, they will get merged with the default * list of table names whose data is to be ignored during a database backup. * * @return bool|string The file path to the database backup, or false if something went wrong. */ public function backup($ignoreDataTables = null) { $backup = new DbBackup(); if ($ignoreDataTables !== null) { $backup->setIgnoreDataTables($ignoreDataTables); } if (($backupFile = $backup->run()) !== false) { // Fire an 'onBackup' event $this->onBackup(new Event($this, array('filePath' => $backupFile))); return $backupFile; } return false; }
/** * Rolls back any changes made to the DB during the update process. * * @param $backupPath * * @return null */ public static function rollBackDatabaseChanges($backupPath) { $dbBackup = new DbBackup(); $fullBackupPath = craft()->path->getDbBackupPath() . $backupPath . '.sql'; $dbBackup->restore($fullBackupPath); }
$dbBackupObj = new DbBackup($config); $dbBackupObj->executeBackup(); /* * Example 2: Extended Backup */ try { $dbBackupObj = new DbBackup($config); $dbBackupObj->setBackupDirectory('backups/extendedExample'); //CustomFolderName $dbBackupObj->setDumpType(0); //To disable the single table files dumping (1 Dump file for the whole database) $dbBackupObj->excludeTable('table1Name', 'tabel2Name', 'table3Name'); //Exclude few tables from your backup execution $dbBackupObj->addDumpOption('--xml', '--force'); //Add few custom options to your backup execution $dbBackupObj->enableS3Support($amazonConfig); //Transfer your backup files to Amazon S3 Storage $dbBackupObj->executeBackup(); //Start the actual backup process using the user specified settings and options } catch (Exception $e) { echo $e->getMessage(); } /* * Example 3: Very Basic Restore Database Example */ try { $dbBackupObj = new DbBackup($config); $dbBackupObj->executeRestore(); } catch (Exception $e) { echo $e->getMessage(); }
else { if($HTTP_POST_FILES["dump"]["error"]!=0) { $error = true; $message = "Erreur lors de l'upload du fichier !"; }else { if($HTTP_POST_FILES["dump"]["name"]!="backup.sql") { $error = true; $message = "Le fichier ne porte pas le nom backup.sql.<br /><br />Si vous avez modifié le nom du fichier, merci de le renommer en \"backup.sql\".<br />Si ce fichier n'est pas issu du système de sauvegarde du e-shop vous risquez d'endommager irrémédiablement l'application.<br /><br /><a href=\"./index.php?module=mod_backup&action=restoredb\">Retour</a>"; } else { $restoredb = new DbBackup(); // call the function which restore the DB $restoredb->Restoredb($HTTP_POST_FILES["dump"]["tmp_name"]); $message = "La base de données a été restaurée avec succès !"; $error = false; } } } break; default: $error = false; $message = "Choisissez le fichier .sql à restaurer depuis votre disque dur :\n"; $message .= "<br /><br />\n";