window下数据库自动备份脚本

::换成默认的gbk
chcp 936
rem ******MySQL backup start********
@echo off
::如果没有则创建数据库文件夹
IF NOT EXIST "D:\db_backup" MD "D:\db_backup"
::删除超过30天的备份
forfiles /p "D:\db_backup" /m *_backup_*.sql -d -30 /c "cmd /c del /f @path"

::定义时间
set data_time=%date:~0,4%%date:~5,2%%date:~8,2%
::定义mysqldump.exe所在目录+mysqldump
set "mysqldump=D:\program\mysql-5.7.21-winx64\bin\mysqldump"
::定义mysql连接
set "mysql_connect=--opt --single-transaction=TRUE --user=root --password=nyt@aA? --host=127.0.0.1 --protocol=tcp --port=3306 --default-character-set=utf8 --single-transaction=TRUE --routines --events"

IF NOT EXIST "D:\db_backup\eucenter" MD "D:\db_backup\eucenter"
%mysqldump% %mysql_connect% "eucenter" > D:\db_backup\eucenter\eucenter_backup_%data_time%.sql

IF NOT EXIST "D:\db_backup\mlgl_bm" MD "D:\db_backup\mlgl_bm"
%mysqldump% %mysql_connect% "mlgl_bm" > D:\db_backup\mlgl_bm\mlgl_bm_backup_%data_time%.sql

IF NOT EXIST "D:\db_backup\mlgl_nyt" MD "D:\db_backup\mlgl_nyt"
%mysqldump% %mysql_connect% "mlgl_nyt" > D:\db_backup\mlgl_nyt\mlgl_nyt_backup_%data_time%.sql

IF NOT EXIST "D:\db_backup\sdnyt" MD "D:\db_backup\sdnyt"
%mysqldump% %mysql_connect% "sdnyt" > D:\db_backup\sdnyt\sdnyt_backup_%data_time%.sql

IF NOT EXIST "D:\db_backup\saiku" MD "D:\db_backup\saiku"
%mysqldump% %mysql_connect% "saiku" > D:\db_backup\saiku\saiku_backup_%data_time%.sql

IF NOT EXIST "D:\db_backup\GIS_dlkj" MD "D:\db_backup\GIS_dlkj"
%mysqldump% %mysql_connect% "GIS_dlkj" > D:\db_backup\GIS_dlkj\GIS_dlkj_backup_%data_time%.sql

IF NOT EXIST "D:\db_backup\ncpsc" MD "D:\db_backup\ncpsc"
%mysqldump% %mysql_connect% "ncpsc" > D:\db_backup\ncpsc\ncpsc_backup_%data_time%.sql

IF NOT EXIST "D:\db_backup\ncpscjyzt" MD "D:\db_backup\ncpscjyzt"
%mysqldump% %mysql_connect% "ncpscjyzt" > D:\db_backup\ncpscjyzt\ncpscjyzt_backup_%data_time%.sql

IF NOT EXIST "D:\db_backup\ncpzz" MD "D:\db_backup\ncpzz"
%mysqldump% %mysql_connect% "ncpzz" > D:\db_backup\ncpzz\ncpzz_backup_%data_time%.sql

IF NOT EXIST "D:\db_backup\njtg" MD "D:\db_backup\njtg"
%mysqldump% %mysql_connect% "njtg" > D:\db_backup\njtg\njtg_backup_%data_time%.sql

IF NOT EXIST "D:\db_backup\nykjfw" MD "D:\db_backup\nykjfw"
%mysqldump% %mysql_connect% "nykjfw" > D:\db_backup\nykjfw\nykjfw_backup_%data_time%.sql

IF NOT EXIST "D:\db_backup\nysczl" MD "D:\db_backup\nysczl"
%mysqldump% %mysql_connect% "nysczl" > D:\db_backup\nysczl\nysczl_backup_%data_time%.sql

IF NOT EXIST "D:\db_backup\nysthj" MD "D:\db_backup\nysthj"
%mysqldump% %mysql_connect% "nysthj" > D:\db_backup\nysthj\nysthj_backup_%data_time%.sql
@echo on
rem %data_time%
rem ******MySQL backup end********
::pause

 

转载于:https://www.cnblogs.com/a-fun/p/9391301.html

你可能感兴趣的:(window下数据库自动备份脚本)