Quick Answer
Fix SQL Server error 4305 in 3 ways. Restore the missing log, a differential or a new full backup. Error 4305 means your log backup chain has a gap. Find the gap with msdb and RESTORE HEADERONLY first. Missing log fits when you still have the file. Differential fits when the log is lost for good. New full backup fits when no usable chain is left. Test every restore on a copy first.
SQL Server error 4305 appears when a log backup begins at an LSN that is too recent to apply to your database. SQL Server needs an earlier log backup first and refuses the file you chose.
This guide explains what the message means, how to find the missing backup with msdb and RESTORE HEADERONLY and 3 ways to finish the restore.
What is SQL Server Error 4305?
SQL Server error 4305 is a restore error. It stops RESTORE LOG when the first LSN of the log backup is later than the last LSN your database already contains.
Both LSNs appear in the message. These numbers are examples.
Msg 4305, Level 16, State 1
The log in this backup set begins at LSN 42000000032000001, which is too recent to apply to the database. An earlier log backup that includes LSN 41000000028800001 can be restored.
Msg 3013, Level 16, State 1
RESTORE LOG is terminating abnormally.
| Message part | Meaning |
|---|---|
| begins at LSN 42000000032000001 | First LSN of the log backup you tried to restore |
| too recent to apply | A gap sits between your database and this backup |
| includes LSN 41000000028800001 | LSN that SQL Server needs next, found in the lost backup |
| Msg 3013 | RESTORE LOG ended and applied nothing |
According to Microsoft, you must restore every log backup in chronological order after the full or differential backup. If one log backup is lost or damaged, you can restore only the logs before it.
What Causes SQL Server Error 4305?
Five causes produce SQL Server error 4305. This table links every cause to a fix.
| Cause | What happened | Fix |
|---|---|---|
| Missing file | A .trn file was deleted, moved or never copied | Method #1 |
| Wrong order | You restored the log backups out of sequence | Method #1 |
| Outside log backup | Another task or tool took a log backup that your restore set does not contain | Method #1 |
| Broken chain | The recovery model moved to SIMPLE and back to FULL | Method #2 or #3 |
| Log shipping drift | The secondary server missed a log file | Method #1 or #3 |
How do You Find the Missing Log Backup for SQL Server Error 4305?
Four steps locate the gap.
- Copy the two LSNs. Take them from the error message.
- Query msdb on the source server. List every backup for the database in time order.
- Match the needed LSN. Find the log backup whose first_lsn is at or below it and whose last_lsn is above it.
- Check the file. Use RESTORE HEADERONLY when msdb has no record, for example on a new server.
SELECT bs.type, bs.backup_start_date, bs.first_lsn, bs.last_lsn,
bs.database_backup_lsn, bmf.physical_device_name
FROM msdb.dbo.backupset AS bs
JOIN msdb.dbo.backupmediafamily AS bmf ON bs.media_set_id = bmf.media_set_id
WHERE bs.database_name = N'YourDatabase'
ORDER BY bs.backup_start_date;
-- Find the log backup that holds the LSN from the message
SELECT bmf.physical_device_name, bs.first_lsn, bs.last_lsn
FROM msdb.dbo.backupset AS bs
JOIN msdb.dbo.backupmediafamily AS bmf ON bs.media_set_id = bmf.media_set_id
WHERE bs.database_name = N'YourDatabase' AND bs.type = 'L'
AND bs.first_lsn <= 41000000028800001 AND bs.last_lsn > 41000000028800001;
RESTORE HEADERONLY FROM DISK = N'D:\Backups\YourDatabase_log_0900.trn';
RESTORE HEADERONLY returns FirstLSN, LastLSN, DatabaseBackupLSN and BackupType. BackupType 1 is a database backup, 2 is a log backup and 5 is a differential backup. According to Microsoft, the command needs CREATE DATABASE permission.
Heads Up. Replace the database name, the LSN and the file paths with your own values. Test every command on a copy first.
Which 3 Methods Fix SQL Server Error 4305?
Every method ends the error in a different situation. This table shows where it fits.
| Method | Best for | Main limit |
|---|---|---|
| Restore the missing log backup | You still have the missing file | Needs every later log backup too |
| Restore a differential backup | The log is lost but a newer differential exists | No point in time inside the gap |
| Take a new full backup | No usable chain is left | Needs access to the source server |
Method #1: Restore the Missing Log Backup First (Free, Start Here)
This method fills the gap. Restore the full backup, then the lost log file, then every later log in order of first LSN. Microsoft recommends NORECOVERY for every log and a separate recovery step at the end.
- Restore the full backup WITH NORECOVERY.
- Restore the lost log file WITH NORECOVERY.
- Restore every later log backup in order WITH NORECOVERY.
- Finish with RESTORE DATABASE WITH RECOVERY.
RESTORE DATABASE [YourDatabase] FROM DISK = N'D:\Backups\YourDatabase_full.bak' WITH NORECOVERY;
RESTORE LOG [YourDatabase] FROM DISK = N'D:\Backups\YourDatabase_log_0900.trn' WITH NORECOVERY;
RESTORE LOG [YourDatabase] FROM DISK = N'D:\Backups\YourDatabase_log_0915.trn' WITH NORECOVERY;
RESTORE DATABASE [YourDatabase] WITH RECOVERY;
Heads Up. According to Microsoft, a restore that recovers after a middle log backup cannot go further. You must start again from the full backup.
Our guide to the SQL Server NORECOVERY option explains the restoring state in detail.
Method #2: Restore a Differential Backup (Free, Faster)
Differential backups store every data modification since their base full backup. You can move past a lost log backup when a newer differential exists.
- Start with the full backup WITH NORECOVERY.
- Restore the newest differential taken after the gap, also WITH NORECOVERY.
- Confirm the differential belongs to the full backup you restored.
- Restore the log backups taken after the differential, then recover the database.
RESTORE DATABASE [YourDatabase] FROM DISK = N'D:\Backups\YourDatabase_full.bak' WITH NORECOVERY;
RESTORE DATABASE [YourDatabase] FROM DISK = N'D:\Backups\YourDatabase_diff.bak' WITH NORECOVERY;
RESTORE LOG [YourDatabase] FROM DISK = N'D:\Backups\YourDatabase_log_1000.trn' WITH NORECOVERY;
RESTORE DATABASE [YourDatabase] WITH RECOVERY;
You lose the option to restore to a time inside the gap. See create a differential backup in SQL Server and SQL Server point in time restore for the details.
Method #3: Take a New Full Backup (Free, Last Resort)
This method starts a fresh log chain. Take the backup on the source server and restore it on the destination. Log shipping secondaries need the same file to start again.
BACKUP DATABASE [YourDatabase] TO DISK = N'D:\Backups\YourDatabase_new_full.bak' WITH CHECKSUM, STATS = 10;
Full backups add disk activity on a busy server. Schedule yours outside business hours. Follow our create full database backup guide for the steps.
Which Errors Look Like SQL Server Error 4305?
Three restore errors share the same symptom of a refused log backup.
| Error | Cause | Fix |
|---|---|---|
| 4326, too early to apply | The database already contains this log backup | Restore the next log backup in sequence |
| 3117, no files ready to roll forward | The database is not in the restoring state | Restore the full backup WITH NORECOVERY first |
| 3159, tail of the log not backed up | You restore over a live database with unsaved log records | Take a tail log backup first |
Our SQL Server error 3159 guide explains the tail log step.
How do You Prevent SQL Server Error 4305?
Four habits stop gaps before a restore fails.
- One owner for log backups. Use a single scheduled task for every log backup.
- One folder. Copy every .trn file to one folder with the time in the file name.
- Fresh full backup after a recovery model move. Take it right after you switch back to FULL.
- Gap alert. Compare every log backup with the one before it. Use the query below to list breaks in the chain.
WITH l AS (
SELECT database_name, backup_start_date, first_lsn, last_lsn,
LAG(last_lsn) OVER (PARTITION BY database_name ORDER BY backup_start_date) AS prev_last
FROM msdb.dbo.backupset WHERE type = 'L' AND is_copy_only = 0)
SELECT * FROM l WHERE prev_last IS NOT NULL AND first_lsn <> prev_last;
Use our backup and restore strategy in SQL Server guide to plan the schedule.
FAQs
Does SQL Server Error 4305 Mean the Backup File is Corrupt?
No. Your file is healthy but starts later than your database expects. Confirm it with RESTORE VERIFYONLY.
Can You Restore Log Backups Out of Order?
No. According to Microsoft, you must restore log backups in chronological order after the full or differential backup.
Does Error 4305 Appear in Log Shipping?
Yes. Your secondary server fails with this message when it misses one log file. Restore that file or start the secondary again from a fresh full backup.
Does Switching the Recovery Model Break the Log Chain?
Yes. Moving to SIMPLE ends the chain. Take a full backup after you switch back to FULL.
How do You Confirm the Missing Log Backup Exists?
Query msdb for the log backup whose LSN range contains the needed LSN. On a new server, execute RESTORE HEADERONLY on every file and compare FirstLSN and LastLSN.
Can a Differential Backup Replace a Missing Log Backup?
Yes, for moving forward. It does not give you a point in time inside the gap.
Do You Need a New Full Backup After the Restore?
No, when the full chain restored without a gap. Yes, when you used Method #3 or your recovery model moved to SIMPLE.
Final Verdict
A log backup that is too recent to apply always points to a gap in the chain. Find the lost file first, because Method #1 preserves every point in time.
Use Method #2 or #3 only when the file is gone. Microsoft documents the restore order on its apply transaction log backups page and the header columns on its RESTORE HEADERONLY page.
