下面的批处理脚本,可以自动备份mysql数据库整个库,按日期保存,并且自动会删除给定天数前的备份,减少控件占用。
; 下面是redmine的备份脚本,每天自动计划任务0点运行即可。
@echo off
net stop redmineApache
set today=%date:~0,4%-%date:~5,2%-%date:~8,2%
C:\Bitnami\redmine-3.4.6-0\mysql\bin\mysqldump -h 127.0.0.1 -P 3306 -uroot -pyourpassword --lock-all-tables --all-databases > mysql_%today%.sql
"C:\Program Files\7-Zip\7z.exe" a mysql_%today%.zip mysql_%today%.sql
del mysql_%today%.sql
"C:\Program Files\7-Zip\7z.exe" a -r redmine_files_%today%.zip C:\Bitnami\redmine-3.4.6-0\apps\redmine\htdocs\files
REM 删除20天前的备份
forfiles /m mysql_*.zip /d -20 /c "cmd /c del @file"
forfiles /m git_*.zip /d -20 /c "cmd /c del @file"
forfiles /m redmine_files_*.zip /d -20 /c "cmd /c del @file"
net start redmineApache