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

在网上找一了一个多数据库同时备份的脚本,之前存在少许问题作了更改,脚本如下:

@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 Files\WinRAR\Rar.exe"
  set rarlist="D:\backupdb\script\rarlst.txt"
  set ftplist="D:\backupdb\script\ftplst.txt"
  set baklog=D:\backupdb\script\tkblbackup.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:\backupdb\backupdb\%%a_%svr%_%today%.bak' with init" >> %baklog%
  echo D:\backupdb\backupdb\%%a_%svr%_%today%.bak >> %rarlist%
  )
::Rar files
  %rar% a D:\backupdb\backupdb\%svrrole%_%svr%_%today%.bak.rar @%rarlist%  >> %baklog%
  cd /d D:\backupdb\backupdb
  del *.bak

echo. > %rarlist%
@echo -------------------------------------------------- >> %baklog%
@echo. >> %baklog%

(引用:http://www.hackbase.com/tech/2011-05-04/63571.html)

你可能感兴趣的:(多数据库同时备份,sqlserver数据库备份)