Exemplo n.º 1
0
 /**
  * 备份
  */
 public function backup()
 {
     if (!IS_GET) {
         $this->error("页面不存在!");
     }
     $dir = Q("get.dir");
     Backup::backup(array("database" => "proxy", 'dir' => ROOT_PATH . 'Backup/Databases/' . $dir, "url" => U("Admin/Databases/index")));
 }
Exemplo n.º 2
0
 public function backup_db()
 {
     $result = Backup::backup(array('size' => Q("size", 2000000, "intval"), 'dir' => APP_PATH . 'backup/' . date("Ymdhis"), 'table' => Q('table'), 'structure' => Q('structure', 0)));
     if ($result['status'] == 'success') {
         $this->success($result['message'], U('index', array('app' => 'Addon')));
     } else {
         $this->success($result['message'], $result['url'], 0.2);
     }
 }
Exemplo n.º 3
0
 /**
  * 数据库备份
  * @return [type] [description]
  */
 public function backup()
 {
     $result = Backup::backup(array("size" => 200, "dir" => C("DB_BACKUP") . date("Ymdhis")));
     if ($result['status'] == 'success') {
         $this->success($result['message'], U('index'));
     } else {
         $this->success($result['message'], $result['url'], 0.2);
     }
 }
Exemplo n.º 4
0
 /**
  * 执行数据备份
  */
 public function backup_db()
 {
     $size = Q("size", 2000000, "intval");
     $table = Q("post.table");
     //备份表结构
     $structure = Q("post.structure", false);
     $result = Backup::backup(array("size" => $size, "table" => $table, "structure" => $structure, "dir" => "./data/" . C("BACKUP_DIR") . '/' . date("Ymdhis")));
     if ($result['state'] == 'success') {
         $this->success($result['message'], U('index'));
     } else {
         $this->success($result['message'], $result['url'], 0.2);
     }
 }
Exemplo n.º 5
0
 public function backup_db()
 {
     $result = Backup::backup(array('size' => 200, 'structure' => false, 'dir' => 'Backup/' . date("Ymdhis") . '/', 'step_time' => 1));
     if ($result === false) {
         //备份发生错误
         $this->error(Backup::$error, addon_url('index'));
     } else {
         if ($result['status'] == 'success') {
             //备份完成
             $this->success($result['message'], addon_url('index'));
         } else {
             //备份过程中
             $this->success($result['message'], $result['url'], 0.2);
         }
     }
 }
Exemplo n.º 6
0
 public function runBackup()
 {
     Backup::backup();
 }
Exemplo n.º 7
0
 public function backup()
 {
     if (!$this->accessAdminPage(3)) {
         return new ActionResult($this, '/admin/modules/', 1, 'You are not allowed to do that', B_T_FAIL);
     }
     $backups = WebApp::post('backups') === NULL ? array() : strgetcsv(WebApp::post('backups'));
     if (count($backups) == 0) {
         $backups = WebApp::get('m') === NULL ? array() : array(WebApp::get('m'));
     }
     if (count($backups) == 0) {
         return new ActionResult($this, '/admin/modules/backup', 0, 'No module(s) were selected!', B_T_FAIL);
     }
     foreach ($backups as $backup) {
         $validated = GUMP::is_valid(array('bk' => $backup), array('bk' => 'integer'));
         if ($validated !== true) {
             return new ActionResult($this, '/admin/modules/backup', 0, 'No module(s) were selected!', B_T_FAIL);
         }
     }
     $location = __BACKUP__ . DIRECTORY_SEPARATOR . date(DATET_BKUP) . DIRECTORY_SEPARATOR;
     require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'resources' . DIRECTORY_SEPARATOR . 'backup.php';
     $result = array();
     foreach ($backups as $module) {
         $backup = new Backup($this->parent);
         if (!$backup->setLocation($location)) {
             return new CronResult($this, false, 'Failed to create backup dir: ' . DIRECTORY_SEPARATOR . 'backup' . str_replace(__BACKUP__, '', $location . $module));
         }
         if (!$backup->setID($module)) {
             return new CronResult($this, false, 'Failed to setID for ' . $module);
         }
         $results[$module] = $backup->backup();
         unset($backup);
     }
     $msg = '';
     $status = true;
     foreach ($results as $ns => $data) {
         $msg .= '"' . $ns . '": ' . $data['msg'] . PHP_EOL;
         if (!$data['s']) {
             $status = false;
         }
     }
     if ($status) {
         $msg = 'Backup was completed for selected module(s)!';
         $type = B_T_SUCCESS;
     } else {
         $msg = 'Backup was completed but failed for some/all module(s). Details as follows:' . PHP_EOL . $msg;
         $type = B_T_WARNING;
     }
     $this->parent->parent->logEvent($this::name_space, 'Back up modules: ' . csvgetstr($backups));
     return new ActionResult($this, '/admin/modules/backup', 1, $msg, $type);
 }
 /**
  * Perform a Backup.
  *
  * ## OPTIONS
  *
  * [--files_only]
  * : Backup files only, default to off
  *
  * [--database_only]
  * : Backup database only, defaults to off
  *
  * [--destination]
  * : dir that the backup should be save in, defaults to your existing backups directory
  *
  * [--root]
  * : dir that should be backed up, defaults to site root.
  *
  * [--zip_command_path]
  * : path to your zip binary, standard locations are automatically used
  *
  * [--mysqldump_command_path]
  * : path to your mysqldump binary, standard locations are automatically used
  *
  * [--archive_filename]
  * : filename for the resulting zip file
  *
  * [--excludes]
  * : list of paths you'd like to exclude
  *
  * ## Usage
  *
  *     wp backupwordpress backup [--files_only] [--database_only] [--path<dir>] [--root<dir>] [--zip_command_path=<path>] [--mysqldump_command_path=<path>]
  *
  * @todo errors should be bubbled from Backup, Scheduled_Backup and the like instead of being repeated.
  */
 public function backup($args, $assoc_args)
 {
     add_action('hmbkp_mysqldump_started', function () {
         WP_CLI::line(__('Backup: Dumping database...', 'backupwordpress'));
     });
     add_action('hmbkp_archive_started', function () {
         WP_CLI::line(__('Backup: Zipping everything up...', 'backupwordpress'));
     });
     $hm_backup = new Backup();
     if (!empty($assoc_args['destination'])) {
         Path::get_instance()->set_path($assoc_args['destination']);
     }
     Path::get_instance()->cleanup();
     if (!empty($assoc_args['root'])) {
         $hm_backup->set_root($assoc_args['root']);
     }
     if (!is_dir(hmbkp_path())) {
         WP_CLI::error(__('Invalid backup path', 'backupwordpress'));
         return false;
     }
     if (!is_dir($hm_backup->get_root()) || !is_readable($hm_backup->get_root())) {
         WP_CLI::error(__('Invalid root path', 'backupwordpress'));
         return false;
     }
     if (isset($assoc_args['archive_filename'])) {
         $hm_backup->set_archive_filename($assoc_args['archive_filename']);
     }
     if (!empty($assoc_args['files_only'])) {
         $hm_backup->set_type('file');
     }
     if (!empty($assoc_args['database_only'])) {
         $hm_backup->set_type('database');
     }
     if (isset($assoc_args['mysqldump_command_path'])) {
         $hm_backup->set_mysqldump_command_path($assoc_args['mysqldump_command_path']);
     }
     if (isset($assoc_args['zip_command_path'])) {
         $hm_backup->set_zip_command_path($assoc_args['zip_command_path']);
     }
     if (!empty($assoc_args['excludes'])) {
         $hm_backup->set_excludes($assoc_args['excludes']);
     }
     $hm_backup->backup();
     if (file_exists($hm_backup->get_archive_filepath())) {
         WP_CLI::success(__('Backup Complete: ', 'backupwordpress') . $hm_backup->get_archive_filepath());
     } else {
         WP_CLI::error(__('Backup Failed', 'backupwordpress'));
     }
 }
Exemplo n.º 9
0
 public function backup()
 {
     $url = U("Recovery/index");
     Backup::backup(array('url' => $url, 'size' => Q("size", null, 'intval'), 'step_time' => Q('step_time', null, 'intval')));
 }