1.安装php执行环境 网上百度php即可,或者下载
2.写php执行文件 保存为backup.php
<?php
if ($argc != 2 || in_array($argv[1], array('--help', '-?'))) {?>
backup Ver 0.01, for Win95/Win98/WinNT/Win2000/WinXP on i32
Copyright (C) 2000 ptker All rights reserved.
This is free software,and you are welcome to modify and redistribute it
under the GPL license
PHP Shell script for the backup MySQL database.
Usage: <?php echo $argv[0]; ?> <option>
<option> can be database name you would like to backup.
With the --help, or -? options, you can get this help and exit.
<?php
} else {
$dbname = $argv[1];
$dburi =$dbname.date("Y-m-d-H-i-s");
echo $dburi;
$dump_tool = "C:\\xampp\\mysql\\bin\\mysqldump";
$rar_tool = "c:\\php\\rar";
@exec("$dump_tool --opt -u root -p -h127.0.0.1 $dbname > C:/php/aa/$dburi.sql");
del_dir("C:/php/aa");
//@exec("$rar_tool a -ag_yyyy_mm_dd_hh_mm $dbname.rar $dbname.sql");
//@unlink("$dbname.sql");
echo "Backup complete!";
}
?>
<?php
function del_dir($dir){ //删除目录
if(!($mydir=@dir($dir))){
return;
}
while($file=$mydir->read()){
echo $file;
if(is_dir("$dir$file") && $file!='.' && $file!='..'){
//@chmod("$dir$file", 0777);
//del_dir("$dir$file");
}elseif(is_file("$dir/$file")){
$file_time=stat("$dir/$file"); //读取文件的最后更新时间
if(time()-$file_time['ctime']>3600*24*8){
if($file != '.'&& $file!='..'&& $file !="")
{
@chmod("$dir/$file", 0777);
@unlink("$dir/$file");
}
}
}
}
$mydir->close();
}
?>
3.设定定时执行任务 c:\php\php.exe -q c:\php\backup.php busiman