1、创建bat任务脚本(功能:备份数据库并删除30天前备份文件),并运行测试
注:提前建好备份文件目录(不能保护中文);bat文件中不能包含中文
@echo off
@echo begin mysqldump
set hour=%Time:~0,2%
if "%Time:~0,1%"==" " set hour=0%Time:~1,1%
set now=%Date:~0,4%%Date:~5,2%%Date:~8,2%-%hour%%Time:~3,2%%Time:~6,2%
set host=localhost
set port=3306
set user=root
set pass=pass
set dbname=dbname
set back_path=D:\mysql-bak\gnyz
set backupfile=%back_path%\%dbname%-%now%.sql
"C:\Program Files (x86)\MySQL\MySQL Server 5.5\bin\mysqldump" -h%host% -P%port% -u%user% -p%pass% -c --add-drop-table %dbname% > %backupfile%
@echo mysqldump success
@echo begin delete 30-day files
Forfiles /p D:\mysql-bak\gnyz /s /d -30 /m *.* /c "cmd /c del /q /f @path"
@echo delete file success
网友评论