A restore failed and the message ends with Msg 3013, RESTORE DATABASE is terminating abnormally. Error 3013 is only the generic "restore failed" message. The real cause is in the error printed above it. Find that number in the table below and go to its section.
Quick lookup
| Error | What it means | Usual fix |
|---|---|---|
| 3154 | The backup is of a different database than the one you are restoring over | Restore to a new name, or use WITH REPLACE deliberately |
| 3159 | The tail of the log has not been backed up | Take a tail-log backup, or use WITH REPLACE if you accept losing it |
| 3101 | Exclusive access could not be obtained; the database is in use | Set the database SINGLE_USER WITH ROLLBACK IMMEDIATE |
| 3201 | Cannot open the backup device (OS error 2, 3 or 5) | Fix the path or the service account's permissions |
| 5133 / 3156 / 1834 | Target data or log file path is invalid or already in use | WITH MOVE to valid, unused paths |
| 3241 | The media family is incorrectly formed | Newer-version backup, damaged copy, or not a SQL Server backup |
| 3132 | The media set has more families than you supplied | Supply every stripe file in the same FROM clause |
| 3169 | The backup is from a newer SQL Server version | Restore to the same or a newer version |
| 4305 | The log backup is too recent to apply | A log backup is missing from the chain |
| 3117 | No files are ready to roll forward | The database was already recovered; start again from the full backup |
| 3183 / 3203 | Read or checksum error in the backup | The backup is damaged; use another copy |
Before you restore: read the backup
Most restore errors can be predicted from the backup's header and file list.
-- Which database, version, backup type and LSNs?
RESTORE HEADERONLY FROM DISK = N'D:\Backup\Sales_FULL.bak';
-- Logical and physical file names (needed for WITH MOVE)
RESTORE FILELISTONLY FROM DISK = N'D:\Backup\Sales_FULL.bak';
-- Can the whole backup be read? Checks page checksums if the backup was taken WITH CHECKSUM
RESTORE VERIFYONLY FROM DISK = N'D:\Backup\Sales_FULL.bak' WITH CHECKSUM;
In HEADERONLY output, DatabaseName, SoftwareVersionMajor, BackupType, FirstLSN and LastLSN answer most of the questions in this sheet.
To find the backups SQL Server recorded for a database, query msdb on the source server:
SELECT bs.database_name, bs.type, bs.backup_start_date, bs.backup_finish_date,
bs.first_lsn, bs.last_lsn, bmf.physical_device_name
FROM msdb.dbo.backupset bs
JOIN msdb.dbo.backupmediafamily bmf ON bs.media_set_id = bmf.media_set_id
WHERE bs.database_name = N'Sales'
AND bs.backup_start_date > DATEADD(DAY, -2, SYSDATETIME())
ORDER BY bs.backup_start_date;
-- type: D = full, I = differential, L = log
Errors about the target database
3154: backup set holds a backup of a database other than the existing database
You are restoring Sales from a backup of Sales_Dev (or of a different database that happens to have the same name). SQL Server refuses to overwrite it silently.
-- Safer: restore beside it under a new name
RESTORE DATABASE Sales_Restore
FROM DISK = N'D:\Backup\Sales_FULL.bak'
WITH MOVE N'Sales' TO N'E:\Data\Sales_Restore.mdf',
MOVE N'Sales_log' TO N'F:\Log\Sales_Restore_log.ldf',
STATS = 10;
Caution
WITH REPLACEoverwrites the existing database and skips the checks that protect you. Use it only after you have confirmed, withRESTORE HEADERONLYandSELECT name FROM sys.databases, that you are overwriting the right database on the right server.
3159: the tail of the log has not been backed up
The target database uses the FULL or BULK_LOGGED recovery model and has log records that are not in any backup. If you restore over it, those transactions are lost.
-- Keep the tail: back it up and leave the database in RESTORING
BACKUP LOG Sales TO DISK = N'D:\Backup\Sales_TAIL.trn' WITH NORECOVERY, CHECKSUM;
Then restore full, differential and logs, ending with the tail-log backup. If you really do not need the tail (for example, refreshing a test copy), use WITH REPLACE.
3101: exclusive access could not be obtained because the database is in use
-- Who is connected?
SELECT session_id, login_name, host_name, program_name
FROM sys.dm_exec_sessions
WHERE database_id = DB_ID(N'Sales');
ALTER DATABASE Sales SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
-- run the RESTORE from this same session, straight away
Your own SSMS Object Explorer or a query window that has Sales as its current database counts as a connection. Run the restore from master. If an application reconnects first and takes the single connection, see the single-user mode (error 924) post.
Errors about files and paths
3201: cannot open backup device
The operating system error that follows tells you why:
| OS error | Meaning | Fix |
|---|---|---|
| 2 | File not found | Check the file name and extension |
| 3 | Path not found | Check the folder; mapped drive letters are not visible to the service |
| 5 | Access is denied | Grant the SQL Server service account read access to the folder or share |
Use a UNC path (\\fileserver\backups\Sales_FULL.bak), not a mapped drive. To check which account to grant access to:
SELECT servicename, service_account FROM sys.dm_server_services;
5133, 3156 and 1834: the target file path is invalid or in use
The backup remembers the source server's file paths. If D:\Data does not exist on the target, or another database already uses that file, the restore fails. Get the logical names from RESTORE FILELISTONLY and move every file:
RESTORE DATABASE Sales
FROM DISK = N'\\fileserver\backups\Sales_FULL.bak'
WITH MOVE N'Sales' TO N'E:\Data\Sales.mdf',
MOVE N'Sales_Data2' TO N'E:\Data\Sales_Data2.ndf',
MOVE N'Sales_log' TO N'F:\Log\Sales_log.ldf',
NORECOVERY, STATS = 10;
Errors about the backup itself
3241: the media family on device is incorrectly formed
Check these causes in order:
- The backup comes from a newer version.
RESTORE HEADERONLYfails too, or shows aSoftwareVersionMajorhigher than the target'sSELECT SERVERPROPERTY('ProductMajorVersion'). A newer backup cannot be restored on an older version. Error 3169 is the clearer form of the same problem. - The copy is incomplete. Compare the file size with the source. Copy it again with a tool that verifies the copy, for example
robocopy. - It is not a native SQL Server backup. A third-party backup tool's file or a
.bacpacneeds its own restore tool.
3132: the media set has N media families but only M are provided
The backup was striped across several files. List all of them in one statement:
RESTORE DATABASE Sales
FROM DISK = N'\\fs\b\Sales_1.bak', DISK = N'\\fs\b\Sales_2.bak',
DISK = N'\\fs\b\Sales_3.bak', DISK = N'\\fs\b\Sales_4.bak'
WITH NORECOVERY, STATS = 10;
3183 and 3203: read failed or checksum error
The backup file is damaged. Run RESTORE VERIFYONLY ... WITH CHECKSUM on any other copies you have and restore the first good one. As a last resort, WITH CONTINUE_AFTER_ERROR restores what it can, followed by DBCC CHECKDB. Treat the result as damaged data, not as a fix.
Errors about the restore sequence
4305: the log in this backup set begins at LSN X, which is too recent to apply
A log backup is missing between the last one restored and this one. Compare the FirstLSN of the failing file with the LastLSN of the previous one using RESTORE HEADERONLY or the msdb query above. Common causes are a backup taken by another tool or job, or one written to a different folder. Find that file and restore it first.
Warning
If the missing log backup no longer exists, you cannot roll forward past it. A later differential backup, if there is one, can bridge the gap. Otherwise the furthest you can recover to is the end of the last log backup before the gap.
3117: no files are ready to roll forward
An earlier step used WITH RECOVERY (the default), so the database is online and will not accept more log backups. Start the sequence again and use NORECOVERY on every step except the last:
RESTORE DATABASE Sales FROM DISK = N'...\Sales_FULL.bak' WITH NORECOVERY, REPLACE;
RESTORE DATABASE Sales FROM DISK = N'...\Sales_DIFF.bak' WITH NORECOVERY;
RESTORE LOG Sales FROM DISK = N'...\Sales_LOG_0100.trn' WITH NORECOVERY;
RESTORE LOG Sales FROM DISK = N'...\Sales_LOG_0115.trn' WITH NORECOVERY;
RESTORE DATABASE Sales WITH RECOVERY;
If the restore fails with a certificate thumbprint message, the backup is TDE-encrypted. See the TDE recovery post instead.
Prevent it next time
- Take every backup
WITH CHECKSUMand runRESTORE VERIFYONLY ... WITH CHECKSUMon a sample of them each day. - Write backups to UNC paths the service account can read on every server that might have to restore them.
- Keep one log backup chain per database. A second tool taking log backups is the most common cause of error 4305.
- Script restores with
MOVEclauses generated fromRESTORE FILELISTONLY, and run a real test restore at least monthly. A backup only counts once you have restored it.
Get the weekly HubDatAI email
One email a week with everything new: posts, learning sessions and videos. Free, no spam, unsubscribe in one click. What you get