原理:使用windows任务计划 执行bat脚本
在bat脚本目录中放置以下文件
winrar程序文件夹,upload_db.bat 脚本
upload_db.bat脚本如下:
========================================
@echo off
rem 上面是切换到数据库备份文件夹
echo -----%date%-----[%time%]---->>upload_db.log
rem upload_db.log是自己定义的日志文件
echo 启动Winrar文件压缩程序.....[%time%]>>upload_db.log
echo 开始对数据库文件进行压缩...[%time%]>>upload_db.log
rem 压缩备份文件
%cd%\winrar\winrar a -m5 -r -ag x:\dbbackup\backup_DB_.rar x:\dbbackup\backup_%date:~,4%_%date:~5,2%_%date:~8,2%_*.bak
echo 准备开始FTP上传压缩文件....[%time%]>>upload_db.log
echo open 10.10.10.10>upload.txt
echo username>>upload.txt
echo 123456>>upload.txt
echo cd /backup_catagory>>upload.txt
echo prompt>>upload.txt
echo mput x:\dbbackup\backup_DB_%date:~,4%%date:~5,2%%date:~8,2%*.rar>>upload.txt
echo bye>>upload.txt
rem 上面是FTP服务器的IP地址、用户名、密码和上传的文件类型,(这里可根据实际情况修改)保存到upload.txt中
ftp -s:upload.txt
rem 通过upload.txt中FTP配置信息,进行ftp上传。
echo 数据库压缩文件已上传完毕...[%time%]>>upload_db.log
findstr \C"Not connected" ftp.log
if %errorlevel%==0 (goto D)
findstr \C"Not logged in" ftp.log
if %errorlevel%==0 (goto E) else (goto F)
:D
echo 无法连接到您的FTP服务器....[%time%]>>upload_db.log
echo -------------------------------------------->>upload_db.log
echo.>>upload_db.log
del ftp.log,upload.txt
exit
:E
echo 您的FTP账号密码无法登陆....[%time%]>>upload_db.log
echo -------------------------------------------->>upload_db.log
echo.>>upload_db.log
del ftp.log,upload.txt
exit
:F
echo 数据库压缩文件已上传完毕...[%time%]>>upload_db.log
del upload.txt
rem 删除超过7天的备份文件
forfiles /p x:\dbbackup /m *.rar -d -7 /c "cmd /c del @path"
echo 任务全部执行完毕..[%time%]>>upload_db.log
exit
转载请注明:轮回阁 » sqlserver备份定时上传到FTP并删除旧备份
特别说明:所有资源均无解压密码且可直接下载,若有会特别注明,部分回复可见内容仅为提供更多的下载点。