PHP Backup MySQL Instance program

Source: Internet
Author: User

#将所有备份文件备份到指定的目录, such as/backup/mysql_data_backup

The code is as follows Copy Code

Mkdir/backup/mysql_data_backup-p
Cd/backup/mysql_data_backup
Wget/backmysql.txt-o backmysql.php
chmod +x backmysql.php
Crontab-e

Add a row of tasks

The code is as follows Copy Code
0 * * */usr/bin/php/backup/mysql_data_backup/backmysql.php

To use PHP to perform backup commands every night 0:13

The code is as follows Copy Code
#!/usr/bin/php
< PHP

Generate Save Directory
$path = DirName (__file__). '/'. Date ("Ym");
$filename = sprintf ("%s/%s.sql.gz", $path, Date ("Ymdhis"));

if (!is_dir ($path))
mkdir ($path);

Export and compress all databases
$cmd = sprintf ("/usr/bin/mysqldump-uroot-ppassword--all-databases | /bin/gzip >%s ", $filename);
echo "BACKUPING...N";
' $cmd ';
echo "Backup DONE.N";

Note that this is only a plan for information processing, and if you want to execute PHP files we need to write one ourselves.

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.