示例#1
0
 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');
 }
示例#2
0
文件: Job.php 项目: guysyml/software
 /**
  * Cron task
  *
  * @param array $args
  *
  * @return void
  */
 public function cron_run($args)
 {
     if (false !== get_transient('my-wp-backup-running')) {
         error_log(__('A job is already running', 'my-wp-backup'));
         return;
     }
     $id = $args[0];
     $uniqid = $args[1];
     $is_verbose = isset($args[2]) ? $args[2] : false;
     $job = self::get($id);
     $job->is_verbose = $is_verbose;
     $job['uniqid'] = $uniqid;
     try {
         $options = get_site_option('my-wp-backup-options', Admin::$options);
         set_time_limit($options['time_limit']);
         $job->running($uniqid);
         $files = array();
         $job->log(__('Performing full backup', 'my-wp-backup'));
         $sql = new ExportFile($job);
         $archive = new Archive($job);
         // Export database into wp directory.
         $sql->export();
         set_transient('my-wp-backup-running', $job->toArray(), 0);
         // Create a list of files to be backed up.
         // This excludes unchanged files if the backup is differential.
         $job->do_files($files);
         // Create an archive.
         $archive->create();
         // Upload all created archives.
         $job->upload();
         // Deleted sql file from wp directory.
         $sql->delete();
         // Commit the backup information into file.
         $job->finish();
         // Send reports.
         $job->report();
     } catch (\Exception $e) {
         $job->log($e->getMessage(), 'error');
         error_log($e);
     }
     delete_transient('my-wp-backup-running');
     set_transient('my-wp-backup-finished', $uniqid, 0);
     $job->log(sprintf(__('Finished running job in %.1f seconds.', 'my-wp-backup'), (null === $job->end ? time() : $job->end) - $job->start));
 }