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

备份|数据|虚拟主机

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



Statement
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools