Home > php教程 > php手册 > body text

php备份mysql实例程序

WBOY
Release: 2016-06-13 10:09:26
Original
1048 people have browsed it

php备份mysql我们需借助于系统的计划任务功能,下面我来介绍在linux中php备份mysql实例方法。

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

 代码如下 复制代码

mkdir /backup/mysql_data_backup -p
cd /backup/mysql_data_backup
wget /backmysql.txt -O backmysql.php
chmod +x backmysql.php
crontab -e

添加一行任务

 代码如下 复制代码
0 13 * * * /usr/bin/php /backup/mysql_data_backup/backmysql.php

表示在每天晚上0点13分用php执行备份命令

 

 代码如下 复制代码
#!/usr/bin/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";

注意,这里只是计划信息处理了,如果要执行php文件我们需要自己写一个即可。

source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!