[英]SQL Server Restore Error: Directory lookup for the file “db.mdf” failed
When trying to restore a dbname.bak
file (from a windows machine) for SQL Server on a linux machine using: 尝试使用dbname.bak
命令在Linux计算机上为SQL Server还原dbname.bak
文件(从Windows计算机)时:
RESTORE DATABASE dbname
FROM DISK = '/path/to/dbname.bak'
I got the following error: 我收到以下错误:
Error: Directory lookup for the file "C:\\Program Files\\Microsoft SQL Server\\MSSQL\\DATA\\dbname.mdf" failed with the operating system error 2(The system cannot find the file specified.). 错误:文件“C:\\ Program Files \\ Microsoft SQL Server \\ MSSQL \\ DATA \\ dbname.mdf”的目录查找失败,并显示操作系统错误2(系统找不到指定的文件。)。
SQLState: S0001 SQLState:S0001
ErrorCode: 5133 ErrorCode:5133
and also another error for the dbname_log.ldf
file. 以及dbname_log.ldf
文件的另一个错误。
Why is SQL Server trying to reference windows files on a linux machine, I hear you ask? 为什么SQL Server试图在linux机器上引用windows文件,我听说你问?
Explanation 说明
MS SQL Server assumes by default that the file path(s) saved inside the dbname.bak
is where the database should be restored to. 默认情况下,MS SQL Server假定dbname.bak
保存的文件路径是数据库应还原到的位置。 If the file path(s) don't exist, you'll get an error like that. 如果文件路径不存在,您将收到类似的错误。
Solution 解
Explicitly tell the DB to use a different file(s). 明确告诉DB使用不同的文件。 But first you need to know how the file(s) is (are) referred to by executing the following T-SQL: 但首先,您需要通过执行以下T-SQL来了解文件是如何被引用的:
RESTORE FILELISTONLY FROM DISK = '/path/to/dbname.bak'
which might give you something like this: 这可能会给你这样的东西:
Dbname_Empty
Dbname_Empty_log
which you can then use to execute the following T-SQL: 然后,您可以使用它来执行以下T-SQL:
RESTORE DATABASE dbname
FROM DISK = '/path/to/dbname.bak'
WITH MOVE 'Dbname_Empty' TO '/var/opt/mssql/data/dbname.mdf',
MOVE 'Dbname_Empty_log' TO '/var/opt/mssql/data/dbname.ldf'
hopefully without getting any errors. 希望没有任何错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.