When the @CleanupTime parameter is used in the [dbo].[DatabaseBackup] procedure, are the targeted old backup files deleted after each successful database backup? Or are all the backups processed first and then cleanup is performed?

I'm having problems with free disk space and trying to give my network administrator an accurate spec for the size of the backup volume.

I read through Understanding CleanupTime in Ola Hallengren's SQL Server scripts in relation to FULL backups and LOG backups before posting. I couldn't find an answer to my question there. If it is there, I missed it. Just read through it again, but still don't see anything.


1 Answer 1


There's a separate @CleanupMode parameter that controls whether cleanup happens before or after. The default behavior is to do the cleanup AFTER. This is the safest option, but requires the most disk space. In the event of a failed backup, nothing is cleaned up, ensuring you have extra files, rather than having deleted a file without making a new one.

This is particularly important if backups were to fail repeatedly (cleaning up, but never making a new one) or when there's a very short retention.

From the documentation:


Specify if old backup files should be deleted before or after the backup has been performed.


  • BEFORE_BACKUP - Delete old backup files before the backup has been performed.
  • AFTER_BACKUP - Delete old backup files after the backup and verify has been performed. If the backup or verify failed, then no backup files are deleted. This is the default.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.