備份bat:
@set destfile=ICBC_mysql%date:~0,4%%date:~5,2%%date:~8,2%.sql
@set ftpfile=ICBC_mysql%date:~0,4%%date:~5,2%%date:~8,2%.rar
@echo 當天日期:%date:~0,4%%date:~5,2%%date:~8,2%
@echo 備份文件:%destfile%
@F:
@cd \bak_mis
@echo 正在備份……
@”C:\Program Files\MySQL\MySQL Server 5.1\bin\mysqldump.exe” –opt -uroot -p1234 -P3306–all-databases > %destfile%
@echo 開始壓縮
@”C:\Program Files\WinRAR\Rar.exe” a -ed %ftpfile% %destfile%
@del F:\bak_mis\%destfile%
@echo 備份完成,正在備份到異地FTP……
@echo user nmcx 185700>ftp.txt
@echo bin >>ftp.txt
@echo put %ftpfile% %ftpfile%>>ftp.txt
@echo bye >>ftp.txt
@ftp -i -n XXXX.XXXX.XXXX.XXXX <ftp.txt
@echo 備份順利結束
還原bat:
@set destfile=ICBC_mysql%date:~0,4%%date:~5,2%%date:~8,2%.sql
@set ftpfile=ICBC_mysql%date:~0,4%%date:~5,2%%date:~8,2%.rar
@echo 當天日期:%date:~0,4%%date:~5,2%%date:~8,2%
@echo 還原文件:%destfile%
@D:
@cd \DB_bak
@echo 正在從異地FTP下載文件……
@echo user nmcx 185700>ftp.txt
@echo bin >>ftp.txt
@echo get %ftpfile% %ftpfile%>>ftp.txt
@echo bye >>ftp.txt
@ftp -i -n XXXX.XXXX.XXXX.XXXX <ftp.txt
@echo 開始解壓
@”C:\Program Files\WinRAR\UnRAR.exe” e %ftpfile%
@echo 正在還原數據庫……
@”D:\MySQL\MySQL Server 5.1\bin\mysql.exe” -uroot -p1234 -P3306 < D:\DB_bak\%destfile%
@del %destfile%
@echo 還原順利結束
注:(標紅色部分,分別為ftp的用戶名、密碼和ftp地址)
(標紫色部分,分別為MySQL數據庫的用戶名、密碼和端口)