Home  >  Article  >  Backend Development  >  PHP backup mysql example program_PHP tutorial

PHP backup mysql example program_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:06:35878browse

We need to use the system’s scheduled task function to back up mysql in php. Next, I will introduce the method of backing up mysql in linux using php.

#Back up all backup files to the specified directory, such as /backup/mysql_data_backup

means to execute the backup command using php at 0:13 every night
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

Copy code

 代码如下 复制代码
0 13 * * * /usr/bin/php /backup/mysql_data_backup/backmysql.php
mkdir /backup/mysql_data_backup -p
cd /backup/mysql_data_backup
wget /backmysql.txt -O backmysql.php
chmod +x backmysql.php
crontab -e

 代码如下 复制代码
#!/usr/bin/php
< ?php

//产生保存目录
$path = dirname(__FILE__) . '/' .date("Ym");
$filename = sprintf("%s/%s.sql.gz", $path, date("YmdHis"));

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

//导出并压缩所有数据库
$cmd = sprintf("/usr/bin/mysqldump -uroot -ppassword --all-databases | /bin/gzip > %s", $filename);
echo "backuping...n";
`$cmd`;
echo "backup done.n";
Add a line of tasks

Note that this is only the planning information processing. If we want to execute the php file, we need to write one ourselves. http://www.bkjia.com/PHPjc/630679.htmlwww.bkjia.comtrue
http: //www.bkjia.com/PHPjc/630679.html
TechArticle
php backup mysql we need to use the system's scheduled task function, let me introduce the example of php backup mysql in linux method. #Back up all backup files to the specified directory, such as /backup/...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn