How do I get more control over backup file retention using Ola Hallengren's DatabaseBackup solution?
This can occur when you have variations in the runtime of your backups. If your backup job executes faster one day it may be less than 48 hours since the oldest file was created, so it will not remove it and leave you with 3 files.

Example:


Backup1 created on 2019-06-17 at 21:01 - deletes backups created on or before 2019-06-15 21:01
Backup2 created on 2019-06-17 at 21:03 - deletes backups created on or before 2019-06-16 21:03
Backup3 created on 2019-06-17 at 20:59 - deletes backups created on or before 2019-06-17 20:59 which does not include Backup1


The easiest solution I've found for this is to subtract a few hours from the CleanupTime value. Setting to 40 or even 45 in the example above would mean Backup1 was deleted after Backup3 was taken.