DBAtlas · Database operations atlas

Take a tail-log backup before a restore (NORECOVERY / NO_TRUNCATE)

SQL ServerRestore & Recovery

Command

-- A) Healthy DB: back up the tail and put the DB into RESTORING (no new writes):
BACKUP LOG [Musteri]
TO DISK = N'D:\Backup\Musteri_tail.trn'
WITH NORECOVERY, CHECKSUM, INIT;

-- B) Damaged DB / data file lost, log file intact:
-- BACKUP LOG [Musteri]
-- TO DISK = N'D:\Backup\Musteri_tail_damaged.trn'
-- WITH NO_TRUNCATE, CONTINUE_AFTER_ERROR, INIT;

SELECT name, state_desc FROM sys.databases WHERE name = N'Musteri';

What it does

Backs up the part of the log written since the last log backup (the tail), so the restore chain reaches the moment of failure and the last minutes of transactions are not lost.

When to use it

Before restoring over the same database, when the data file disk fails, or at the final cutover of a migration.

Caution

NORECOVERY puts the database into RESTORING and ends user access; do not run it on the wrong database. Restoring WITH REPLACE without a tail-log backup permanently discards the transactions after the last log backup. A backup taken with NO_TRUNCATE may contain incomplete metadata; run DBCC CHECKDB after the restore. A tail-log backup is not possible in SIMPLE recovery.

Open in DBAtlas →

Related