/** * @param Job $job * * @throws \Exception * */ public function __construct(Job $job) { $this->job = $job; $this->backup = $job->get_backup(); switch ($job['compression']) { case 'zip': $this->extension = 'zip'; $this->format = 'zip'; $this->compression = Pharchive::COMPRESS_NONE; break; case 'tar': $this->extension = 'tar'; $this->format = 'tar'; $this->compression = Pharchive::COMPRESS_NONE; break; case 'gz': $this->extension = 'tar.gz'; $this->format = 'tar'; $this->compression = Pharchive::COMPRESS_GZIP; break; case 'bz2': $this->extension = 'tar.bz2'; $this->format = 'tar'; $this->compression = Pharchive::COMPRESS_BZIP; break; default: throw new \Exception('Unknown compression: ' . $job['compression']); } $this->password = $job['password']; $this->split_size = $job['volsize'] > 0 ? $job['volsize'] * 1024 * 1024 : 0; if (!is_null($this->backup)) { $this->archives = $this->backup->get_archives(); } }
/** * @param array $db_options * * @param Job $job * * @return Native|Shell */ static function create(array $db_options, Job $job) { $db = Connection::create($db_options); $db->connect(); if (self::has_shell_access() && self::is_shell_command_available('mysqldump')) { $dumper = new Shell($db, $job); $job->log(__('Using mysqldump.', 'my-wp-backup'), 'debug'); } else { $dumper = new Native($db, $job); $job->log(__('Using native dumper.', 'my-wp-backup'), 'debug'); } if (isset($db_options['include_tables'])) { $dumper->include_tables = $db_options['include_tables']; } if (isset($db_options['exclude_tables'])) { $dumper->exclude_tables = $db_options['exclude_tables']; } return $dumper; }
public function cron_run($args) { list($id, $uniqid, $method) = $args; $is_verbose = isset($args[3]) ? $args[3] : false; $options = get_site_option('my-wp-backup-options', Admin::$options); set_time_limit($options['time_limit']); $this->maintenance(); $backup = self::get($id, $uniqid); $job = new JobModel($backup, true); $job->is_verbose = $is_verbose; $job->running($backup['uniqid']); $job->log(__('Restoring...', 'my-wp-backup')); if ('local' === $method && !$backup->has_archives()) { $job->log(__('No local copy of the backup is available.', 'my-wp-backup')); } try { $job->download($method); $archive = new Archive($job); // Joins the file if backup has been split into smaller files. // Uncompresses the file if compressed with bz2 or gz. $archive->pre_restore(); $archive->restore(); if ($job['volsize'] > 0) { unlink(reset($archive->get_archives())); } $job->log(__('Importing database file...', 'my-wp-backup')); $sql = new ExportFile($job); $sql->import(); $sql->delete(); $job->log(__('Ok.', 'my-wp-backup')); $job->finish(); $job->log(__('Done restoring.', 'my-wp-backup')); $job->log(sprintf(__('Finished restoring backup in %.1f seconds.', 'my-wp-backup'), $job->end - $job->start)); } catch (\Exception $e) { error_log($e); $job->log($e->getMessage(), 'error'); } $this->maintenance('off'); }
public function __construct(Job $job) { $this->job = $job; $this->filePath = null === $job->get_backup() ? tempnam(sys_get_temp_dir(), 'my-wp-backup-export') : MyWPBackup::$info['root_dir'] . self::FILENAME; $job->set_dbpath($this->filePath); }