PHP代码:
/**
* 虚拟主机备份程序
* 编程:Boban
* 讨论:http://www.21php.com/forums/
* 更新: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 “
“;
// 删除备份文件
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数据备份成功
“;
else echo “备份失败
“;
system(“gzip ./$servername$today.sql”,$r2);
if($r2==0) echo “MYSQL数据压缩成功
“;
else echo “备份失败
“;
system(“tar -czf ‘./$servername$today.tar.gz’ ‘$docroot/../'”,$r3);
if($r3==0) echo “网站($docroot)备份成功
“;
else echo “备份($docroot)失败
“;
?>