时间:2021-07-01 10:21:17 帮助过:2人阅读
- @echo off &<span style="color: #000000;"> setlocal ENABLEEXTENSIONS
- ::日期
- 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;">
- ::源程序所在目录
- set DATAPATH</span>=E:\bak\data\*<span style="color: #000000;">
- ::备份目录
- set BAKPATH</span>=<span style="color: #000000;">E:\webInfobackup::备份名称前缀
- set BAKNAME</span>=<span style="color: #000000;">mg3MyData
- ::</span>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++<span style="color: #000000;">
- ::</span>+++++++++此目录为备份目录,压缩后会删除,修改时务必注意++++++++<span style="color: #000000;">
- set SRCPATH</span>=%BAKPATH%\%BAKNAME%%TODAY%<span style="color: #000000;">
- ::</span>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++<span style="color: #000000;">
- 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
- set </span>/a sdays-=<span style="color: #800080;">7</span><span style="color: #000000;">
- call :Day2Date </span>%sdays%<span style="color: #000000;"> difdate
- </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
- ::关闭mysql服务
- net stop mysql
- ::复制data目录
- xcopy </span>%DATAPATH% %SRCPATH%\ /e /<span style="color: #000000;">y
- ::开启mysql服务
- net start mysql
- </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
- ::压缩数据库文件并删除
- </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
- ::</span>++++++++++++++++++删除目录++++++++++++++<span style="color: #000000;">
- rd </span>/q /s %SRCPATH%<span style="color: #000000;">
- ::</span>++++++++++++++++++删除目录++++++++++++++<span style="color: #000000;">
- ::删除N天前备份文件
- </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;">
- goto:EOF exit
- :Date2Day
- setlocal ENABLEEXTENSIONS
- </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;"> (
- set yy</span>=%%a & set mm=%%b & set <span style="color: #0000ff;">dd</span>=%%<span style="color: #000000;">c
- )
- 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;">
- 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;">
- 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;">
- endlocal</span>&set %<span style="color: #800080;">2</span>=%j%&<span style="color: #000000;">goto :EOF
- :Day2Date
- setlocal ENABLEEXTENSIONS
- 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
- 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;">
- 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;">
- (</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;">)
- endlocal</span>&set %<span style="color: #800080;">2</span>=%yy%%mm%%<span style="color: #0000ff;">dd</span>%&goto :EOF
2、创建任务计划
不懂的可以GG一下,在此不详细介绍。
windows下如何对mysql进行整裤备份
标签: