Home > Backend Development > PHP Tutorial > windows2003 server mysql scheduled backup every day

windows2003 server mysql scheduled backup every day

WBOY
Release: 2016-07-28 08:25:58
Original
907 people have browsed it

1.php uses mysqldump to back up the database, the code is as follows:

<?php 

/**
 * 数据库备份
 */

$sqlname = $argv[1]; //接受bat或cmd传过来的第一个参数  要备份的数据库名
$day = $argv[2]; //接受bat或cmd传过来的第一个参数   备份数据保存天数

/*备份保存$day天,老数据删除*/
$old = 'e:/wamp/db_backup/'.date('Ymd',strtotime("-".$day." day")).$sqlname.'.sql';
if(file_exists($old)){
    unlink($old);
}

//备份数据库
$filepath = 'e:/wamp/db_backup/'.date('Ymd').$sqlname.'.sql';
$sql = 'mysqldump --no-defaults -uroot -p*** '.$sqlname.' > '.$filepath;
exec($sql);

 ?>
Copy after login

2. Run the above php file through bat, the content of the bat file is as follows:

<code><span>e:/wamp/php5<span>.4<span>.44/php<span>.exe e:/wamp/backup<span>.php zzy <span>30</span></span></span></span></span></span></code>
Copy after login

Among them:
e:/wamp/php5.4.44/php.exe: PHP installation path;
e:/wamp/backup.php: PHP file to be run;
zzy: Database to be backed up;
30: Number of days to save backup data.
3. Just add the bat file to the scheduled task.

The above introduces the daily scheduled backup of mysql in windows2003 server, including the content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template