window 2008r2 下mysql的自动备份脚本

 1 @echo off

 2 :start

 3 CLS

 4 

 5 set dt=%time:~0,2%

 6 if %dt% lss 10 set dt=%dt: =0%

 7 

 8 set file_name=%date:~0,4%%date:~5,2%%date:~8,2%_%dt%_%time:~3,2%

 9 set bin_path="c:\MySQL\MySQL Server 5.5\bin\"

10 set save_path="c:\mysql_backup\data"

11 set zip_path="C:\Program Files (x86)\7-Zip\7z.exe"

12 set bak_path="d:\mysql_backup\data"

13 

14 echo export_starting

15 %bin_path%mysqldump.exe -uroot -p123 db1> %save_path%\db1_%file_name%.sql

16 %bin_path%mysqldump.exe -uroot -p123 db2> %save_path%\db2_%file_name%.sql

17 echo export_end

18 

19 echo zip_starting

20 %zip_path% a -tzip -p123 %save_path%\db1_%file_name%.zip %save_path%\db1_%file_name%.sql

21 %zip_path% a -tzip -p123 %save_path%\db2_%file_name%.zip %save_path%\db2_%file_name%.sql

22 echo zip_end

23 

24 echo copy_starting

25 copy %save_path%\db1_%file_name%.zip %bak_path%\db1_%file_name%.zip

26 copy %save_path%\db2_%file_name%.zip %bak_path%\db2_%file_name%.zip

27 echo copy_end

28 

29 echo rm_starting

30 del %save_path%\db1_%file_name%.sql

31 del %save_path%\db2_%file_name%.sql

32 echo rm_end

33 

34 echo rm_history_starting

35 set DaysAgo=10

36 forfiles /p %save_path% /s /m *.* /d -%DaysAgo% /c "cmd /c del /f /q /a @path"

37 forfiles /p %bak_path% /s /m *.* /d -%DaysAgo% /c "cmd /c del /f /q /a @path"

38 echo rm_history_end

39 

40 echo ok

你可能感兴趣的:(window)