A recent question got me looking at MS Documents and wondering.
Is there a limit to how many backups can be appended to a single file?
By default SQL Server uses NOINIT
to append new backups to the old backup file.
{ NOINIT | INIT } Controls whether the backup operation appends to or overwrites the existing backup sets on the backup media. The default is to append to the most recent backup set on the media (NOINIT). Source
The documents clearly say that lack of free disk space will cause an appended backup to fail.
If a disk file fills while a backup operation is appending a backup to the media set, the backup operation fails. The maximum size of a backup file is determined by the free disk space available on the disk device; therefore, the appropriate size for a backup disk device depends on the size of your backups. Source
The answer at SQL Recover from .bak file with NOINIT indicates that the Position
from RESTORE HEADERONLY
indicates the individual backup in the file. Which is a "smallint" field, which should max out at 32,767
For the most part when googling around, you find people who are accidently appending their backups, and can't understand why the backups are so big.
I don't find any clear references on how many backups can be appended, assuming sufficient disk space. Is the limit 32,767 or something else entirely?
Best Answer
TL:DR; It is possibly to put 32,000+ backups on a single file. If this is good thing or if you can recover from a backup on this file is not addressed here.
I started taking tlog backups last night, on an existing database (231682) with no activity. I used a while loop and a counter so I could get a running total.
sp_whoisactive
shows wait info (2029ms)BACKUPTHREADsp_whoisactive
shows wait info (52113ms)BACKUPTHREAD time between backups has slowed to about 70 seconds per log backup.restore headeronly from disk='G:\SQLBackups\Test_Tlog.trn'
Did not attempt a database restore, as it would be beyond painful. Set counter to startSET @counter = 13717
and restart adding backups to the same file with the same code. Backups resume and are taking about 80 secondsRAISERROR(N'Count equals :%d', 16, 1, @counter ) WITH LOG;
so the running count displays in the SQL error log Thank you @Erik Darlingrestore headeronly from disk='G:\SQLBackups\Test_Tlog.trn'
Count is 32,021BackupSize
and a value of ~4,000 forCompressedBackupSixe
, Compressed size varies on each backup.I am compressing backups by default on this instance.
Week 3 Note: File size and backup time is growing out of proportion to number of backups. Looking at tlog headers, we see the backup in position 2 has a size of 75766 bytes and a start to finish time of one second or less. The backup in position 22919 also has a size of 75766 bytes and a start to finish time of one second or less. The overhead of appending the backups to the same file seems be causing the slow down. The abnormal growth is probably related to weekly maintenance tasks I have running on the instance.
Off site backups, It looks like my offsite backup solution (IBM Spectrum) is not backing up the trn file. I suspect this is because the file is constantly being edited.
Edit, some time later. I was considering doing another experiment to test recovery at around 30,000 backups. To avoid the issues of trying to restore multiple t-logs I looked at using differential backups. I created an empty database, took a full backup and then took 10 differential backups. Then I took 10 t-logs backups and using
RESTORE HEADERONLY FROM DISK
I compared the size, the differential backups are significantly larger then the t-logs, I don't have a enough space to perform a good test.Differential backups 2-10 (first is always a bit bigger)
T-Logs backups 2-10 (first is always a bit bigger)
Differential backups are about 16 times larger, best case I could only get about 2,000 of them, I am not doing further testing at this time.