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(); }
private static function init($config) { //创建备份目录 is_dir(self::$dir) or Dir::create(self::$dir); self::$config = array(); //没有设置表时,备份当前库所有表 if (empty($config['table'])) { $info = M()->getTableInfo(); $config['table'] = array(); if (empty($info['table'])) { if (DEBUG) { halt('数据库中没有任何表用于备份'); } else { return false; } } foreach ($info['table'] as $t => $v) { $config['table'][] = $t; } } else { if (is_string($config['table'])) { //只备份一张表时,转为数组格式 $config['table'] = array($config['table']); } } //分卷大小,单位kb if (!isset($config['size'])) { $config['size'] = 200; } //备份成功后的跳转url $config['url'] = isset($config['url']) ? $config['url'] : ''; //数据库 $config['database'] = isset($config['database']) ? $config['database'] : C('DB_DATABASE'); foreach ($config['table'] as $table) { $info = M()->getTableInfo(array($table)); self::$config[$table] = array(); //共有行数 self::$config[$table]["row"] = $info['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'] = isset($config['step_time']) ? $config['step_time'] * 1000 : 200; self::$config[$table]['database'] = $config['database']; } self::update_config_file(); }
private static function init($config) { //创建备份目录 is_dir(self::$dir) or Dir::create(self::$dir); //检测目录 if (!is_dir(self::$dir)) { return false; } //所有表信息 $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; } } //分卷大小,单位kb if (!isset($config['size'])) { $config['size'] = 200; } //备份成功后的跳转url $config['url'] = isset($config['url']) ? $config['url'] : ''; //数据库 $config['database'] = isset($config['database']) ? $config['database'] : C('DB_DATABASE'); 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'] = isset($config['step_time']) ? $config['step_time'] * 1000 : 200; self::$config[$table]['database'] = $config['database']; } return self::update_config_file(); }
private static function init($args) { C("URL_TYPE", 2); $dir = isset($_GET['hdphp_bakdir']) ? str_replace("@@", "/", urldecode($_GET['hdphp_bakdir'])) : (isset($args['dir']) && !empty($args['dir']) ? $args['dir'] : C("DB_BACKUP")); //备份目录 if (!$dir || !dir_create($dir)) { throw_exception("备份目录不存在或创建失败"); } if (!isset($args['url']) || empty($args['url'])) { throw_exception("必须指定备份或恢复完成后的跳转URL"); } $configFile = $dir . '/Config.php'; if (is_file($configFile)) { self::$config = (include $configFile); } else { $config['type'] = isset($args['type']) && in_array(strtolower($args["type"]), array("row", "file")) ? $args['type'] : "row"; $config['db_name'] = isset($args['db_name']) ? $args['db_name'] : C("DB_DATABASE"); //备份的数据库 $config['row'] = isset($args['row']) ? $args['row'] : 200; //每次备份条数 $config['msg'] = isset($args['msg']) ? $args['msg'] : '后盾网 人人做后盾'; //备注内容 $backTables = null; //备份的表 if (isset($args['table'])) { if (!is_array($args['table'])) { error("备份表时的参数table必须为数组"); } $backTables = $args['table']; //需要备份的表 } C("DB_DATABASE", $config['db_name']); //设置数据库 $db = M(); $databaseInfo = $db->getTableInfo(); //所有表信息 $tableAll = array_keys($databaseInfo['table']); //库中所有表名 //没有传参备份所有表 if (is_null($backTables)) { $backTables = $tableAll; } $tableConfig = array(); foreach ($backTables as $table) { if (in_array($table, $tableAll)) { $tableConfig[$table]['totalfiles'] = 0; //文件总数 $tableConfig[$table]['totalrows'] = $databaseInfo['table'][$table]['rows'] * 1; //文件总数 } } $config['table'] = $tableConfig; file_put_contents($configFile, "<?php if(!defined('HDPHP_PATH'))EXIT;\nreturn " . var_export($config, true) . ";\n?>"); self::$config = $config; } self::$config['url'] = U($args['url']); self::$config['step_time'] = isset($args['step_time']) ? $args['step_time'] : 1; //备份间隔时间 self::$config['dir'] = $dir; }