Back up mysql instance programs in php. We need to use the scheduled task function of the system to back up mysql in php. The following describes how to back up mysql instances in php in linux. # Back up all backup files to the specified directory. for example, to back up php to back up mysql, we need to use the scheduled task function of the system. next I will introduce how to back up mysql instances in php in linux.
# Back up all backup files to the specified directory, such as/backup/mysql_data_backup
| The code is as follows: |
|
|
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 task line
| The code is as follows: |
|
0 13 ***/usr/bin/php/backup/mysql_data_backup/backmysql. php
|
Run the backup command in php at 00:13 every night.
| The code is as follows: |
|
#! /Usr/bin/php
<? Php
// Generate a storage 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: The plan information is processed here. if you want to execute the php file, you need to write one by yourself.
Bytes. # Back up all backup files to the specified directory, such as/backup /...