Villain博客

您现在的位置是:首页 > 技术笔记

技术笔记

windows自动备份mysql数据库bat脚本

2020-09-09技术笔记
windows自动备份mysql数据库bat脚本
@echo off
echo Perform backup tasks
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%
echo %now%
set host=localhost
set port=3306
set user=root
set pass=rootpass
set dbname=Weekly%backup
set backupfile=D:\mysqlautobackup\%dbname%-%now%.sql
"D:\PHPWEB\MySQL Server 5.6\bin\mysqldump" -h%host% -P%port% -u%user% -p%pass% -c --all-databases > %backupfile%
echo delete files before 30 days
forfiles /p D:\mysqlautobackup /s /m *.sql /d -30 /c "cmd /c del @file /f"
echo Exiting the backup task
ping /n 3 127.0.0.1 >nul
exit