Home > php教程 > php手册 > 备份虚拟主机数据的办法

备份虚拟主机数据的办法

WBOY
Release: 2016-06-21 09:14:35
Original
830 people have browsed it

备份|数据|虚拟主机

一般来说虚拟主机备份数据库是一件比较麻烦的事情。为了方便,我自己写了一个简单的办法用于备份MYSQL的数据库。
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)失败
";
?>



Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template