Sql-server – Transaction Log Truncation with Copy Only

availability-groupsbackuphigh-availabilitysql-server-2012transaction-log

I have a database backup job set to use full backup with the Copy only option on once daily. The copy only is on because from what I have read that is the only way to backup a database that is connected to an availability group. I have log backups happening every 20 minutes using the same options on the same AG. What is the best practice for truncating the transaction logs after these backups run. The full backup is not truncating since its using copy only the same for the log backups. They are growing out of control. I know i can use DBCC SHRINKFILE but the more i read about it the more dangerous it seems. Is there some other method or best practice?

Any advice is appreciated.

Best Answer

I'll be the first to admit the documentation is not very clear on this. They state that you should be offloading your backups to the secondaries, but while most statements are made in a general sense, I think they really mean, specifically, log backups (and copy_only backups, if you have some need for those).

You should occasionally run full backups on the primary IMHO. The copy_only restriction is about full backups, not log backups, and only applies to the secondary AFAIK.

You will not be able to use shrinkfile against your current transaction logs because they are full of activity that has technically not been backed up. Once you take a full (non-copy_only) backup on the primary, then let one log backup run, you should be able to shrink the log file manually. Currently your log backups are working because the database is set to full, but they are continuing to grow because (presumably) you've never run a proper full backup on the primary.

This should be a one-time operation, and you shouldn't shrink them too small; you need to set your primary to be backing up regularly, and you need to accommodate for the largest set of activity that will occur between full or log backups. I won't go on and on about how shrinking files only so they can grow again is a futile exercise and guarantees poor performance, but I could. :-)