HiveBrain v1.2.0
Get Started
← Back to all entries
debugsqlMajor

Restore Backup Fails - File 'Db' cannot be restored to '{...}.mdf'. Use WITH MOVE to identify a valid location for the file

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
cannotmdffilefailsthewithidentifymovevalidfor

Problem

I am getting the following errors trying to do a restore using the restore command on a backup file I recieved from a customer.

RESTORE DATABASE SFDB FROM DISK = N'C:\Backup\Backup.bak'

Any thoughts on what I can do to correct this? It's looking for the mdf, so can I assume that the backup file I have is an incremental backup and not the full backup and that's why it's looking for the mdf?

I am not sure if 1) they have given all the data (the entire db) or 2) I have the right data - and I can do the restore with the right T-SQL commands - I just don't know how.

Help is appreciated.

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.


RESTORE FileListOnly FROM DISK = N'C:\Backup\Backup.bak' shows me the following...

```
LogicalName PhysicalName Type FileGroupName Size MaxSize FileId CreateLSN DropLSN UniqueId ReadOnlyLSN

Solution

Take another look at the output from your first command. There is an error messag in it that points you to the fix.

Look for this section:

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


Basically, the file path on your machine doesn't match the original machine. The MOVE option will let you fix that.

Here is an example of the RESTORE command using the MOVE option:

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


Hope this helps!

Code Snippets

Use WITH MOVE to identify a valid location for the file.
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

Context

StackExchange Database Administrators Q#28082, answer score: 24

Revisions (0)

No revisions yet.