windows下备份mysql和网站

最近使用的一个windows2003下的数据库和网站备份脚本,每天晚上备份网站文件和数据库文件,并只保留最近7天的备份。

 

set today=%date:~0,4%-%date:~5,2%-%date:~8,2%
for /f  %%i in ('dir d:\wamp\bin\mysql\mysql5.5.20\data /ad /b ') do d:\wamp\bin\mysql\mysql5.5.20\bin\mysqldump.exe -u root -proot %%i >d:\wamp\sql\%%i.sql
net stop wampapache
net stop wampmysqld
net stop "Apache Tomcat 6.0 Tomcat6"
7z.exe a -tzip ..\files\%today%-wamp.zip d:\wamp\ -mx0 -xr!u_mtc -xr!6027 >..\files\%today%-wamp.log
net start wampmysqld
net start wampapache
net start "Apache Tomcat 6.0 Tomcat6"
del /q d:\wamp\sql\*
dir ..\files\*.zip /a /b >..\files\%today%-deleting.log
forfiles /p ..\files /d -7 /c "cmd /c del /f @path"
dir ..\files\*.zip /a /b >..\files\%today%-deleted.log

 附,备份sql数据库,只保留最近30天的备份

set BPM=D:\BPMDailyBackup
for /f  %%i in ('dir ..\files\*.bak /a /b ') do 7z.exe a -tzip ..\files\%%i.zip ..\files\%%i -mx0 >..\files\%%i.txt
del ..\files\*.bak
forfiles /p ..\files\ /d -30 /c "cmd /c del /f @path"
for /f  %%j in ('dir %BPM%\*.bak /a /b ') do 7z.exe a -tzip %BPM%\%%j.zip %BPM%\%%j -mx0 >%BPM%\%%j.txt
del %BPM%\*.bak
forfiles /p %BPM%\ /d -30 /c "cmd /c del /f @path"

 

 

 

你可能感兴趣的:(windows,mysql)