Delete backup files older than 7 days

Posted by rockbala on Stack Overflow See other posts from Stack Overflow or by rockbala
Published on 2009-12-13T06:10:41Z Indexed on 2010/03/21 2:31 UTC
Read the original article Hit count: 269

Filed under:
|

Using osql command, SSQL backup of a database is created. It is saved to Disk. Then renamed to match the date of the day backup was taken. All these files are saved in a single folder all the time.

for example: Batch1.bat does the following 1) Created backup.bak 2) renamed to backup 12-13-2009.bak (this is done by the combination of % ~ - etc to get the date parameter)

This is now automated to take backup everyday by Task scheduler in Windows.

Can the batch file also be modified to delete backup files older than 7 days? if so, how ?

If it is not possible via batch file, other than manually deleting the files are there any other alternatives to automate the deleting job ?

Thanks in advance, Balaji S

© Stack Overflow or respective owner

Related posts about sql

Related posts about backup