Search code examples
sql-serverbackupretention

SQL Server set number of Backup to retain


I have already defined a SQL Server Agent job, in order to backup 'mydb' in a specific disk location.

BACKUP DATABASE [MYDB] TO  DISK = N'C:\Dummy.bak' WITH RETAINDAYS = 3;

I planned this job to be performed every day of the week, but not Sunday. The question is: can I set to have n different backup instances in my bak file instead of using n retaindays parameter, AND to delete others?


Solution

  • First, to get a clear understanding about parameter "RETAINDAYS" please go through this following blog link.

    But if I get your issue correctly, your concern is to avoid the Job to execute on Sunday and I think this is configurable in the job scheduling setup. You can select or deselect any day from the week (Under Frequency section) to Execute the job as per your requirement.