Windows2003 MySQL database automatic daily backup _php tutorial

Source: Internet
Author: User
Finally, the server backs up the MySQL database once a day and automatically packs it, deleting the backup files 5 days ago. Share the following:

1. Environment: Windows Server 2003 + Apache 2.0 + PHP5 + MySQL 4.0.26.

2. Assuming that the PHP installation directory is d:/php, the MySQL installation directory is d:/mysql.

3. Create a directory WinRAR under d:/php and copy the WinRAR.exe and Rarreg.key from your WinRAR installation directory to D:/php/winrar.

4. Create file mysql_backup.php under d:/php:

/*/////////////////////////
#FileName: mysql_backup.php #Author: Faisun #Website: http://www.softpure.com
////////////////////////*/
Save the directory, using a backslash for the path. You need to build it manually.
$store _folder = ' D:\databse_backup ';
User name and password
The account must have the operation [all] the database and file permissions
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 (DirName (__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 \ "$nowdir. rar\" "$nowdir \" ");
Delete files from 5 days ago
@unlink ("$store _folder\\". Date ("Ymd", $time -86400*5). ". RAR ");
echo "\nok!\n"; 〉

5. Under the d:/php to establish a document Mysql_backup.bat, the content only one sentence:

Php.exe mysql_backup.php

6. Double-click the bat file to run, if you can back up, OK, next add the task schedule.

7. Add the D:/php/mysql_backup to the task schedule and choose the time of day. According to the monitoring results of the server, the traffic is low peak period at 5-8 a.m. per day. Due to the cleanup of some databases at 5-7, the time can be set at 8 o'clock in the morning.

http://www.bkjia.com/PHPjc/317561.html www.bkjia.com true http://www.bkjia.com/PHPjc/317561.html techarticle Finally, the server backs up the MySQL database once a day and automatically packs it, deleting the backup files 5 days ago. Share the following: 1. Environment: windowsserver2003+apache2.0+php5+mysql4.0.26. 2 ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.