标签:
客户需要对网站进行定期备份,并保留最近30天的文件,编写后以下脚本,通过Windows的任务计划进行调度
对比手工和任务计划调度运行情况来看,手工运行中可直接调用RAR.exe和网络进行传输,但是任务计划调度则需要调用安装RAR的程序并且无法进行网络进行传输
1 :: 用于备份网站文件 2 rem ***********************需要配置*********************************** 3 rem 设置需要备份目录 4 set sourcePath=D:\esa_app\ekp-j\ekp 5 6 rem 存放压缩文件远程服务器地址、用户名和密码 7 set remoteServerPath=10.164.117.75 8 set remoteUserName=administrator 9 set remotePassword=admin12345! 10 11 rem 远程服务器存放备份文件目录 12 set remoteTargetPath=d$\ekp_back 13 14 rem 压缩程序路径 15 set rarProgExePath="C:\Program Files (x86)\WinRAR\RAR.exe" 16 rem **************************************************************** 17 18 rem 临时备份目录存放目录 19 set workRootPath=D:\$$TEMP_EKP_BACK 20 21 rem 备份保留份数 22 rem set backupNumber=30 23 set backupNumber=5 24 25 rem 形成备份文件名称和存放路径 26 set workFileName=ekp%date:~0,4%%date:~5,2%%date:~8,2% 27 set backWorkPath=%workRootPath%\%workFileName% 28 set strBatCurrPath=%cd% 29 30 rem 创建备份工作目录 31 if not exist %workRootPath% md /s /q %workRootPath% 32 if exist %backWorkPath% rmdir /s /q %backWorkPath% 33 md %backWorkPath% 34 35 rem 把源文件拷贝到工作目录中 36 xcopy %sourcePath% %backWorkPath% /s /e /h /y >%workRootPath%\log_backup_ekp%date:~0,4%%date:~5,2%%date:~8,2%.log 37 38 rem 压缩文件 39 cd/d "%backWorkPath%\" 40 %rarProgExePath% -y a "%backWorkPath%.rar" -r * 41 42 rem 把压缩文件传送到远程服务器进行备份 43 net use \\%remoteServerPath% %remotePassword%/user:%remoteUserName% 44 xcopy /y "%backWorkPath%.rar" \\%remoteServerPath%\%remoteTargetPath% 45 46 rem 在远程服务器保留最新文件,份数按照设置进行保留 47 for /f "skip=%backupNumber% delims=" %%i in (‘dir /s /b /o-d \\%remoteServerPath%\%remoteTargetPath%\*.rar‘) do del /f /q "%%i" 48 49 rem 删除工作目录和压缩文件 50 cd/ 51 rmdir /s /q %backWorkPath% 52 del /f /q "%backWorkPath%.rar"
标签:
原文地址:http://www.cnblogs.com/shishanyuan/p/4633031.html