How to back up VM data

Source: Internet
Author: User
Generally, backing up a database on a VM is troublesome. For convenience, I wrote a simple method for backing up MYSQL databases. PHP code :? * Virtual host backup program * programming: Bobanboban@21php.com * discussion: ahrefwww.21php. comforumstarget_blkwww.21php.comfo virtual host

Generally, backing up a database on a VM is troublesome. For convenience, I wrote a simple method for backing up MYSQL databases.
PHP code:

/**
* VM Backup Program
* Programming: Boban
* Discussion: http://www.21php.com/forums/
* Updated: 2004-02-02
* Instructions
* 1. change the MYSQL connection parameters, $ dbuser, $ dbpass, $ dbname
* 2. log on via FTP and create a dedicated directory for backup data. change the attribute to 777.
* 3. access this program through a browser. if the path of mysqldump is incorrect, change it by yourself (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"
";

// Delete the backup file
System ("rm./*. gz ");
System ("rm./*. SQL ");

// Start backup
System ("/usr/bin/mysqldump -- opt $ dbname -- user = '$ dbuser' -- password =' $ dbpass'> '. /$ servername $ today. SQL '", $ r1 );
If ($ r1 = 0) echo "MYSQL data backup successful
";
Else echo "backup failed
";
System ("gzip./$ servername $ today. SQL", $ r2 );
If ($ r2 = 0) echo "MYSQL data is compressed successfully.
";
Else echo "backup failed
";
System ("tar-czf'./your servername=today.tar.gz'' $ docroot/../'", $ r3 );
If ($ r3 = 0) echo "website ($ docroot) backup successful
";
Else echo "backup ($ docroot) failed
";
?>

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.