<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>系统维护</title> <style> body{ font-size:12px; } </style> </head> <body> <p> <a href="updateAdminpwd.html" target="content">修改管理员密码</a> || <a href="sys_main.php?action=beifen" target="content">备份数据库</a> || <a href="sys_main.php?action=huifu" target="content">恢复数据库</a> </p> <?php if($_GET["action"] == "huifu") { include "sys_huifuData.php"; }else if ($_GET["action"] == "beifen"){ date_default_timezone_set('PRC'); include "config.php"; $backcmd = "mysqldump -u$username -p$password yanjing"; //exec($backcmd,$out,$status); //echo "备份成功".$backcmd; $comm_dir = "D:/Program Files (x86)/EasyPHP-5.3.8.0/mysql/bin/";//mysqldump所在路径:mysql/bin $file_dir = "backup/";//备份文件路径 $file_name = date("Ymd-His").".sql";//备份文件名 $backCMD = $backcmd.'>'.$file_dir.$file_name; //echo $backCMD."<br>"; exec($backCMD,$arr,$i);//执行备份命令 if($i == 0) { echo "备份成功"; }else{ echo "备份失败"; } }else if ($_GET["action"] == "huifuaction") { // 我的数据库信息都存放到config.php文件中,所以加载此文件,如果你的不是存放到该文件中,注释此行即可; require_once('config.php'); if ( isset ( $_POST['sqlFile'] ) ) { $file_name = "backup/".$_POST['sqlFile']; //要导入的SQL文件名 set_time_limit(0); //设置超时时间为0,表示一直执行。当php在safe mode模式下无效,此时可能会导致导入超时,此时需要分段导入 $fp = @fopen($file_name, "r") or die("不能打开SQL文件 $file_name");//打开文件 mysql_connect($dbhost, $dbuser, $dbpass) or die("不能连接数据库 $dbhost");//连接数据库 mysql_select_db($dbname) or die ("不能打开数据库 $dbname");//打开数据库 echo "<p>正在清空数据库,请稍等....<br>"; $result = mysql_query("SHOW tables"); while ($currow=mysql_fetch_array($result)) { mysql_query("drop TABLE IF EXISTS $currow[0]"); echo "清空数据表【".$currow[0]."】成功!<br>"; } echo "<br>恭喜你清理MYSQL成功<br>"; echo "正在执行导入数据库操作<br>"; // 导入数据库的MySQL命令 //linux下 //exec("mysql -u$dbuser -p$dbpass $dbname < ".$file_name); //win下 exec("source ".$file_name); echo "<br>导入完成!"; mysql_close(); } } ?> </body> </html>