windows导出mysql(mysqldump)
dump.bat
echo off
cls
echo 正在初始化环境变量……
echo.
set backup_date=%date:~0,4%%date:~5,2%%date:~8,2%
set db_name=db_test
echo %backup_date%
D:\mysql57\bin\mysqldump -h localhost -uudumpmonitor -pmysql -P13306 %db_name% --default-character-set=utf8 --set-gtid-purged=OFF --skip-tz-utc --skip-disable-keys --skip-add-locks --single-transaction --master-data=2 >D:\mysqlbak\%db_name%_%backup_date%bak.sql
set dbbak_dir=D:\mysqlbak\
echo 删除7天前的备份文件……
echo.
forfiles /P %dbbak_dir% /D -2 -M *bak.sql /C "cmd /c del @file"
##生成检查日志
set mysqlbackup_file=D:\mysqlbak\%db_name%_%backup_date%bak.sql
if exist %mysqlbackup_file% (set file_exist_flag=ok) else (set file_exist_flag=failed)
cd /d D:\mysqlbak\logs
echo %backup_date%^|%file_exist_flag%>mysqlbackup_%backup_date%.log
copy D:\mysqlbak\logs\mysqlbackup_%backup_date%.log C:\mylogs\