Windows 下负责触发备份的 index.bat @echo off & setlocal ENABLEEXTENSIONS
:: 这里只是 SSH 连接和备份路径配置信息 :: 请同时修改同目录下 linux 文件中要备份的路径和 MySQL 数据库
:: SSH 相关信息 set SERVER=192.168.1.100 set PORT=22 set USER=root set PASSWORD=password
:: 和同目录下 linux 文件中配置的路径对应 set BACKUP_PATH=/root/backup
:: 备份要下载到的本机位置(会自动创建) set SAVE_PATH=D:/Backup/
:: ---------- 配置结束,以下请勿修改 ----------
:: 运行时变量 set EXE_SSH=%~dp0/exe/plink.exe set EXE_SCP=%~dp0/exe/pscp.exe set LINUX=%~dp0/linux
set YEAR=%date:~0,4% set MONTH=%date:~5,2% set DAY=%date:~8,2% set TRUE_PATH=%SAVE_PATH%%YEAR%-%MONTH%-%DAY%/
:: 创建备份路径 echo Creating Backup Dir... if not exist %TRUE_PATH% ( mkdir %TRUE_PATH% 2>nul ) if not exist %TRUE_PATH% ( echo Backup path: %TRUE_PATH% not exists, create dir failed. goto exit ) echo Creating Backup Dir... Done.
:: 生成备份目录和文件 echo Connecting to remote server and creating backups... %EXE_SSH% -C %USER%@%SERVER% -P %PORT% -pw %PASSWORD% -m %LINUX% 2>nul echo Connecting to remote server and creating backups... Done.