测试环境:WINDOWS2008
::……………………………………………………………………………………………………………………………………………………………………………………………………………………………
:: 版本:BACKDATESYSTEM V1.0
:: 功能:用于系统平台备份程序及数据
:: 特点:按当前日期生成文件名
:: Andy Lu 2:08 2008/06/04
:: MSN: mengyao145@hotmail.com
:: www.edongguan.com & www.softprj.cn
:: pathback、pathSource、pathdatabase、filename、password、letter(接下行)
:: (接上行)baklogPath、bakdatabase、bakdatatime、baktimeStart分别为(接下行)
:: (接上行)备份路径、源路径、数据库路径、备份文件前缀名、密码 (接下行)
:: (接上行)WinRAR安装盘符、日志路径、数据库名、SQL自动备份时间、文档时间
:: bak_ftpServer、bak_ftpUserName、bak_ftpUserPass为FTP地址、用户及密码
::……………………………………………………………………………………………………………………………………………………………………………………………………………………………
set pathback=E:/Project/WebSite_AspNet/AspNet_Test008/DB_2005/
set PathSource=E:/Project/WebSite_AspNet/AspNet_Test008/WebSite
set pathdatabase=E:/Project/WebSite_AspNet/AspNet_Test008/DB_2005
set filename=Andy_WebSite_
set password=andy
set letter=d:
set baklogPath=E:/Project/WebSite_AspNet/AspNet_Test008/DB_2005/
set baktimeStart=%time:~0,2%%time:~3,2%%time:~6,2%%time:~9,2%
set bakdate=%date:~0,4%%date:~5,2%%date:~8,2%
set bakdatabase=dg_gongjiao
set bakdatatime=1126
:: ftp 相关参数
set bak_ftpServer=10.0.0.0
set bak_ftpUserName=andy
set bak_ftpUserPass=andy123456
del %pathback%%filename%*.rar
%letter%/Progra~1/WinRAR/WinRAR.exe a -inul -p%password% %pathback%%filename%%bakdate%%baktimeStart% %pathSource% %pathdatabase%/%bakdatabase%_backup_%bakdate%%bakdatatime%.bak
echo -- 压缩完成,生成%filename%%bakdate%%baktimeStart%.rar …… [%date% %time%] >%baklogPath%log_%bakdate%.txt
echo -- 开始上传 …… [%date% %time%] >>%baklogPath%log_%bakdate%.txt
echo open %bak_ftpServer% >ftp.andy
echo %bak_ftpUserName%>>ftp.andy
echo %bak_ftpUserPass%>>ftp.andy
echo bin >>ftp.andy
:: 是否以天创建文件夹
:: echo mkdir %bakdate% >>ftp.andy
:: echo cd %bakdate% >>ftp.andy
echo mput %pathback%%filename%*.rar >>ftp.andy
echo bye >>ftp.andy
FTP -s:ftp.andy -i >>%baklogPath%log_%bakdate%.txt
del ftp.andy /q
rem Xcopy %bak_tmpFile%* %pathback%%filename% /y
:: del %pathback%%filename%*.rar /q /s
rd %pathback% /q
echo -- 上传完成 [%date% %time%]-- >>%baklogPath%log_%bakdate%.txt
以上代码另存为:Run_back.bat
加入系统的任务中,即可。
在WINDOWS 2008的防火墙中,默认FTP.EXE是禁止的,要在出站和入站的规则均允许此程序方可。
完整 Run_back.bat稍后提供