I am using SQL Server 2016. I have setup SQL Agent for Full backup (Weekly) and Transaction Log backup (Daily).
Backup transaction log into a single file using:
BACKUP LOG [XXX] TO DISK = N'E:\SQLDB\Backup\XXX_Trans_Log.bak' WITH RETAINDAYS = 28, NOFORMAT, NOINIT, NAME = N'XXX-Transaction Log Backup', NOSKIP, NOREWIND, NOUNLOAD, STATS = 10
GO
What I expected is only 28 days transaction log backups will be kept. But now I just found All transaction log backups are kept. So the file grows to very large in size.
After finding this, I change the plan to backup log in a separate file each day by:
DECLARE @Ver VARCHAR(2)
DECLARE @File VARCHAR(100)
SET @Ver = (SELECT RIGHT('0' + CAST((DATEPART(DAY,GETDATE())) AS VARCHAR(2)),2))
SET @File = 'E:\SQLDB\Backup\XXX_Trans_Log_' + @Ver + '.bak'
BACKUP LOG [XXX] TO DISK = @File WITH RETAINDAYS = 28, NOFORMAT, INIT, NAME = N'XXX-Transaction Log Backup', NOSKIP, NOREWIND, NOUNLOAD, STATS = 10
I am testing it on testing environment. Basically it works but I found the log size is quite large, as nobody is using the environment. Here are the figures:
DB file size = 500MB (38% free)
Log file Size = 865MB (38% free)
DB Backup (Weekly) = 311MB
Trans Log Backup (Daily)= 277MB
Any reason why the trans log backup so large?