当前位置:Gxlcms > 数据库问题 > windows下如何对mysql进行整裤备份

windows下如何对mysql进行整裤备份

时间:2021-07-01 10:21:17 帮助过:2人阅读

  1. @echo off &<span style="color: #000000;"> setlocal ENABLEEXTENSIONS
  2. ::日期
  3. set TODAY</span>=%<span style="color: #0000ff;">date</span>:~<span style="color: #800080;">0</span>,<span style="color: #800080;">4</span>%%<span style="color: #0000ff;">date</span>:~<span style="color: #800080;">5</span>,<span style="color: #800080;">2</span>%%<span style="color: #0000ff;">date</span>:~<span style="color: #800080;">8</span>,<span style="color: #800080;">2</span>%<span style="color: #000000;">
  4. ::源程序所在目录
  5. set DATAPATH</span>=E:\bak\data\*<span style="color: #000000;">
  6. ::备份目录
  7. set BAKPATH</span>=<span style="color: #000000;">E:\webInfobackup::备份名称前缀
  8. set BAKNAME</span>=<span style="color: #000000;">mg3MyData
  9. ::</span>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++<span style="color: #000000;">
  10. ::</span>+++++++++此目录为备份目录,压缩后会删除,修改时务必注意++++++++<span style="color: #000000;">
  11. set SRCPATH</span>=%BAKPATH%\%BAKNAME%%TODAY%<span style="color: #000000;">
  12. ::</span>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++<span style="color: #000000;">
  13. call :Date2Day </span>%<span style="color: #0000ff;">date</span>:~<span style="color: #800080;">0</span>,<span style="color: #800080;">10</span>%<span style="color: #000000;"> sdays
  14. set </span>/a sdays-=<span style="color: #800080;">7</span><span style="color: #000000;">
  15. call :Day2Date </span>%sdays%<span style="color: #000000;"> difdate
  16. </span><span style="color: #0000ff;">echo</span> start bauckup mysql %<span style="color: #0000ff;">date</span>:~<span style="color: #800080;">0</span>,<span style="color: #800080;">4</span>%-%<span style="color: #0000ff;">date</span>:~<span style="color: #800080;">5</span>,<span style="color: #800080;">2</span>%-%<span style="color: #0000ff;">date</span>:~<span style="color: #800080;">8</span>,<span style="color: #800080;">2</span>% %<span style="color: #0000ff;">time</span>:~<span style="color: #800080;">0</span>,<span style="color: #800080;">2</span>%:%<span style="color: #0000ff;">time</span>:~<span style="color: #800080;">3</span>,<span style="color: #800080;">2</span>%:%<span style="color: #0000ff;">time</span>:~<span style="color: #800080;">6</span>,<span style="color: #800080;">2</span>% >><span style="color: #000000;">log.log
  17. ::关闭mysql服务
  18. net stop mysql
  19. ::复制data目录
  20. xcopy </span>%DATAPATH% %SRCPATH%\ /e /<span style="color: #000000;">y
  21. ::开启mysql服务
  22. net start mysql
  23. </span><span style="color: #0000ff;">echo</span> bauckup mysql finish %<span style="color: #0000ff;">date</span>:~<span style="color: #800080;">0</span>,<span style="color: #800080;">4</span>%-%<span style="color: #0000ff;">date</span>:~<span style="color: #800080;">5</span>,<span style="color: #800080;">2</span>%-%<span style="color: #0000ff;">date</span>:~<span style="color: #800080;">8</span>,<span style="color: #800080;">2</span>% %<span style="color: #0000ff;">time</span>:~<span style="color: #800080;">0</span>,<span style="color: #800080;">2</span>%:%<span style="color: #0000ff;">time</span>:~<span style="color: #800080;">3</span>,<span style="color: #800080;">2</span>%:%<span style="color: #0000ff;">time</span>:~<span style="color: #800080;">6</span>,<span style="color: #800080;">2</span>% >><span style="color: #000000;">log.log
  24. ::压缩数据库文件并删除
  25. </span><span style="color: #800000;">"</span><span style="color: #800000;">C:\Program Files\WinRAR\WinRAR.exe</span><span style="color: #800000;">"</span> a -r -ep2 -ibck -inul -<span style="color: #0000ff;">df</span> -t %SRCPATH%.rar %SRCPATH%<span style="color: #000000;"></span><span style="color: #0000ff;">echo</span> compress mysql data finish %<span style="color: #0000ff;">date</span>:~<span style="color: #800080;">0</span>,<span style="color: #800080;">4</span>%-%<span style="color: #0000ff;">date</span>:~<span style="color: #800080;">5</span>,<span style="color: #800080;">2</span>%-%<span style="color: #0000ff;">date</span>:~<span style="color: #800080;">8</span>,<span style="color: #800080;">2</span>% %<span style="color: #0000ff;">time</span>:~<span style="color: #800080;">0</span>,<span style="color: #800080;">2</span>%:%<span style="color: #0000ff;">time</span>:~<span style="color: #800080;">3</span>,<span style="color: #800080;">2</span>%:%<span style="color: #0000ff;">time</span>:~<span style="color: #800080;">6</span>,<span style="color: #800080;">2</span>% >><span style="color: #000000;">log.log
  26. ::</span>++++++++++++++++++删除目录++++++++++++++<span style="color: #000000;">
  27. rd </span>/q /s %SRCPATH%<span style="color: #000000;">
  28. ::</span>++++++++++++++++++删除目录++++++++++++++<span style="color: #000000;">
  29. ::删除N天前备份文件
  30. </span><span style="color: #0000ff;">for</span> /r %BAKPATH% %%f <span style="color: #0000ff;">in</span> (%BAKNAME%*.rar) <span style="color: #0000ff;">do</span> <span style="color: #0000ff;">if</span> <span style="color: #800000;">"</span><span style="color: #800000;">%%~tf</span><span style="color: #800000;">"</span> LEQ <span style="color: #800000;">"</span><span style="color: #800000;">%difdate%</span><span style="color: #800000;">"</span> del <span style="color: #800000;">"</span><span style="color: #800000;">%%f</span><span style="color: #800000;">"</span><span style="color: #000000;">
  31. goto:EOF exit
  32. :Date2Day
  33. setlocal ENABLEEXTENSIONS
  34. </span><span style="color: #0000ff;">for</span> /f <span style="color: #800000;">"</span><span style="color: #800000;">tokens=1-3 delims=/-, </span><span style="color: #800000;">"</span> %%a <span style="color: #0000ff;">in</span> (<span style="color: #800000;">‘</span><span style="color: #800000;">echo/%1</span><span style="color: #800000;">‘</span>) <span style="color: #0000ff;">do</span><span style="color: #000000;"> (
  35. set yy</span>=%%a & set mm=%%b & set <span style="color: #0000ff;">dd</span>=%%<span style="color: #000000;">c
  36. )
  37. set </span>/a <span style="color: #0000ff;">dd</span>=<span style="color: #800080;">100</span>%<span style="color: #0000ff;">dd</span>%%%<span style="color: #800080;">100</span>,mm=<span style="color: #800080;">100</span>%mm%%%<span style="color: #800080;">100</span><span style="color: #000000;">
  38. set </span>/a z=<span style="color: #800080;">14</span>-mm,z/=<span style="color: #800080;">12</span>,y=yy+<span style="color: #800080;">4800</span>-z,m=mm+<span style="color: #800080;">12</span>*z-<span style="color: #800080;">3</span>,j=<span style="color: #800080;">153</span>*m+<span style="color: #800080;">2</span><span style="color: #000000;">
  39. set </span>/a j=j/<span style="color: #800080;">5</span>+<span style="color: #0000ff;">dd</span>+y*<span style="color: #800080;">365</span>+y/<span style="color: #800080;">4</span>-y/<span style="color: #800080;">100</span>+y/<span style="color: #800080;">400</span>-<span style="color: #800080;">2472633</span><span style="color: #000000;">
  40. endlocal</span>&set %<span style="color: #800080;">2</span>=%j%&<span style="color: #000000;">goto :EOF
  41. :Day2Date
  42. setlocal ENABLEEXTENSIONS
  43. set </span>/a i=%<span style="color: #800080;">1</span>,a=i+<span style="color: #800080;">2472632</span>,b=<span style="color: #800080;">4</span>*a+<span style="color: #800080;">3</span>,b/=<span style="color: #800080;">146097</span>,c=-b*<span style="color: #800080;">146097</span>,c/=<span style="color: #800080;">4</span>,c+=<span style="color: #000000;">a
  44. set </span>/a d=<span style="color: #800080;">4</span>*c+<span style="color: #800080;">3</span>,d/=<span style="color: #800080;">1461</span>,e=-<span style="color: #800080;">1461</span>*d,e/=<span style="color: #800080;">4</span>,e+=c,m=<span style="color: #800080;">5</span>*e+<span style="color: #800080;">2</span>,m/=<span style="color: #800080;">153</span>,<span style="color: #0000ff;">dd</span>=<span style="color: #800080;">153</span>*m+<span style="color: #800080;">2</span>,<span style="color: #0000ff;">dd</span>/=<span style="color: #800080;">5</span><span style="color: #000000;">
  45. set </span>/a <span style="color: #0000ff;">dd</span>=-<span style="color: #0000ff;">dd</span>+e+<span style="color: #800080;">1</span>,mm=-m/<span style="color: #800080;">10</span>,mm*=<span style="color: #800080;">12</span>,mm+=m+<span style="color: #800080;">3</span>,yy=b*<span style="color: #800080;">100</span>+d-<span style="color: #800080;">4800</span>+m/<span style="color: #800080;">10</span><span style="color: #000000;">
  46. (</span><span style="color: #0000ff;">if</span> %mm% LSS <span style="color: #800080;">10</span> set mm=<span style="color: #800080;">0</span>%mm%)&(<span style="color: #0000ff;">if</span> %<span style="color: #0000ff;">dd</span>% LSS <span style="color: #800080;">10</span> set <span style="color: #0000ff;">dd</span>=<span style="color: #800080;">0</span>%<span style="color: #0000ff;">dd</span>%<span style="color: #000000;">)
  47. endlocal</span>&set %<span style="color: #800080;">2</span>=%yy%%mm%%<span style="color: #0000ff;">dd</span>%&goto :EOF

2、创建任务计划

 不懂的可以GG一下,在此不详细介绍。

windows下如何对mysql进行整裤备份

标签:

人气教程排行