sqlserver 2005定时任务计划批量文件备份脚本

发布时间:2020-05-16编辑:脚本学堂
本文介绍了sql server 2005中定时任务计划实现批量文件备份的脚本,需要的朋友参考下。

数据库同时备份sqlserver数据库备份。

一个多数据库同时备份的脚本
 

复制代码 代码示例:
@echo off
set svr=sqldb
set svrrole=bozch
set nowtime=%date:~0,10% %time%
set year=%date:~0,4%
set month=%date:~5,2%
set day=%date:~8,2%
set today=%year%-%month%-%day%
if "%time:~0,1%" == " " (set nowh=%time:~1,1%) else (set nowh=%time:~0,2%)
  set rar="c:Program FilesWinRARRar.exe"
  set rarlist="D:backupdbscriptrarlst.txt"
  set ftplist="D:backupdbscriptftplst.txt"
  set baklog=D:backupdbscripttkblbackup.log
@echo. >> %baklog%
@echo -------------------------------------------------- >> %baklog%
@echo %nowtime% BackupScript is starting....... >> %baklog%
::数据库备份语句,可添加多个数据库
  for %%a in (test) do (
  @echo %nowtime% BackupDB %%a is beginning....... >> %baklog%
  @osql -s localhost -U sa -P sa -Q "backup database %%a to disk='D:backupdbbackupdb%%a_%svr%_%today%.bak' with init" >> %baklog%
  echo D:backupdbbackupdb%%a_%svr%_%today%.bak >> %rarlist%
  )
::Rar files
  %rar% a D:backupdbbackupdb%svrrole%_%svr%_%today%.bak.rar @%rarlist%  >> %baklog%
  cd /d D:backupdbbackupdb
  del *.bak
echo. > %rarlist%
@echo -------------------------------------------------- >> %baklog%
@echo. >> %baklog%