rem
rem C:\Program Files\WinRAR 需要放到 path 下,才能调用rar cli工具
rem
rem 跳转到工作目录下
f:
cd f:\DBBAK
rem 设置变量:备份文件名
SET BAK_FILE=MY_DBBAK_%date:~0,-4%.sql
rem 设置变量:日志文件名
SET LOG_FILE=MY_DBBAK.log
rem 记录日志
echo "%date%" >> %LOG_FILE%
rem 开始做备份
[color=]mysqldump --default-character-set=utf8 -hlocalhost -uroot -R --triggers --single-transaction -B mydb > %BAK_FILE%
rem 压缩备份文件
rar a %BAK_FILE%.rar %BAK_FILE%
rem 删除源文件
del /F %BAK_FILE%
echo "%date%" >> %LOG_FILE%
echo "" >> %LOG_FILE%