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
转载请注明出处!