Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The tail of the log for the database "DBName" has not been backed up

I tried to restore a database using the following query:

ALTER DATABASE [DatabaseName] SET Single_User WITH Rollback Immediate GO RESTORE DATABASE DatabaseName FROM DISK = 'C:\DBName-Full Database Backup' ALTER DATABASE [DatabaseName] SET Multi_User GO 

but instead of restoring the database, I am getting this error:

Msg 3159, Level 16, State 1, Line 2

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 2 RESTORE DATABASE is terminating abnormally.

like image 875
tereško Avatar asked Sep 11 '12 13:09

tereško


People also ask

What is tail log backup?

A tail-log backup captures any log records that have not yet been backed up (the tail of the log) to prevent work loss and to keep the log chain intact. Before you can recover a SQL Server database to its latest point in time, you must back up the tail of its transaction log.

What would happen if the database transaction log was not present within the database?

If no Transaction Log backup is taken from the database, the Transaction Log file will grow continuously, without truncation, until it runs out of free space.

How do I restore a DB BAK file?

Restore the database from a BAK fileRight-click on the database server in the left navigation pane, click Tasks, click Restore. The name of the restoring database appears in the To database list box. To create a new database, enter its name in the list box. Select 'From device'.

What is the difference between tail log backup and transactional log backup?

Answers. They are essentially the same (a transaction log backup), however the term "tail log backup" is taken by you at a time where your database has a problem and you know you are probably going to perform a recovery of a filegroup or database.


1 Answers

The error message you are getting tells you exactly what you need to do if you don't care about the existing database or log.

RESTORE DATABASE DAtabaseName FROM DISK = 'C:\DBName-Full Database Backup'  WITH REPLACE 

In SQL Server Management Studio (Tasks > Restore), you can add the WITH REPLACE option by opening the page "Options" on the left side and ticking "Overwrite the existing database".

like image 168
tomfanning Avatar answered Oct 29 '22 14:10

tomfanning