批处理备份SQL Server(原创)

set SQLCMD=C:\Program Files\Microsoft SQL Server\90\Tools\Binn\
set PATH=%SQLCMD%;%PATH%
set BAKPATH=D:\test\
set DBNAME=test
REM set DATES=%date:~0,4%%date:~5,2%%date:~8,2%
set DATES=%date:~10,4%%date:~4,2%%date:~7,2%_%time:~0,2%%time:~3,2%
set HOST_NAME=HRCOMP
set DBUSER=HR
SQLCMD.exe -H %HOST_NAME% -U %DBUSER% -P 1234 -d master -Q "BACKUP DATABASE %DBNAME% to disk='%BAKPATH%%DBNAME%_%DATES%.bak'"


============简写=============
set SQLCMD=C:\Program Files\Microsoft SQL Server\90\Tools\Binn\
set PATH=%SQLCMD%;%PATH%
set BAKPATH=D:\test\
set DBNAME=test
REM set DATES=%date:~0,4%%date:~5,2%%date:~8,2%
set DATES=%date:~10,4%%date:~4,2%%date:~7,2%_%time:~0,2%%time:~3,2%
SQLCMD.exe  -d master -Q "BACKUP DATABASE %DBNAME% to disk='%BAKPATH%%DBNAME%_%DATES%.bak'"

===========兼容版===========
set BAKPATH=D:\test\
set DBNAME=test
REM set DATES=%date:~0,4%%date:~5,2%%date:~8,2%
set DATES=%date:~10,4%%date:~4,2%%date:~7,2%_%time:~0,2%%time:~3,2%
OSQL.exe  -E -d master -Q "BACKUP DATABASE %DBNAME% to disk='%BAKPATH%%DBNAME%_%DATES%.bak'"

==========win2000 and sql server 2000=======
set BAKPATH=D:\HR_db20110214bak\
set DBNAME=test
REM set DATES=%date:~0,4%%date:~5,2%%date:~8,2%
set DADA=%date:-=%
set TITI=%time::=%
set DATES=%dada:~4,14%_%titi:~0,6%
OSQL.exe  -E -d master -Q "BACKUP DATABASE %DBNAME% to disk='%BAKPATH%%DBNAME%_%DATES%.bak'"

posted @ 2011-03-22 18:31  艾阳君  阅读(350)  评论(0编辑  收藏  举报