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