Finally, let the server back up the MySQL database every morning and automatically package it, and delete the backup files five days ago. Share as follows:
1. Environment: Windows Server 2003 + Apache 2.0 + PhP5 + MySQL 4.0.26.
2. Assume that the PHP installation directory is D:/PHP, And the MySQL installation directory is D:/MySQL.
3. Create the WinRAR directory in D:/PHP and copy winrar.exe and rarreg. Key in the WinRAR installation directory to D:/PHP/WinRAR.
4. D:/PHP file mysql_backup.php:
/* // # filename: mysql_backup.php # Author: faisun # Website: http://www.softpure.com //////////// // Save the directory, the path must use a backslash. You need to create it manually. $ Store_folder = 'd: \ databse_backup '; // user name and password // This account must have the permission to operate [all] databases and files // otherwise, some databases cannot be backed up $ db_username = "root"; $ db_password = ""; $ time = Time (); $ nowdir = "$ store_folder \". date ("ymd", $ time ). "; if(file_exists({%nowdir.rar") Die ("file exists. \ n "); @ mkdir ($ nowdir); mysql_connect (" localhost "," $ db_username "," $ db_password "); $ query = mysql_list_dbs (); while ($ result = mysql_fetch_array ($ query) {system (Dir Name (_ file __). '\.. \ mysql \ bin \ mysqldump -- opt '. "$ result [database]-U {$ db_username}". ($ db_password? "-P {$ db_password}": ""). "> $ nowdir \ $ result [database]. SQL "); echo" dumping database '$ result [database]'... \ n ";} echo" \ nwinrar loading... \ n "; System (dirname (_ file __). "\ WinRAR \ winrar.exe A-EP1-R-O +-M5-DF \ has reached nowdir.rar \" "$ nowdir \" "); // delete the file five days ago @ unlink ("$ store_folder \". date ("ymd", $ time-86400 * 52.16.w..rar "); echo" \ nok! \ N ";>
5. D:/PHP creates the file mysql_backup.bat, which contains only one sentence:
Php.exe mysql_backup.php
6. Double-click the BAT file to run the task. If the file can be backed up, OK. Next, add the task plan.
7. add D:/PHP/mysql_backup to the task schedule. Select daily as the time. based on the monitoring results of the server, the traffic is low every morning from 5 to 8. because some database cleanup operations are performed during the 5-7 period, you can set the time to eight o'clock in the morning. Detailed source reference: http://www.jb51.net/article/5416.htm