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)
 Backups deletion

Author  Topic 

sqlfresher2k7
Aged Yak Warrior

623 Posts

Posted - 2012-04-25 : 13:52:04
I would like automate the deletion of the backups after 2 days.
How can i achieve this..

Sachin.Nand

2937 Posts

Posted - 2012-04-25 : 13:52:56
Powershell,VBscript,batch files etc etc...

After Monday and Tuesday even the calendar says W T F ....
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2012-04-25 : 14:15:14
Here's one I like (command-line/batch file):

forfiles /P Z:\Backup /M *.BAK /D -2 /C "cmd /c @del @path"
Go to Top of Page

Lumbago
Norsk Yak Master

3271 Posts

Posted - 2012-04-26 : 04:02:00
quote:
Originally posted by robvolk

Here's one I like (command-line/batch file):

forfiles /P Z:\Backup /M *.BAK /D -2 /C "cmd /c @del @path"

Is this standard command-line?? If so it's quite elegant in comparison the the stuff I keep setting up

- Lumbago
My blog-> http://thefirstsql.com/2011/07/08/how-to-find-gaps-in-identity-columns-at-the-speed-of-light/
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2012-04-26 : 07:23:46
I've been using the for command for years and just stumbled on forfiles about 1 year ago. The one huge advantage with forfiles is its date features, which for doesn't do well.

Hard to say if it's standard, I know most people don't use either command.
Go to Top of Page

senthil_nagore
Master Smack Fu Yak Hacker

1007 Posts

Posted - 2012-04-26 : 07:31:28
Use Backup Expire Option..

Will delete automatically after <2> days..

Senthil Kumar C
------------------------------------------------------
MCITP - Database Administration SQL SERVER 2008
MCTS - Database Development SQL SERVER 2008
Go to Top of Page

sqlfresher2k7
Aged Yak Warrior

623 Posts

Posted - 2012-04-26 : 09:16:26
Thanks senthil_nagore

Does the Backup Expire option will delete the backups physically from the backup location?
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2012-04-26 : 09:21:25
Backup expiration doesn't delete files, it allows the backup contained in the file to be overwritten. If you were using a single backup file or device you'd never delete it, and use expiration to prevent it from growing too large.
Go to Top of Page

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2012-04-26 : 09:51:03
Nice script Rob. I love command line scripts. Take away my mouse, but not my keyboard.
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2012-04-26 : 10:09:57
Fortunately that's one of my cleaner command line utilities. I've written some INSANE stuff with FOR that should never have happened:

http://weblogs.sqlteam.com/robv/archive/2011/08/10/t-sql-tuesday-21-crap.aspx
Go to Top of Page

mumbaidba
Starting Member

1 Post

Posted - 2012-04-28 : 07:32:13
Unless you want to use scripts (and nothing else) for achieving your objective there is cleanup task available when you are setting up a backup maintenance plan in SQL Server, in that case all you have got to do is to attach the cleanup task to the backup task and specify the directories and the period after which backups are deleted, it is quite user friendly so i suggest you give this a try as well.

you can also find additional details at the following URL:

http://msdn.microsoft.com/en-us/library/ms177182.aspx

I like the scripting option as well though, i guess it gives you that much more control.
Go to Top of Page

sqlfresher2k7
Aged Yak Warrior

623 Posts

Posted - 2012-05-01 : 11:53:45
Thanks Mumbaidba
Go to Top of Page
   

- Advertisement -