近期为了进行备份策略的调整,需要将应用系统中部分的数据进行下载到另外搭建的备份服务器。因备份服务器为windows,故查找相关资料和论坛上的帖子,梳理了一份适合自己系统的备份脚本(通过BAT文件执行FTP下载任务)。详细需求为:
每天到指定服务器下载名为:after"当天日期".dmp的数据库dump文件,输出脚本如下:
1).ftpUser为ftp服务器的用户名:
2).ftpPWD为ftp用户的密码;
3).ftpIP为服务器地址;
4).ftp脚本中的mget后面可以结合需求自定义下载规则。
- @echo off
- rem Set User Name for Login to FTP Server
- set ftpUser=<USERNAME>
-
- rem Set Password for the FTP User
- set ftpPWD=<PASSWORD>
-
- rem Set the FTP Server IP
- set ftpIP=10.10.6.111
-
- rem Set the RemoteFolder Path
- set RemoteFolder=/app/backup
-
- rem Set LocalFolder Path
- set LocalFolder=D:\DataBackup
-
- rem Get Date For File Name
- nowDate=%date:~0,4%%date:~5,2%%date:~8,2%
-
- rem Define the ftp Command Scripts
- set ftpcmd=%LocalFolder%\1_Scripts\ftp1.txt
- > "%ftpcmd%" (
- echo user %ftpUser% %ftpPWD%
- echo cd "%RemoteFolder%"
- echo lcd "%LocalFolder%"
- echo bin
- echo mget after%nowDate%.dmp*
- echo bye
- )
- @echo on
-
- rem Start Download Files use the Command File. If you want Start a new CMD Session to run it, Use "start " before "ftp"
- ftp -n -i -s:"%ftpcmd%" %ftpIP% >%LocalFolder%\log.txt
-
- del %ftpcmd%
- pause
|