恢复备份失败-无法将文件'Db'恢复到'{…} .mdf'。使用WITH MOVE标识文件的有效位置


9

我在从客户收到的备份文件上尝试使用restore命令进行还原时遇到以下错误。

从磁盘还原数据库SFDB = N'C:\ Backup \ Backup.bak'

我有什么想法可以纠正这个问题?它正在寻找mdf,所以我可以假定我拥有的备份文件是增量备份,而不是完整备份,这就是为什么它在寻找mdf?

我不确定1)他们是否提供了所有数据(整个数据库),或者2)我是否拥有正确的数据-我可以使用正确的T-SQL命令进行还原-我只是不知道该怎么做。

感谢帮助。

Msg 5133, Level 16, State 1, Line 2
Directory lookup for the file "D:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\Db.mdf" failed with the operating system error 21(failed to retrieve text for this error. Reason: 15105).
Msg 3156, Level 16, State 3, Line 2
File 'Db' cannot be restored to 'D:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\Db.mdf'. Use WITH MOVE to identify a valid location for the file.
Msg 5133, Level 16, State 1, Line 2
Directory lookup for the file "D:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\Db_log.LDF" failed with the operating system error 21(failed to retrieve text for this error. Reason: 15105).
Msg 3156, Level 16, State 3, Line 2
File 'DbDev_log' cannot be restored to 'D:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\Db_log.LDF'. Use WITH MOVE to identify a valid location for the file.
Msg 3634, Level 16, State 1, Line 2
The operating system returned the error '21(failed to retrieve text for this error. Reason: 15105)' while attempting 'GetVolumeInformation' on 'D:\'.
Msg 3013, Level 16, State 1, Line 2
RESTORE DATABASE is terminating abnormally.

还原FileListOnly FROM DISK = N'C:\ Backup \ Backup.bak'向我显示以下内容...

LogicalName PhysicalName    Type    FileGroupName   Size    MaxSize FileId  CreateLSN   DropLSN UniqueId    ReadOnlyLSN ReadWriteLSN    BackupSizeInBytes   SourceBlockSize FileGroupId LogGroupGUID    DifferentialBaseLSN DifferentialBaseGUID    IsReadOnly  IsPresent   TDEThumbprint
Db  D:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\Db.mdf  D   PRIMARY 29622272    35184372080640  1   0   0   02925462-83CC-4222-8966-53229FA25B1C    0   0   29032448    512 1   NULL    269000000146900238  735C7F0E-F63D-4AA1-AC48-505A084AC00B    0   1   NULL
Db_log  D:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\Db_log.LDF  L   NULL    40239104    2199023255552   2   0   0   71038B04-CBC9-4E4A-93AD-4E1268859CB2    0   0   0   512 0   NULL    0   00000000-0000-0000-0000-000000000000    0   1   NULL
DbDev_filestream    D:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\Db  S   PRIMARY_FILESTREAM  4691012 0   65537   18000000011800001   0   627C9AAA-97BD-4991-9C8C-90C400226A9F    0   0   4784128 512 2   NULL    269000000146900238  735C7F0E-F63D-4AA1-AC48-505A084AC00B    0   1   NULL

Answers:


19

再看一下第一个命令的输出。其中包含错误信息,可将您引向该修复程序。

查找本节:

Use WITH MOVE to identify a valid location for the file.

基本上,您计算机上的文件路径与原始计算机不匹配。该MOVE选项会让你解决这个问题。

这是使用MOVE选项的RESTORE命令的示例:

USE [master]
RESTORE DATABASE [AdventureWorks2008R2] 
FROM  DISK = N'C:\SQL Backups\AdventureWorks2008R2.bak' 
WITH  FILE = 1,  
MOVE N'AdventureWorks2008R2_Data' TO N'C:\MyNewDataLocation\AdventureWorks2008R2_Data.mdf',  
MOVE N'AdventureWorks2008R2_Log' TO N'C:\MyNewLogLocation\AdventureWorks2008R2_Log.ldf',  
MOVE N'FileStreamDocuments2008R2' TO N'C:\MyNewFileStreamLocation\Documents2008R2',  
NOUNLOAD,  REPLACE,  STATS = 1
GO

希望这可以帮助!


2

当我在RESTORE之前执行此命令时,Steven的答案对我有用:

alter database [YourDBName] 
set offline with rollback immediate

并在还原之后:

 alter database [YourDBName] 
 set online

-1

它也可能是访问权限的问题。确保用户在sysadmin角色中。

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.