Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Urgent:VB Script to delete 2-days old backup automatically Expand / Collapse
Author
Message
Posted Thursday, February 28, 2008 6:20 PM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Wednesday, February 8, 2012 3:19 AM
Points: 87, Visits: 61
Hi All,

I have to develope an automation task in SQL server 2005 which can delete 2-days old backup from Netwok drive automatically. It is possible with vb script. But I don't know how to implement it in to the Production server. So, if some body help me in this issue. I want a vb script and stepwise procedure to implement it. I need to create a Job or maintenace plan in SQL Server 2005 ? I have to delete older back up in network drive so, how can i give the path. Please help me.

I will really appreciate all of you. Looking for your reply...urgent please...

Regards,

KP
Post #462107
Posted Thursday, February 28, 2008 6:52 PM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Monday, September 8, 2014 1:18 PM
Points: 2,664, Visits: 830
Attached is a script I was using for a while (drop the .txt extension when you implement it, natch). You can either create a scheduled task in the Windows Task Scheduler or you can create a SQL Agent job with the following CmdExec command:

cscript "c:\scripts\DeleteFiles.vbs" //b //nologo

Just make sure the account that the SQL Agent runs under has rights to the folders in question (the folder the script is in as well as the folder the files to delete are in).

As for the script, you can specify as many folders as you want. You can specify the maximum age of any files in those folders - anything older will be deleted (look for intMaxAge).

Note - this script will look at ALL files in the folder, not just .bak files. I had things sorted into subfolders, so I could afford to be a bit lazy with the script in that respect.

Test it first to get the parameters to what you want them to be. Be aware that the files will be deleted, not moved to the recycle bin. There is no undo.





Scott Duncan

MARCUS. Why dost thou laugh? It fits not with this hour.
TITUS. Why, I have not another tear to shed;
--Titus Andronicus, William Shakespeare


  Post Attachments 
DeleteOldFiles.vbs.txt (88 views, 1.71 KB)
Post #462115
Posted Thursday, February 28, 2008 8:45 PM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Wednesday, January 8, 2014 2:49 PM
Points: 1,278, Visits: 2,203
It should work using maintenance plan - Maintenance Cleanup Task.

Refer to this post:
http://www.sqlservercentral.com/Forums/Topic432440-357-1.aspx#bm451969
Post #462137
Posted Friday, February 29, 2008 7:16 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Wednesday, February 8, 2012 3:19 AM
Points: 87, Visits: 61
Thanks for your Reply... I really appreciate all of you...
Post #462341
Posted Friday, February 29, 2008 9:13 AM


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Tuesday, September 23, 2014 9:22 AM
Points: 3,461, Visits: 351
You have a backup delete task in SSIS which can be used to specify the location where the backup files reside. Why can't you use that.

Cheers,
Sugeshkumar Rajendran
SQL Server MVP
http://sugeshkr.blogspot.com
Post #462486
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse