function backup($dir) { require_once 'DbManage.php'; $db = new DBManage('localhost', 'root', '', 'jianji02test', 'utf8'); // 参数:备份哪个表(可选),备份目录(可选,默认为backup),分卷大小(可选,默认2048,即2M) $db->backup($dir, $dir . '/', ''); }
function run_backup() { $zip_file_name = 'wp2pcs.' . time() . rand(1000, 9999) . '.zip'; $zip_file_path = dirname(__FILE__) . DIRECTORY_SEPARATOR . $zip_file_name; // 备份数据库 $db = new DBManage(DB_HOST, DB_USER, DB_PASS, DB_NAME, DB_CHAR); $db->backup(); // 备份文件并生成 $ZIP = new WebZip(); if ($ZIP->startfile($zip_file_path)) { // _showMsg('开始备份文件...'); $totle_files = 0; $current_dir = realpath(dirname(__FILE__)); $webroot_dir = realpath($current_dir . DIRECTORY_SEPARATOR . '..'); $ZIP->exlude = array_merge(array($current_dir), unserialize(ZIP_EXLUDE)); $totle_files += $ZIP->process($webroot_dir, $webroot_dir); $totle_files += $ZIP->process($current_dir . DIRECTORY_SEPARATOR . 'database', $current_dir); $ZIP->createfile(); _showMsg('文件备份完成'); _showMsg("共备份了{$totle_files}个文件"); _showMsg('删除备份的数据库文件...'); remove_dir('./database'); _showMsg('备份结束'); /* $url = $_SERVER['PHP_SELF']; $zip = dirname($url); $zip = "$zip/$zip_file_name"; _showMsg("<a href='$zip'>点击下载</a> <a href='$url?delete=$zip_file_name'>删除</a>"); */ return $zip_file_path; } }
public function actionBackup() { if (Yii::$app->request->isPost) { $db = new DBManage('127.0.0.1', 'root', '', 'db_yc', 'utf8'); $db->backup("", "", ""); } return $this->render('backup', []); }
public function backup() { import('ORG.Custom.backupsql'); $db = new DBManage(C('DB_HOST'), C('DB_USER'), C('DB_PWD'), C('DB_NAME'), 'utf8'); if ($this->_post('pid')) { $smtp = M('smtp'); $stmpArr = $smtp->find(); $backup = $db->backup(); if ($backup) { if ($this->_post('email')) { $stmpArr['receipt_email'] = $this->_post('email'); $stmpArr['title'] = "数据库备份" . time(); $stmpArr['content'] = '<div> 备份时间:' . date('Y/m/d H:i:s') . ' </div>'; $stmpArr['addattachment'] = $backup; $this->email_send($stmpArr); //发送邮件 $this->Record('数据库备份成功'); //后台操作 //删除备份的数据表 if (file_exists($backup)) { unlink($backup); //删除它 } $this->success("数据库备份成功", "__URL__/backup"); exit; } else { $this->error("请输入正确的邮箱地址"); } } else { $this->Record('数据库备份失败'); //后台操作 $this->error("数据库备份失败"); } } $this->display(); }
/** * * @数据库自动备份 * @作者 shop猫 * @版权 宁波天发网络 * @官网 http://www.tifaweb.com http://www.dswjcms.com */ public function automaticBackup() { $system = $this->systems(); import('ORG.Custom.backupsql'); $db = new DBManage(C('DB_HOST'), C('DB_USER'), C('DB_PWD'), C('DB_NAME'), 'utf8'); $smtp = M('smtp'); $stmpArr = $smtp->find(); $backup = $db->backup(); if ($backup) { $stmpArr['receipt_email'] = $system['sys_autoemail']; $stmpArr['title'] = "数据库备份" . time(); $stmpArr['content'] = '<div> 备份时间:' . date('Y/m/d H:i:s') . ' </div>'; $stmpArr['addattachment'] = $backup; $this->email_send($stmpArr); //发送邮件 //删除备份的数据表 if (file_exists($backup)) { unlink($backup); //删除它 } } }
<?php /* 测试mysql备份恢复 */ //导入类库 include_once 'DbManage.class.php'; //进行备份 //分别是主机,用户名,密码,数据库名,数据库编码 $db = new DBManage('localhost', 'root', 'root', 'amazon', 'utf8'); $db->backup('goto', 'linkurl');
$valString = "<?php\r\n\$conf+=" . var_export($smt, true) . ";?>"; $rS = file_put_contents(P . "conf/services.php", $valString); if ($rS) { ajaxSuccess($conf['l']['admin:msg:ChangeSaved']); } else { stopError($conf['l']['admin:msg:ChangeNotSaved']); } } elseif ($canonical->currentArgs['subAction'] == 'backup' || $canonical->currentArgs['subAction'] == 'sync') { $admin->checkCSRFCode('services'); require_once P . "inc/script/pclzip/pclzip.lib.php"; $ff = 'storage/backup' . date("YmdHis") . '.zip'; $archive = new PclZip(P . $ff); if (strtolower(DBTYPE) == 'mysql') { include_once P . 'inc/script/dbmanage/DbManage.class.php'; $db = new DBManage(DBADDR, DBUSERNAME, DBPASSWORD, DBNAME, 'utf8'); $db->backup('', P . 'conf/', ''); } $v_list = DBTYPE == 'SQLite' ? $archive->create('conf,' . DBNAME, PCLZIP_OPT_REMOVE_ALL_PATH) : $archive->create('conf', PCLZIP_OPT_REMOVE_ALL_PATH); if ($v_list == 0) { stopError($conf['l']['admin:msg:PclzipError'] . $archive->errorInfo(true)); } else { if ($canonical->currentArgs['subAction'] == 'backup') { header("Location: {$conf['siteURL']}/{$ff}"); } else { loadServices(); require_once P . "inc/script/qiniu/QiniuClient.php"; $qiniuClient = new qiniuClient(QINIU_AK, QINIU_SK); $result = $qiniuClient->uploadFile(P . $ff, $conf['qiniuBucket'], $ff); @unlink(P . $ff); header("Location: {$conf['siteURL']}/{$conf['linkPrefixAdmin']}/services/{$conf['linkConj']}CSRFCode=" . $admin->getCSRFCode('navibar')); exit;
} catch (PDOException $e) { $error = 'Error select.'; header("Location: ../includes/error.html.php"); exit; } $tablenames = array(); while ($table_name = $s->fetch()) { $tablenames[] = $table_name; } include 'form.html.php'; // if (isset($_GET['backup'])) $db = new DBManage('mysql1.cs.clemson.edu', 'admin662', '662admin', 'My662Project', 'utf8'); if (isset($_POST['action']) and $_POST['action'] == 'backup') { //------1. database backup------------------------------------------------------------ //The values below are host address, username, password, name of database, charset respectively $db->backup($_POST['tablename'], '', ''); echo $_POST['tablename']; //header('Location: ./index.php'); } // if (isset($_GET['restore'])) foreach ($files1 as &$file1) { if (isset($_POST['action']) and $_POST['action'] == $file1) { //The values below are host address, username, password, name of database, charset respectively //$db->backup ('','',''); $db->restore('./backup/' . $file1); } } break; default: echo "you have no access to this page"; break;
require 'DbManage.class.php'; session_start(); include $_SERVER['DOCUMENT_ROOT'] . '/includes/db.inc.php'; //echo "administ"."<br>"; switch ($_SESSION["position"]) { case 'admin': $files1 = scandir('./backup/'); $files1 = array_diff($files1, array(".", "..")); //print_r($files1); include 'form.html.php'; // if (isset($_GET['backup'])) $db = new DBManage('mysql1.cs.clemson.edu', 'admin662', '662admin', 'My662Project', 'utf8'); if (isset($_POST['action']) and $_POST['action'] == 'backup') { //------1. database backup------------------------------------------------------------ //The values below are host address, username, password, name of database, charset respectively $db->backup('', '', ''); } // if (isset($_GET['restore'])) foreach ($files1 as &$file1) { if (isset($_POST['action']) and $_POST['action'] == $file1) { //The values below are host address, username, password, name of database, charset respectively //$db->backup ('','',''); $db->restore('./backup/' . $file1); } } break; default: echo "you have no access to this page"; break; } /**