SQL Server error message 3159

One of my friends working on SQL Server 2000 to 2005 faced following issue.

Msg 3159, Level 16, State 1, Line 1
The tail of the log for the database “databasename” has not been backed up.
Use BACKUP LOG WITH NORECOVERY to backup the log if it contains work you do not want to lose.
Use the WITH REPLACE or WITH STOPAT clause of the RESTORE statement to just overwrite the contents of the log.
Msg 3013, Level 16, State 1, Line 1
RESTORE DATABASE is terminating abnormally.

-- worked well on 2000 - failed on 2005
RESTORE DATABASE mydb2000 
FROM DISK = 'C:\mydbbackup.bak' WITH 
MOVE 'mydb2000_Data' TO 'E:\mydb\Data', 
MOVE 'mydb2000_Log' TO 'D:\mydb\log'

As mentioned in the error detail mentioned above, the backup failed because tail log backup is not available. The error message further states that to resolve overwrite the log by using WITH REPLACE/STOPAT option. The T-SQL to fix the error is given below

   
 -- drop connections to database
ALTER DATABASE mydb2000 SET SINGLE_USER WITH ROLLBACK IMMEDIATE
-- Restore WITH REPLACE
RESTORE DATABASE mydb2000 
FROM DISK = 'C:\mydbbackup.bak' WITH 
MOVE 'mydb2000_Data' TO 'E:\mydb\Data', 
MOVE 'mydb2000_Log' TO 'D:\mydb\log' ,REPLACE
-- Set database to multi_user
ALTER DATABASE mydb2000 SET MULTI_USER

 

Like us on FaceBook Join the fastest growing SQL Server group on FaceBook

   

Leave a Reply

Your email address will not be published.