Working Environment Windows Server 2003, MySQL installation directory D:\MySQL, WinRAR installation directory C:\Program Files\winrar\winrar.exe
The path to the backup data store is the E:\ data backup, so let's start with the DOS batch command.
Copy Code code as follows:
Set "ymd=%date:~,4%%date:~5,2%%date:~8,2%"
MD "E:\ data backup \%ymd%"
"D:\MySQL\bin\mysqldump.exe"--opt-q mysql-uroot-p123456789 > E:\ Data Backup \%ymd%\mysql.sql
Rem..... Here you can add more commands to see how many databases you have, where-Q is followed by the database name-p followed by the password
echo Winrar Loading ...
"C:\Program files\winrar\winrar.exe" a-ep1-r-o+-m5-df "e:\ data backup \%ymd%.rar" "E:\ Data Backup \%ymd%"
Echo ok!
Save the above command as Backup.bat, double-click to run, and start backing up the data.
The first sentence is to create a variable%ymd%, by%date% This system variable to get the date,%date:~,4% represents the first 4 characters of the date is the year,%%date:~5,2% represents the date 5th characters start 2 characters is the month,%date:~8,2% This is the date, and as of 2009-06-20, the end result is 20090620.
The second sentence is to create an empty folder using the value of the variable%ymd%.
The third sentence is to use MySQL's command to back up the database MySQL, and stored in the E:\ data backup \%ymd% This folder, there can be many similar commands, back up multiple databases.
Finally, the backed-up data is compressed using WinRAR and stored as a RAR filename with the%ymd% variable value, and the%ymd% directory of the backup is deleted.
If you want the system to automatically back up regularly, this command can be executed periodically through the system's task schedule.