Sql-server – Restoring full and differential backups from production to a report server

restoresql server

Running this SQL query:

   RESTORE DATABASE Demo 
   FROM DISK = 'C:\DBBackup\Demo_FULL_Sunday.bak' 
   WITH  NORECOVERY 

   RESTORE DATABASE Demo 
   FROM DISK = 'C:\DBBackup\Demo_Diff_Monday.bak' 
   WITH RECOVERY

I'm getting these errors:

Msg 3117, Level 16, State 4, Line 1
The log or differential backup cannot be restored because no files are ready to rollforward.

Msg 3013, Level 16, State 1, Line 1
RESTORE DATABASE is terminating abnormally.

I have also tried adding WITH REPLACE but no luck. This is meant to restore to a report server, not to the original server that the backup was taken from.

I have tried Googling, however everything I read just says to make sure you are using WITH NORECOVERY.

Best Answer

Although you have WITH NORECOVERY on the 1st statement, the error is actually occurring since there is an existing database with the name Demo which cannot be overwritten without explicit instruction.

Try:

ALTER DATABASE Demo SET SINGLE_USER WITH ROLLBACK IMMEDIATE;

RESTORE DATABASE Demo 
FROM DISK = 'C:\DBBackup\Demo_FULL_Sunday.bak' 
WITH REPLACE, NORECOVERY; 

RESTORE DATABASE Demo 
FROM DISK = 'C:\DBBackup\Demo_Diff_Monday.bak' 
WITH RECOVERY;

Be aware this will totally destroy the existing database and replace it with the contents of the backup file. Ensure you do this on the correct server, since you will have no 2nd chances.