PHP代码:
<?
/**
* 备份程序
* 编程:Boban<boban@21php.com>
* 讨论:<a href="http://www.21php.com/forums/" target="_blank">http://www.21php.com/forums/</a>
* 更新:2004-02-02
* 使用说明
* 1. 更改MYSQL连接的参数,$dbuser,$dbpass,$dbname
* 2. 用FTP登录,建立一个备份数据的专用目录,更改属性为777
* 3. 通过浏览器访问这个程序,如果mysqldump的路径不对,请自行更改(默认:/usr/bin/mysqldump)
* */
set_time_limit(900);
$today = date("_Y_m_d");
$dbuser = "root";
$dbpass = "";
$dbname = "www_21php_com";
$servername = $_SERVER[@#SERVER_NAME@#];
$servername = str_replace(@#.@#,@#_@#,$servername);
//echo $servername;
$docroot = getcwd();
echo system("locate mysqldump");
echo "<br>";
// 删除备份文件
system("rm ./*.gz");
system("rm ./*.sql");
// 开始备份
system("/usr/bin/mysqldump --opt $dbname --user=@#$dbuser@# --password=@#$dbpass@# >@#./$servername$today.sql@#",$r1);
if($r1==0) echo "MYSQL数据备份成功<br>";
else echo "备份失败<br>";
system("gzip ./$servername$today.sql",$r2);
if($r2==0) echo "MYSQL数据压缩成功<br>";
else echo "备份失败<br>";
system("tar -czf @#./$servername$today.tar.gz@# @#$docroot/../@#",$r3);
if($r3==0) echo "网站($docroot)备份成功<br>";
else echo "备份($docroot)失败<br>";
?>
文章来源于领测软件测试网 https://www.ltesting.net/