olahallengren / sql-server-maintenance-solution

SQL Server Maintenance Solution
https://ola.hallengren.com
MIT License
2.91k stars 756 forks source link

backup cleanuptime cannot be changed when using @modificationlevel #666

Open wfvdijk opened 2 years ago

wfvdijk commented 2 years ago

I am doing DIFF backups unles the modification level is above a certain treshold. DIFF backups should only last for 24 hours, FULL backups for 2 weeks. However, I cannot specify a retentiontime for every backuptype. If I specify 24 hours and the backup is switching from DIFF to FULL, a lot of my FULL backups got deleted (the ones older than 24 hours) I currently have the @cleanuptime set to 2 weeks, but as a result I got a lot of unnecessary DIFF backups.

In order to fix this I would like to change the @retentiontime to @retentionTimeLog, @retentiontimeDiff and @retentiontimeFull

olahallengren commented 20 hours ago

I have been looking at this.

Currently the code looks like this:

      -- Delete old backup files, after backup
      IF ((@CurrentBackupOutput = 0 AND @Verify = 'N')
      OR (@CurrentBackupOutput = 0 AND @Verify = 'Y' AND NOT EXISTS (SELECT * FROM @CurrentBackupSet WHERE VerifyOutput <> 0 OR VerifyOutput IS NULL)))
      AND (@BackupSoftware <> 'DATA_DOMAIN_BOOST' OR @BackupSoftware IS NULL)
      AND @CurrentBackupType = @BackupType

As you see, cleanup will not be performed when the backup type is changed. This is to protect against scenarios, where you have different retentions for the different backup types.

I will consider introducing additional parameters as you suggest.