A tail-log backup is a transaction log backup that captures the log records not yet backed up at the moment a database is damaged, taken offline or about to be restored, so that recovery can continue up to the point of failure instead of stopping at the last scheduled log backup. The term comes from Microsoft SQL Server, where it is a defined step in the restore sequence, and it belongs to the core vocabulary of backup & recovery in relational databases.
The tail of the log is the active portion written after the most recent log backup. Without it, every committed transaction since that backup is lost, so the tail-log backup is often the difference between zero data loss and a gap of minutes or hours.
How a tail-log backup preserves the last transactions
A tail-log backup works by reading the active transaction log directly from the log file and writing every record after the last backed-up log sequence number (LSN) into a backup file. Because the log contains the redo information for every committed change, replaying those records during restore brings the database to its final consistent state.
The operation is only meaningful under the full or bulk-logged recovery model. Under the simple recovery model, the log is truncated at each checkpoint and no log chain exists, so there is nothing to capture. In SQL Server the command is BACKUP LOG with options that control how it behaves when the database is damaged or must remain unchanged.
The following table lists the main options and their effect on the source database.
| Option | What it does | Typical situation |
|---|---|---|
| NORECOVERY | Backs up the tail and leaves the database in the restoring state | Planned restore or migration to another server |
| NO_TRUNCATE | Backs up the log even when data files are damaged or missing | Data file loss with an intact log file |
| CONTINUE_AFTER_ERROR | Proceeds despite page or checksum errors | Severely damaged database, best-effort capture |
COPY_ONLY | Takes a log copy without affecting the log chain | Ad hoc copy that must not disturb backup routines |
When a tail-log backup is required
A tail-log backup is required whenever a restore must reach the latest committed transaction and the database still has a readable log file. SQL Server enforces this rule: since version 2005, a RESTORE DATABASE over an existing database in the full recovery model fails with an error unless the tail has been backed up or the operator explicitly uses WITH REPLACE or STOPAT.
The common triggers fall into a small number of scenarios, summarized below with the recommended approach.
| Scenario | Recommended action | Reason |
|---|---|---|
| Data file corruption | Tail-log backup with NO_TRUNCATE | Log survives on a separate volume and holds recent work |
| Planned restore in place | Tail-log backup with NORECOVERY | Freezes the database so no new changes are lost |
| Migration or failover cutover | Tail-log backup with NORECOVERY | Final log is applied on the target with no gap |
| Log file destroyed | No tail-log backup possible | Recovery stops at the last regular log backup |
| Simple recovery model | Not applicable | No log chain is maintained |
The essential precondition is a surviving log file. This is why storage designs place data files and log files on separate physical volumes: a failure of the data volume then leaves the tail intact and recoverable.
The tail-log backup in the restore sequence
In a complete recovery, the tail-log backup is the last link of the log chain and is restored after the full backup, any differential backup and all regular log backups. Each backup in the chain must continue exactly where the previous one ended in terms of LSN, otherwise the restore stops with a gap error.
- Take the tail-log backup of the damaged or source database.
- Bring back the newest full backup, leaving the database in the restoring state.
- Apply a differential backup when available, again without recovering.
- Restore each transaction log backup in order with NORECOVERY.
- Restore the tail-log backup last, with RECOVERY, to bring the database online.
The tail can also serve point-in-time recovery: with the STOPAT option, the restore halts at a chosen timestamp inside the tail, for example just before an accidental DELETE statement. This makes the tail useful not only after hardware failure but also after logical errors.
How it compares with related backup types
A tail-log backup is technically a transaction log backup, but it differs in timing and purpose from routine log backups and from the equivalent mechanisms in other database engines. The comparison below places it among its closest neighbors.
| Concept | When it runs | Main purpose |
|---|---|---|
| Tail-log backup | Once, at failure or before restore | Capture the final unsaved log records |
| Transaction log backup | On a schedule, for example every 15 minutes | Maintain the log chain and limit data loss |
| Full backup | Daily or weekly | Provide the base for every restore |
| WAL archiving | Continuously, per completed segment | PostgreSQL equivalent of a log chain |
| Binary log | Continuously, rotated by size or time | MySQL change record used for replay |
Other engines solve the same problem differently. In PostgreSQL, the last partially filled WAL segment in pg_wal plays the role of the tail and must be copied manually before restoring. In Oracle, RMAN applies online redo logs during recovery when they survive. The concept is universal; the term and the explicit command are specific to SQL Server.
Limitations and common mistakes
The most serious limitation is that a tail-log backup cannot rescue a lost log file. If the log volume fails, recovery ends at the last scheduled log backup, and the interval between log backups becomes the real recovery point objective (RPO).
- Skipping the tail by using
WITH REPLACEoverwrites the database and silently discards recent transactions. - Bulk-logged operations in the tail cannot be captured if the data files holding the changed extents are damaged, so the tail may be unusable.
- Forgetting NORECOVERY during a migration lets users keep writing to the source after the final backup, creating changes that never reach the target.
- Storing the tail on the failing server defeats its purpose; it should be written to independent storage immediately.
- A tail taken with CONTINUE_AFTER_ERROR may contain incomplete metadata, and its restore must be tested before trusting it.
The table below links typical symptoms during restore to their cause and remedy.
| Symptom | Likely cause | Fix |
|---|---|---|
| Tail not backed up error | Restore attempted without capturing the tail | Back up the tail or consciously use REPLACE |
| LSN gap error | A log backup is missing from the chain | Locate the missing file or stop at the gap |
| Database stuck restoring | Final restore issued without RECOVERY | Run RESTORE DATABASE with RECOVERY |
Explained without jargon
A database keeps a running diary of every change it makes. Regular backups copy that diary every few minutes, but the pages written since the last copy exist only on the server. A tail-log backup grabs those final pages before anything else happens.
Imagine a notebook damaged by water while its last few pages are still dry. Copying those dry pages first lets you rebuild everything. The key point: take the tail first, then restore, and almost nothing is lost.
A typical use case
An online retailer keeps customer orders in a SQL Server database configured for full logging, with a nightly full backup and log backups every 15 minutes. Data files sit on one storage array and the log file on another. At 14:07 the data array fails, and the last log backup completed at 14:00.
The database administrator runs BACKUP LOG with NO_TRUNCATE against the intact log file, writing the tail to a network share. She then restores the nightly full backup, all log backups up to 14:00 and finally the tail with RECOVERY on a standby server. All orders placed between 14:00 and 14:07 are recovered, and the shop returns to service in about 40 minutes with zero lost transactions instead of seven minutes of missing orders.