sqlserver2008用bat脚本备份时报错因为库名有中横杠【原创】

 

提示原因是数据库名字有中横岗“-”

解决方法:用中括号把名字括起来就可以了

call :backupone [数据库名-new]

 

完整备份脚本如下

@ECHO ON

set DATE=%date:/=-%

set bakupfolder=F:\bakup\

rem 1按子目录保存备份文件;0不按

set lay_in_subfolder=1

call :backupone [数据库名-new]

goto :EOF

@ECHO OFF

:backupone

setlocal

echo %1

set dbname=%1

if not exist %bakupfolder%%dbname% mkdir %bakupfolder%%dbname%

if %lay_in_subfolder%==1 (

set subfolder=%dbname%\

)else set subfolder=

rem echo %bakupfolder%%subfolder%%dbname%%stamp%.bak

sqlcmd -U sa -P "密码" -S localhost -Q "backup database %dbname% to disk='%bakupfolder%%subfolder%%dbname%_%date:~0,10%.bak'"

 endlocal&goto :EOF

 

转载请注明出处!

posted @ 2016-06-03 11:27  paul_hch  阅读(617)  评论(0编辑  收藏  举报