Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 SQL Server Administration (2008)
 FORFILES and deleting old files.

Author  Topic 

ravilobo
Master Smack Fu Yak Hacker

1184 Posts

Posted - 2011-07-29 : 12:42:27
As a part of moving away from maintenance plans, we are using the following code to purge the old backup files.

for %i in (bak,bkp) do forfiles -p d:\dbbackups -s -D -2 -m *.%i -c "cmd /c del @FILE"

This works well; however, when there are no files to delete, the code errors out and the sql job fails with following exception.

ERROR: No files found with the specified search criteria.
Any suggestions? Or is there a better way to achieve this?


------------------------
I think, therefore I am - Rene Descartes

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-07-29 : 13:12:17
one way of doing this is using a ssis package. I assume your backups are all stored in a common location.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

ravilobo
Master Smack Fu Yak Hacker

1184 Posts

Posted - 2011-07-29 : 14:10:59


I guess, maintenance plans itself are stored in a SSIS package. I don’t want a SSIS solution.

We have several servers involved, and the folder structure varies slightly. I am looking for a simpler solution.


------------------------
I think, therefore I am - Rene Descartes
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-07-29 : 14:17:16
SSIS is not that much complex. it cant be used even when multiple servers are involved and also folder structure varies.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -