Ways to back up your virtual host data

Source: Internet
Author: User
Backup | data | Virtual hosts generally speaking, the virtual host backup database is a more troublesome thing. For convenience, I wrote a simple way to back up the MySQL database.
PHP Code:

?
/**
* Virtual Host Backup Program
* Programming:boban<boban@21php.com>
* Discussion: <a href= "http://www.21php.com/forums/" target= "_blank" >http://www.21php.com/forums/</a>
* Update: 2004-02-02
* Instructions for use
* 1. Change the parameters of the MySQL connection, $dbuser, $dbpass, $dbname
* 2. Log in with FTP, set up a private directory to back up your data, change the property to 777
* 3. Access this program through the browser, if the mysqldump path is not correct, please change (default:/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>";

Delete backup files
System ("rm./*.gz");
System ("rm./*.sql");

Start Backup
System ("/usr/bin/mysqldump--opt $dbname--user= ' $dbuser '--password= ' $dbpass ' > './$servername $today.sql '", $r 1);
if ($r 1==0) echo "MySQL Data backup success <br>";
else echo "Backup failed <br>";
System ("gzip./$servername $today.sql", $r 2);
if ($r 2==0) echo "MySQL data compression success <br>";
else echo "Backup failed <br>";
System ("TAR-CZF"/$servername $today.tar.gz ' $docroot/. /' ", $r 3);
if ($r 3==0) echo "website ($docroot) Backup success <br>";
else echo "Backup ($docroot) failed <br>";
?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.