windows下Mysql定时备份数据库(支持自动删除过期备份)

windows下Mysql定时备份数据库(支持自动删除过期备份)_第1张图片

 

写MySQL备份及过期处理bat脚本

整理所需批处理指令,保存为一个Bat文件
@echo off
set "yMd=%date:~0,4%%date:~5,2%%date:~8,2%"
set "hms=%time:~0,2%%time:~3,2%%time:~6,2%"
set "bakdays=10"
set "dumpPath=D:\Program Files\MySQL\mysql-8.0.28-winx64\bin\mysqldump.exe"
set "user=root"
set "password=XXX"
set "db=xxx"
set "host=localhost"
set "port=3308"
set "bakpath=E:/ERPJob/AutoBakMysql/dbbakfiles/"
"%dumpPath%"  -h%host% -u%user% -p%password% %db% >%bakpath%backup_SRM_%yMd%%hms%.sql
@echo on
forfiles /p %log_dir% /S /M *.* /D -%bakdays% /C "cmd /c echo 正在删除@relpath 文件… & echo

你可能感兴趣的:(架构之路,数据库,mysql,运维,windows,服务器,数据库)