1 @ECHO off 2 3 TITLE databaseBackup 4 5 E: 6 7 REM : 源数据库: IP 端口 用户名 密码 8 SET DB_HOST=192.168.1.1 9 SET DB_PORT=3306 10 SET DB_USER=xxxxxx 11 SET DB_PSWD=xxxxxxxx 12 SET DB_TIME=%date:~,4%-%date:~5,2%-%date:~8,2% %time:~,2%:%time:~3,2%:%time:~6,2% 13 14 CD E:APIsqlbackup 15 16 REM : 判断文件夹是否存在, 存在就先删除, 然后创建一个新的文件夹 17 IF EXIST %DB_TIME% ( 18 DEL /s /q %DB_TIME% 19 ) 20 MD %DB_TIME% 21 22 CALL:myBackupFunction database_name 23 24 PAUSE 25 26 :myBackupFunction 27 REM : 备份数据库 28 CALL mysqldump -h%DB_HOST% -u%DB_USER% -p%DB_PSWD% -P%DB_PORT% %~1 --add-drop-database > E:APIsqlbackup\%DB_TIME%\%~1.sql 29 ECHO ========================================== backup %~1 done ========================================== 30 :myBackupFunctionEnd