Ubuntu 上的 MS-SQL:无法恢复 database.bak 文件

MS-SQL on Ubuntu: unable to restore database.bak file

我无法恢复数据库备份 (db.bak)。

给定以下交易-SQL:

1> RESTORE DATABASE db
2> FROM DISK = '/var/opt/mssql/db.bak' ;
3> GO

结果:

Msg 5133, Level 16, State 1, Server mbü-lubuntu, Line 1
Directory lookup for the file "D:\Program Files\Microsoft SQL 
Server\MSSQL12.MSSQLSERVER2014\MSSQL\DATA\db.mdf" failed with the operating     
system error 2(The system cannot find the file specified.).
Msg 3156, Level 16, State 3, Server mbü-lubuntu, Line 1
File 'db' cannot be restored to 'D:\Program Files\Microsoft SQL 
Server\MSSQL12.MSSQLSERVER2014\MSSQL\DATA\db.mdf'. Use WITH MOVE to     
identify a valid location for the file.
Msg 5133, Level 16, State 1, Server mbü-lubuntu, Line 1
Directory lookup for the file "D:\Program Files\Microsoft SQL 
Server\MSSQL12.MSSQLSERVER2014\MSSQL\DATA\db_log.ldf" failed with the     
operating system error 2(The system cannot find the file specified.).
Msg 3156, Level 16, State 3, Server mbü-lubuntu, Line 1
File 'db_log' cannot be restored to 'D:\Program Files\Microsoft SQL 
Server\MSSQL12.MSSQLSERVER2014\MSSQL\DATA\db_log.ldf'. Use WITH MOVE to     
identify a valid location for the file.
Msg 3119, Level 16, State 1, Server mbü-lubuntu, Line 1
Problems were identified while planning for the RESTORE statement. Previous 
messages provide details.
Msg 3013, Level 16, State 1, Server mbü-lubuntu, Line 1
RESTORE DATABASE is terminating abnormally.

我什至想知道,为什么代理在 Linux 程序中寻找 Windows 路径(D:\Program Files...)?

/var/opt/mssql/mssql.conf:

[EULA]
accepteula = Y

[sqlagent]
enabled = true

[filelocation]
defaultbackupdir = /var/opt/mssql/data/
defaultdatadir = /var/opt/mssql/data/
defaultdumpdir = /var/opt/mssql/data/
defaultlogdir = /var/opt/mssql/data/

谢谢!

可能是因为数据库是在 Windows 上创建和备份的。数据库记住它来自哪里,并尝试恢复到同一个地方。

您可能需要使用 restore statementWITH MOVE 子句,正如错误消息指出的那样。

基什内尔是对的。你的错误说明了这一点:

"文件 'db_log' 无法恢复到 'D:\Program Files\Microsoft SQL Server\MSSQL12.MSSQLSERVER2014\MSSQL\DATA\db_log.ldf'。使用 WITH MOVE 到
确定文件的有效位置。"

还原命令如下所示:

USE [master];
GO
RESTORE DATABASE [db] FROM DISK = N'/var/opt/mssql/db.bak'
WITH MOVE '<file_name>' TO '<file_location>'
, MOVE '<file_name>' TO '<file_location>'
...;
GO

假设你有一个目录/data/,数据库有两个文件(一个数据文件和一个日志文件)。以下是实践中的说法:

USE [master];
GO
RESTORE DATABASE [db] FROM DISK = N'/var/opt/mssql/db.bak'
WITH MOVE 'db' TO '/data/db.mdf'
, MOVE 'db_log' TO '/data/db_log.ldf'
...;
GO

记住 Linux 区分大小写。如果您不知道可以将日志和数据文件放在哪里。将其粘贴在与 master 数据库文件相同的位置 (exec sp_helpdb 'master').

爱与亲吻, A-