SQLServer备份还原注意
0
新的公司用了好多数据库:es、neo4j、oracle、mysql、mssql。
今天备份还原mssql头都被搞大了,还有安装oracle也是,主要是都是用的docker,以前没用过。
还原mssql一直提示:
Msg 102, Level 15, State 1, Server 9cd172370331, Line 1
Incorrect syntax near '-'.
Msg 319, Level 15, State 1, Server 9cd172370331, Line 1
Incorrect syntax near the keyword 'with'. If this statement is a common table expression, an xmlnamespaces clause or a change tracking context clause, the previous statement must be terminated with a semicolon.
搞了很久才发现,数据库恢复数据库名需要用中括号包起来,关键是简单名称又不需要。
// 没问题
/opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P 'password' -Q "RESTORE DATABASE acgist FROM DISK...
// 有问题
/opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P 'password' -Q "RESTORE DATABASE acgist-test FROM DISK...
// 没问题
/opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P 'password' -Q "RESTORE DATABASE [acgist-test] FROM DISK...