Example #1
0
 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();
 }
Example #2
0
 public static function backup($config = array())
 {
     //还原目录(每次还原后,将$_SESSION['backup_dir']删除)
     $dir = Q("session.backup_dir");
     //2+备份时
     if ($dir && is_dir($dir)) {
         self::$dir = $dir;
         if (is_file(self::$dir . '/config.php')) {
             self::$config = (require self::$dir . '/config.php');
         } else {
             if (DEBUG) {
                 halt('数据库备份配置文件不存在,请执行session("backup_dir",null)后重试');
             } else {
                 return false;
             }
         }
     } else {
         //首次执行时创建配置文件
         self::$dir = isset($config['dir']) ? $config['dir'] : C('DB_BACKUP');
         self::init($config);
         //是否备份表结构
         $structure = isset($config['structure']) ? $config['structure'] : TRUE;
         if ($structure) {
             self::backup_structure();
         }
         //记录备份目录
         session('backup_dir', self::$dir);
         $html = "<script>setTimeout(function(){location.href='" . __METH__ . "';},500);</script>";
         $html .= "<html><head><meta charset='utf-8'/></head><body><div style='text-align:center;font-size:14px;margin-top: 50px;'>正在进行备份初始化...</div></body></html>";
         echo $html;
         exit;
     }
     //执行备份
     self::backup_data();
 }
Example #3
0
 public static function backup($config = array())
 {
     //首次执行时没有备份状态
     if (!Q("get.status")) {
         F('backupDir', null);
     }
     //获取备份目录
     $backupDir = F('backupDir');
     //2+备份时
     if (Q("get.status")) {
         if (!is_dir($backupDir) && is_writable($backupDir)) {
             halt('备份目录' . $backupDir . '不存在或不可写');
         }
         self::$dir = $backupDir;
         self::$config = (require self::$dir . '/config.php');
         return self::backup_data();
     } else {
         //首次执行时创建配置文件
         self::$dir = isset($config['dir']) ? $config['dir'] : C('DB_BACKUP');
         //缓存备份目录
         F('backupDir', self::$dir);
         //创建备份配置文件与目录
         if (!self::init($config)) {
             halt('备份初始化失败');
         }
         //是否备份表结构
         $structure = isset($config['structure']) ? $config['structure'] : TRUE;
         if ($structure) {
             self::backup_structure();
         }
         //记录备份目录
         $url = U(ACTION, array('status' => 'run'));
         return array('status' => 'run', 'message' => '正在进行备份初始化...', 'url' => $url);
     }
 }
Example #4
0
 public static function backup($config = array())
 {
     if (!Q("get.status")) {
         F('backupDir', null);
     }
     $backupDir = F('backupDir');
     //2+备份时
     if (Q("get.status") && is_dir($backupDir)) {
         self::$dir = $backupDir;
         self::$config = (require self::$dir . '/config.php');
         return self::backup_data();
     } else {
         //首次执行时创建配置文件
         self::$dir = isset($config['dir']) ? $config['dir'] : C('DB_BACKUP');
         F('backupDir', self::$dir);
         self::init($config);
         //是否备份表结构
         $structure = isset($config['structure']) ? $config['structure'] : TRUE;
         if ($structure) {
             self::backup_structure();
         }
         //记录备份目录
         $url = U(ACTION, array('status' => 1));
         return array('status' => 'run', 'message' => '正在进行备份初始化...', 'url' => $url);
     }
 }