PHP backup MySQL instance program _php tutorial

Source: Internet
Author: User
Tags sprintf
PHP backup MySQL We need to take advantage of the system's scheduled Tasks feature, let me introduce the PHP backup MySQL instance method in Linux.

#将所有备份文件备份到指定的目录, 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

Indicates that a backup command is executed at 0:13 every night with PHP

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 just a plan to process information, if you want to execute PHP files we need to write one ourselves.

http://www.bkjia.com/PHPjc/630679.html www.bkjia.com true http://www.bkjia.com/PHPjc/630679.html techarticle PHP backup MySQL We need to take advantage of the system's scheduled Tasks feature, let me introduce the PHP backup MySQL instance method in Linux. #将所有备份文件备份到指定的目录, such as/backup/ ...

  • 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.