sql-server-maintenance-solution icon indicating copy to clipboard operation
sql-server-maintenance-solution copied to clipboard

Delete backups from Secondaries when @cleanupMode is set to 'BEFORE_BACKUP'

Open ghost opened this issue 7 years ago • 3 comments

Consider a scenario where you have an AG running across 3 nodes and your backups are being backed up locally. Each node have all the default jobs deployed and scheduled to run at same time. As the databases are part of the AG, backups are only being taken on the PRIMARY NODE. After failover to a different node, the backups stored in the previous PRIMARY are not being deleted.

I thought that this could be happening since the default for the cleanup is AFTER_BACKUP and since no backups were happening on that node, the cleanup was not happening. I tried changing this to 'BEFORE_BACKUP' to no avail.

@olahallengren mentioned in stack exchange ( https://dba.stackexchange.com/questions/206902/cleanup-of-ag-databases-on-secondaries-nodes)

"The current design is that the stored procedure will decide if the database should be backed up. Only if the database should be backed up, it will go into the code that does the work (creates sub-directories, backup, verify, and cleanup).

It could make sense that if you are running with @CleanupMode = 'BEFORE_BACKUP', then it should delete backups, even if the database should not be backed up. "

ghost avatar May 17 '18 10:05 ghost

Bump... Having same issue but we use Secondary for backups.. When failover occurs the existing files on the other node are not ever cleaned up until SQL fails back to that node...

mikeBulava avatar Mar 06 '24 18:03 mikeBulava

Ther is a check for backup preference before backing up. It really shouldn't go ahead if no backup has been done on other node...then it would delete the last backup. And other nodes, running backup, don't have access to delete files on another server unless you share the backup folder... To have this functionality you should run backup against an UNC path, share one backup disk and the the disk area on the other node...or even better, setup a shared folder on another server to get data outside SQL server.

Stiffboard avatar Mar 06 '24 19:03 Stiffboard