SQL Server Log Explorer
SQL Backup & Restore

Tail Log Backup in SQL Server Before You Restore

Andrew Jackson Published: 7 Minutes Reading
On this page

Quick Answer

Take a tail log backup in 3 ways before you restore. Use NORECOVERY for an online database. Use NO_TRUNCATE for an offline database. Use CONTINUE_AFTER_ERROR for a damaged database. Restore this backup last with RECOVERY. Check it with RESTORE HEADERONLY.

Tail log backup is the last log backup you take before a restore. It captures log records that no earlier backup contains. Your restore then loses no committed work.

This guide explains when you need the tail, gives 3 methods to take it and shows how to restore it.

What is a Tail Log Backup in SQL Server?

This backup copies the part of the log that no log backup has captured yet. According to Microsoft, it prevents work loss and protects the log chain from gaps.

It is the last backup of interest in your recovery plan. You restore it after every other log backup and before you bring the database online.

Tail backups apply only to databases that use the FULL or BULK_LOGGED recovery model. Our recovery models and backup types guide explains both models.

When do You Need a Tail Log Backup?

Take the tail before every restore that must reach the latest point in time. This table shows the three cases from Microsoft with the option for every case.

Database state Option What happens
Online and a restore is planned NORECOVERY The database moves to the restoring state and receives no new transactions
Offline and fails to start NO_TRUNCATE SQL Server backs up the active log without truncating it
Damaged CONTINUE_AFTER_ERROR SQL Server attempts the backup past errors

You need no tail in two cases. Either your recovery point sits inside an earlier log backup or you replace the database and need nothing newer than your latest backup.

Heads Up. Without the tail, SQL Server stops your restore with error 3159. Our SQL Server error 3159 guide explains the message.

What are the System and Software Specifications?

These tables list what your server and your backup folder need. Hardware figures come from the Microsoft SQL Server 2022 requirements page.

System Specifications

Component Requirement
Processor x64 processor, 1.4 GHz minimum and 2.0 GHz or faster recommended
Memory 1 GB minimum (512 MB for Express) and 4 GB or more recommended
Storage 6 GB of available space for SQL Server setup
Backup folder Free space that fits your log. Microsoft lists no fixed size so check your log file size first
Operating system Windows Server 2016 or later, Windows 10 version 1607 or later

Software Specifications

Item Requirement
Recovery model FULL or BULK_LOGGED
Permission sysadmin server role, db_owner or db_backupoperator database role
Service account Your SQL Server service account needs access to the backup file location
Client tool SQL Server Management Studio 22 (works with SQL Server 2014 and later) or sqlcmd
Statement rule BACKUP statements cannot execute inside an explicit or implicit transaction

How do You Take a Tail Log Backup?

Three methods fit every database state. Select the one that matches your database.

Method #1: Use SQL Server Management Studio (Free, Online Database)

Select this method when the database is online and you plan a restore.

  • Right click the database in Object Explorer and select Tasks and then Back Up.
  • Confirm the recovery model is FULL or BULK_LOGGED.
  • Select Transaction Log as the backup type and clear the Copy Only Backup box.
  • Add a destination file under Destination.
  • Open the Options page and tick Back up the tail of the log, and leave database in the restoring state.
  • Select OK.

This option equals the NORECOVERY statement in Method #2. Your restore dialog lists the file as Transaction Log (Copy Only).

Method #2: Use T-SQL With NORECOVERY (Free, Online Database)

Microsoft states that an online database needs the NORECOVERY option or the backup fails. This statement also moves the database to the restoring state.

BACKUP LOG [YourDatabase]
TO DISK = N'D:\Backups\YourDatabase_tail.trn'
WITH NORECOVERY;

SQL Server truncates the log after this backup unless you add NO_TRUNCATE or COPY_ONLY. Our SQL Server NORECOVERY option guide explains the restoring state.

Method #3: Use NO_TRUNCATE or CONTINUE_AFTER_ERROR (Free, Offline or Damaged Database)

Select NO_TRUNCATE when the database is offline and fails to start. It works when the log file is accessible and undamaged.

BACKUP LOG [YourDatabase]
TO DISK = N'D:\Backups\YourDatabase_tail.trn'
WITH NO_TRUNCATE;

Select CONTINUE_AFTER_ERROR for a damaged database. Microsoft states that this option succeeds only when the log files are undamaged and the database state fits a tail backup. Your database must also contain no BULK_LOGGED operations.

BACKUP LOG [YourDatabase]
TO DISK = N'D:\Backups\YourDatabase_tail.trn'
WITH CONTINUE_AFTER_ERROR;

Heads Up. When this backup fails you lose every transaction committed after your latest log backup. Schedule regular log backups so that loss remains small.

Backups of damaged databases can carry incomplete metadata. Your log remains valid and usable. Only the restore information in msdb is affected.

How do You Restore With the Tail Backup?

Restore your full backup first and then every log backup in order. Apply your tail log backup last and bring the database online with RECOVERY.

RESTORE DATABASE [YourDatabase] FROM DISK = N'D:\Backups\YourDatabase_full.bak' WITH NORECOVERY;
RESTORE LOG [YourDatabase] FROM DISK = N'D:\Backups\YourDatabase_log1.trn' WITH NORECOVERY;
RESTORE LOG [YourDatabase] FROM DISK = N'D:\Backups\YourDatabase_tail.trn' WITH RECOVERY;

Add a differential backup before the log backups when you have one. Our SQL Server point in time restore guide shows how to stop at a chosen time.

Restores that stop with a log chain message point to a missing or too recent log backup. Our SQL Server error 4305 guide shows how to find it.

How do You Verify Your Tail Log Backup?

Inspect the file with RESTORE HEADERONLY and check the incomplete metadata flag.

RESTORE HEADERONLY FROM DISK = N'D:\Backups\YourDatabase_tail.trn';

SELECT bs.backup_set_id, bs.has_incomplete_metadata
FROM msdb.dbo.backupset AS bs
WHERE bs.database_name = N'YourDatabase'
ORDER BY bs.backup_finish_date DESC;

Column HasIncompleteMetadata shows 1 when metadata is incomplete. Test these statements on a spare server first because we have not executed them on your version.

How do You Avoid Losing the Tail Next Time?

Three habits protect your last transactions before a failure.

  • Schedule log backups. Short intervals between log backups shrink the part of the log that no backup has captured.
  • Check backup history. Query msdb.dbo.backupset weekly and confirm that every database shows a recent log backup.
  • Test your restore. Restore a full backup and a log chain on a spare server once a month. Our backup and restore strategy in SQL Server guide lists the steps.

FAQs

Do You Need the Tail for Every Restore?

No. You need none when your recovery point sits in an earlier log backup or when you replace the database and need nothing newer than your latest backup.

Does the Tail Work in the SIMPLE Recovery Model?

No. Tail backups apply only to the FULL and BULK_LOGGED recovery models.

Does NORECOVERY Take the Database Offline?

No. NORECOVERY moves the database to the restoring state. Users cannot connect until you restore with RECOVERY.

Which Permission do You Need for the Tail?

Membership in sysadmin, db_owner or db_backupoperator. Your SQL Server service account also needs access to the backup file location.

Can You Capture the Tail of a Damaged Database?

Yes. Use CONTINUE_AFTER_ERROR. It succeeds only when the log files are undamaged and the database contains no BULK_LOGGED operations.

Does NORECOVERY Truncate the Log?

Yes. NORECOVERY truncates the log unless you also add NO_TRUNCATE or COPY_ONLY.

Can You Restore the Tail Before Other Log Backups?

No. This backup is the last log backup of your chain. Restore it after every earlier log backup.

Final Verdict

Tail log backup protects your last transactions before a restore. Use NORECOVERY for online databases and NO_TRUNCATE or CONTINUE_AFTER_ERROR when the database is offline or damaged.

Microsoft documents the options on its tail log backups page and the steps on its transaction log backup of a damaged database page.