windows下设置自动备份 mysql 批处理
@ECHO off
echo Backup mysql database orgbbs...
set bakdir=E:\backup\bbs\
if not exist %bakdir% (
mkdir %bakdir%
)
:获取当天日期格式yyyyMMdd
set curdate=%date:~,4%%date:~5,2%%date:~8,2%
set bbsfile=%bakdir%orgbbsx_%curdate%.sql
set ucfile=%bakdir%ucenter_%curdate%.sql
set zipfile=%bakdir%orgbbsx_ucenter_%curdate%.rar
mysqldump -upsyheart -ppsyheart@2012 ucenter >%bbsfile%
mysqldump -upsyheart -ppsyheart@2012 orgbbsx >%ucfile%
echo zip file...
if exist %bbsfile% if exist %ucfile% (
rar a -df %zipfile% %bbsfile% %ucfile%>nul
)
ping 127.1 >nul
if exist %zipfile% (
echo backup success...
) else (
echo Some error happend
)
ping 127.1 >nul
:删除10天前的文件
echo delete 10 days ago files...
forfiles /P %bakdir% /D -10 /c "cmd /c if exist @file del @file"
echo ok
ping 127.1 >nul