コード例 #1
0
 /**
  * Fire the webhook notification on the hmbkp_backup_complete
  *
  * @see  Backup::do_action
  * @param  string $action The action received from the backup
  * @return void
  */
 public function action($action, Backup $backup)
 {
     if ('hmbkp_backup_complete' !== $action || !$this->is_service_active()) {
         return;
     }
     $webhook_url = $this->get_url();
     $file = $backup->get_archive_filepath();
     $download = add_query_arg('hmbkp_download', base64_encode($file), HMBKP_ADMIN_URL);
     $domain = parse_url(home_url(), PHP_URL_HOST) . parse_url(home_url(), PHP_URL_PATH);
     // The backup failed, send a message saying as much
     if (!file_exists($file) && ($errors = array_merge($backup->get_errors(), $backup->get_warnings()))) {
         $error_message = '';
         foreach ($errors as $error_set) {
             $error_message .= implode("\n - ", $error_set);
         }
         if ($error_message) {
             $error_message = ' - ' . $error_message;
         }
         $subject = sprintf(__('Backup of %s Failed', 'backupwordpress'), $domain);
         $body = array('type' => 'backup.error', 'site_url' => site_url(), 'backup' => array('id' => 'backup_' . pathinfo($file, PATHINFO_FILENAME), 'start' => '0', 'end' => '0', 'download_url' => '', 'type' => $this->schedule->get_type(), 'status' => array('message' => $subject . ' - ' . $error_message, 'success' => '0')));
     } else {
         $body = array('type' => 'backup.success', 'site_url' => site_url(), 'backup' => array('id' => 'backup_' . $this->schedule->get_id(), 'start' => '0', 'end' => '0', 'download_url' => $download, 'type' => $this->schedule->get_type(), 'status' => array('message' => 'Backup complete', 'success' => '1')));
     }
     $signature = hash_hmac('sha1', serialize($body), $this->get_secret_key());
     $webhook_args = array('headers' => array('X-BWP-Signature' => $signature), 'body' => $body);
     $ret = wp_remote_post($webhook_url, $webhook_args);
     if (is_wp_error($ret)) {
         $backup->error('Webhook', sprintf(__('Error: %s', 'backupwordpress'), $ret->get_error_message()));
     }
 }
コード例 #2
0
ファイル: Backup.class.php プロジェクト: lililishuang/hdcms
 public static function recovery($option)
 {
     if (!Q('status')) {
         F('backupDir', null);
     }
     if (!F('backupDir')) {
         F('backupDir', $option['dir']);
     }
     $dir = F('backupDir');
     //检测目录是否存在
     if (!is_dir($dir)) {
         F('backupDir', null);
         self::$error = '数据目录不存在';
         if (DEBUG) {
             halt(self::$error);
         }
         return false;
     }
     self::$config = (require $dir . '/config.php');
     //文件id
     $fid = Q("get.bid", null, "intval");
     //表前缀
     $db = M();
     $db_prefix = C("DB_PREFIX");
     //首次执行还原操作
     if (is_null($fid)) {
         //还原表结构
         if (is_file($dir . '/structure.php')) {
             require $dir . '/structure.php';
         }
         $url = U(ACTION, array('bid' => 1, 'status' => 'run'));
         return array('status' => 'run', 'message' => '还原数据初始化...', 'url' => $url);
     }
     foreach (glob($dir . '/*') as $d) {
         if (preg_match("@_bk_{$fid}.php\$@i", $d)) {
             require $d;
             $_GET['bid'] += 1;
             $url = U(ACTION, array('bid' => $_GET['bid'], 'status' => 'run'));
             return array('status' => 'run', 'message' => "分卷{$fid}还原完毕!", 'url' => $url);
         }
     }
     return array('status' => 'success', 'message' => "所有分卷还原完毕...");
 }
コード例 #3
0
ファイル: Backup.class.php プロジェクト: suhanyujie/spider
 private static function init($config)
 {
     if (!isset($config['dir'])) {
         self::$error = '请设置备份目录';
         return false;
     } else {
         self::$dir = $config['dir'];
         //缓存备份目录
         F('backupDir', self::$dir);
     }
     //检测目录
     if (!Dir::create(self::$dir)) {
         self::$error = '备份目录创建失败';
         return false;
     }
     //数据库
     if (!isset($config['database'])) {
         $config['database'] = C('DB_DATABASE');
     }
     //分卷大小,单位kb
     if (!isset($config['size'])) {
         $config['size'] = 200;
     }
     //备份时间间隔
     if (isset($config['step_time'])) {
         $config['step_time'] *= 1000;
     } else {
         $config['step_time'] = 200;
     }
     //所有表信息
     $tableInfo = M()->getAllTableInfo();
     self::$config = array();
     //没有设置表时,备份当前库所有表
     if (empty($config['table'])) {
         $config['table'] = array();
         if (empty($tableInfo['table'])) {
             return false;
         }
         foreach ($tableInfo['table'] as $t => $v) {
             $config['table'][] = $t;
         }
     }
     //备份成功后的跳转url
     $config['url'] = isset($config['url']) ? $config['url'] : '';
     foreach ($config['table'] as $table) {
         self::$config[$table] = array();
         //共有行数
         self::$config[$table]["row"] = $tableInfo['table'][$table]['rows'];
         //是否已经备份成功
         self::$config[$table]['success'] = false;
         //当前备份行
         self::$config[$table]['current_row'] = 0;
         self::$config[$table]['size'] = $config['size'] * 1000;
         self::$config[$table]['url'] = $config['url'];
         self::$config[$table]['step_time'] = $config['step_time'];
         self::$config[$table]['database'] = $config['database'];
     }
     return self::update_config_file();
 }
コード例 #4
0
ファイル: Backup.class.php プロジェクト: jyht/v5
 public static function recovery($option)
 {
     //备份目录
     $dir = session("backup_dir") ? session("backup_dir") : $option['dir'];
     //检测目录是否存在
     if (!$dir || !is_dir($dir)) {
         self::$error = '数据目录不存在,尝试刷新后重试';
         if (DEBUG) {
             halt('数据目录不存在,请执行session("backup_dir",null)后重试');
         }
         //删除session中记录的目录
         session('backup_dir', null);
         return false;
     }
     session("backup_dir", $dir);
     self::$config = (require $dir . '/config.php');
     //文件id
     $fid = Q("session.backup_fid", NULL, "intval");
     //表前缀
     $db = M();
     $db_prefix = C("DB_PREFIX");
     //首次执行还原操作
     if (is_null($fid)) {
         $url = isset($option['url']) ? $option['url'] : '';
         $step_time = (isset($option['step_time']) ? $option['step_time'] : 0.5) * 1000;
         //还原表结构
         if (is_file($dir . '/structure.php')) {
             require $dir . '/structure.php';
         }
         session('backup_fid', 1);
         $html = "<script>setTimeout(function(){location.href='" . __METH__ . "';},{$step_time});</script>";
         $html .= "<html><head><meta charset='utf-8'/></head><body><div style='text-align:center;font-size:14px;margin-top: 50px;'>还原数据初始化...</div>";
         $html .= '</body></html>';
         //还原成功后跳转的url地址
         session('backup_history_url', $url);
         //每次还原间隔时间,默认1秒
         session('backup_step_time', $step_time);
         echo $html;
         exit;
     }
     //每次还原间隔时间,默认1秒
     $step_time = session('backup_step_time');
     foreach (glob($dir . '/*') as $d) {
         if (preg_match("@_bk_{$fid}.php\$@i", $d)) {
             require $d;
             $_SESSION['backup_fid'] += 1;
             $html = "<script>setTimeout(function(){location.href='" . __METH__ . "';},{$step_time});</script>";
             $html .= "<html><head><meta charset='utf-8'/></head><body><div style='text-align:center;font-size:14px;margin-top: 50px;'>分卷{$fid}还原完毕!</div>";
             $html .= "</body></html>";
             echo $html;
             exit;
         }
     }
     $html = "<html><head><meta charset='utf-8'/></head><body><div style='text-align:center;font-size:14px;margin-top: 50px;'>所有分卷还原完毕!";
     //还原成功后跳转地址
     $url = session('backup_history_url');
     //清空SESSION数据
     unset($_SESSION['backup_history_url']);
     unset($_SESSION['backup_step_time']);
     unset($_SESSION['backup_fid']);
     if (!empty($url)) {
         $html .= "<a href='javascript:parent.location.href=\"" . $url . "\"' class='btn'>返回</a>";
     }
     $html .= '</div></body></html>';
     self::success($html);
 }