通常情况下备份一个数据库,直接单裤备份即可,更完善一点的会要求做到定时单裤备份。然而很多时候又由于裤实例是在太多,这样会导致备份非常耗时,因而有时候需要对整个数据库应用进行备份。那么在windows下如何做到对整个应用做定时备份呢?
1、批处理备份脚本(注意修改脚本里面的变量)
@echo off & setlocal ENABLEEXTENSIONS ::日期 set TODAY=%date:~0,4%%date:~5,2%%date:~8,2% ::源程序所在目录 set DATAPATH=E:\bak\data\* ::备份目录 set BAKPATH=E:\webInfobackup\ ::备份名称前缀 set BAKNAME=mg3MyData ::+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ::+++++++++此目录为备份目录,压缩后会删除,修改时务必注意++++++++ set SRCPATH=%BAKPATH%\%BAKNAME%%TODAY% ::+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ call :Date2Day %date:~0,10% sdays set /a sdays-=7 call :Day2Date %sdays% difdate echo start bauckup mysql %date:~0,4%-%date:~5,2%-%date:~8,2% %time:~0,2%:%time:~3,2%:%time:~6,2% >>log.log ::关闭mysql服务 net stop mysql ::复制data目录 xcopy %DATAPATH% %SRCPATH%\ /e /y ::开启mysql服务 net start mysql echo bauckup mysql finish %date:~0,4%-%date:~5,2%-%date:~8,2% %time:~0,2%:%time:~3,2%:%time:~6,2% >>log.log ::压缩数据库文件并删除 "C:\Program Files\WinRAR\WinRAR.exe" a -r -ep2 -ibck -inul -df -t %SRCPATH%.rar %SRCPATH%\ echo compress mysql data finish %date:~0,4%-%date:~5,2%-%date:~8,2% %time:~0,2%:%time:~3,2%:%time:~6,2% >>log.log ::++++++++++++++++++删除目录++++++++++++++ rd /q /s %SRCPATH% ::++++++++++++++++++删除目录++++++++++++++ ::删除N天前备份文件 for /r %BAKPATH% %%f in (%BAKNAME%*.rar) do if "%%~tf" LEQ "%difdate%" del "%%f" goto:EOF exit :Date2Day setlocal ENABLEEXTENSIONS for /f "tokens=1-3 delims=/-, " %%a in ('echo/%1') do ( set yy=%%a & set mm=%%b & set dd=%%c ) set /a dd=100%dd%%%100,mm=100%mm%%%100 set /a z=14-mm,z/=12,y=yy+4800-z,m=mm+12*z-3,j=153*m+2 set /a j=j/5+dd+y*365+y/4-y/100+y/400-2472633 endlocal&set %2=%j%&goto :EOF :Day2Date setlocal ENABLEEXTENSIONS set /a i=%1,a=i+2472632,b=4*a+3,b/=146097,c=-b*146097,c/=4,c+=a set /a d=4*c+3,d/=1461,e=-1461*d,e/=4,e+=c,m=5*e+2,m/=153,dd=153*m+2,dd/=5 set /a dd=-dd+e+1,mm=-m/10,mm*=12,mm+=m+3,yy=b*100+d-4800+m/10 (if %mm% LSS 10 set mm=0%mm%)&(if %dd% LSS 10 set dd=0%dd%) endlocal&set %2=%yy%%mm%%dd%&goto :EOF
2、创建任务计划
不懂的可以GG一下,在此不详细介绍。