For Windows host
==============
Hypothetical environment:
MySQL Installation Location: C:mysql
Forum database name: BBS
MySQL Root Password: 123456
Database backup destinations: D:db_backup
Program code
@echo off
C:mysqlbinmysqladmin-u Root--password=123456 shutdown
C:mysqlbinmysqldump--opt-u root--password=123456 bbs > D:db_backupbbs.sql
C:mysqlbinmysqld-nt
Save the above code as Backup_db.bat
You can then use Windows Scheduled Tasks to execute the script at timed intervals.
At the same time, you can use PHP to complete:
Let MySQL implement automatic backup become possible!
1, edit the following code, and save as backup.php, if you want to compress can copy a rar.exe:
if ($ARGC!= 2 | | in_array ($ARGV [1], Array ('--help ', '-? ')) {
?>
Backup Ver 0.01, for Win95/win98/winnt/win2000/winxp on I32
Copyright (C) Ptker All rights reserved.
This are free Software,and your are welcome to modify and redistribute it
Under the GPL license
PHP Shell script for the backup MySQL database.
Usage:
Can is database name you would like to backup.
With the--help, or-? Options, you can get this help and exit.
else {
$dbname = $argv [1];
$dump _tool = "C:\mysql\bin\mysqldump";
$rar _tool = "D:\php4\rar";
@exec ("$dump _tool--opt-u User-ppassword $dbname >/$dbname. sql");
@exec ("$rar _tool a-ag_yyyy_mm_dd_hh_mm $dbname. rar $dbname. sql");
@unlink ("$dbname. sql");
echo "Backup complete!";
}
?>
2. Add a task plan, and in this step (shown in Figure 2), enter the command:
D:php4php.exe-q d:php4backup.php DatabaseName
3, the time is set to run once a day, and then run this task.
4, the final will be in the D:PHP4 directory to generate a database name and the current time composed of a RAR file.