Implementation of Win2003 MySQL database daily automatic backup _php tutorial

Source: Internet
Author: User
1. Environment: Windows Server 2003 + PHP5 + MySQL 5.1.6.
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:
The code is as follows:


Save the directory with a backslash. You need to set it up 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.\r\n");
@mkdir ($nowdir);

mysql_connect ("localhost", "$db _username", "$db _password");
$query =mysql_list_dbs ();


$command = ";
while ($result =mysql_fetch_array ($query)) {
$command. = DirName (__file__). ' \.. \mysql\bin\mysqldump--opt '. " $result [Database]-u{$db _username} ". ($db _password? " -p{$db _password} ":"). "> $nowdir \ \ $result [database].sql \ r \ n];
$command. = "echo Dumping database ' $result [database] ' ... \ r \ n";
}
$command. = "echo Winrar loading...\r\n";

$command. = DirName (__file__). " \\WinRAR\\WinRAR.exe a-ep1-r-o+-m5-df \ "$nowdir. Rar\" \ "$nowdir \" \ r \ n ";

$command. = "Echo ok!\r\n";

$command. = "Del mysqldumping_temp.bat\r\n";

$fp = fopen (' Mysqldumping_temp.bat ', ' W ');
Fwrite ($fp, $command);
Fclose ($FP);


Delete files from 5 days ago
@unlink ("$store _folder\\". Date ("Ymd", $time -86400*5). ". RAR ");
?>


5. Create a file Mysql_backup.bat under D:/php, as follows:
echo off
Php.exe mysql_backup.php
If exist Mysqldumping_temp.bat call Mysqldumping_temp.bat
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, I set the time at 8 o'clock in the morning.

Original Author: Faisun
Website:http://www.softpure.com

http://www.bkjia.com/PHPjc/317270.html www.bkjia.com true http://www.bkjia.com/PHPjc/317270.html techarticle 1. Environment: windowsserver2003+php5+mysql5.1.6. 2. Assume that the PHP installation directory for the D:/php,mysql installation directory is d:/mysql. 3. Under d:/php set up directory winrar, put you winrar the installation directory of WinRAR.exe and ...

  • 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.