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

时间:2022-11-15 01:04:01

通常情况下备份一个数据库,直接单裤备份即可,更完善一点的会要求做到定时单裤备份。然而很多时候又由于裤实例是在太多,这样会导致备份非常耗时,因而有时候需要对整个数据库应用进行备份。那么在windows下如何做到对整个应用做定时备份呢?

1、批处理备份脚本(注意修改脚本里面的变量

@echo off & setlocal ENABLEEXTENSIONS
::日期
set TODAY=%date:~,%%date:~,%%date:~,%
::源程序所在目录
set DATAPATH=E:\bak\data\*
::备份目录
set BAKPATH=E:\webInfobackup\
::备份名称前缀
set BAKNAME=mg3MyData ::+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
::+++++++++此目录为备份目录,压缩后会删除,修改时务必注意++++++++
set SRCPATH=%BAKPATH%\%BAKNAME%%TODAY%
::+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ call :Date2Day %date:~,% sdays
set /a sdays-=
call :Day2Date %sdays% difdate echo start bauckup mysql %date:~,%-%date:~,%-%date:~,% %time:~,%:%time:~,%:%time:~,% >>log.log
::关闭mysql服务
net stop mysql
::复制data目录
xcopy %DATAPATH% %SRCPATH%\ /e /y
::开启mysql服务
net start mysql
echo bauckup mysql finish %date:~,%-%date:~,%-%date:~,% %time:~,%:%time:~,%:%time:~,% >>log.log ::压缩数据库文件并删除
"C:\Program Files\WinRAR\WinRAR.exe" a -r -ep2 -ibck -inul -df -t %SRCPATH%.rar %SRCPATH%\
echo compress mysql data finish %date:~,%-%date:~,%-%date:~,% %time:~,%:%time:~,%:%time:~,% >>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=%dd%%%,mm=%mm%%%
set /a z=-mm,z/=,y=yy+-z,m=mm+*z-,j=*m+
set /a j=j/+dd+y*+y/-y/+y/-
endlocal&set %=%j%&goto :EOF :Day2Date
setlocal ENABLEEXTENSIONS
set /a i=%,a=i+,b=*a+,b/=,c=-b*,c/=,c+=a
set /a d=*c+,d/=,e=-*d,e/=,e+=c,m=*e+,m/=,dd=*m+,dd/=
set /a dd=-dd+e+,mm=-m/,mm*=,mm+=m+,yy=b*+d-+m/
(if %mm% LSS set mm=%mm%)&(if %dd% LSS set dd=%dd%)
endlocal&set %=%yy%%mm%%dd%&goto :EOF

2、创建任务计划

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