当前位置: 数据库>sqlserver
sqlserver 2005定时任务计划批量文件备份脚本
来源: 互联网 发布时间:2014-08-29
本文导语: 多数据库同时备份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...
多数据库同时备份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%
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%