I have a simple Integration Service package which has one SQL Task as shown below;

  • WLSTAGE Bakup using Red Gate: Calls master..sqlbackup to backup database

Here is the SQL to run the actual backup

exec master..sqlbackup '-E -SQL "BACKUP DATABASE [WLSTAGE] TO DISK = ''\\Backups\<AUTO>'' WITH COMPRESSION = 1, INIT, MAILTO = ''<left blank intentionally>'', VERIFY"'

Since I have specified the backup file name as <AUTO>, I am wondering if there is a simple way to remove backups older than 2 days (if possible, without having to write any plumbing code to parse the file name).

alt text

link|improve this question

77% accept rate
feedback

1 Answer

up vote 1 down vote accepted

I'm not sure what the AUTO statement does, but you are probably aware of the Maintenance Cleanup task. Does it not do what you need?

I like powershell for things like this as well.

(get-item -path "d:\perflogs\*" | where {$_.creationTime -lt ((get-date) - (new-timespan -days 30))} | where {$_.extension -eq ".blg"}) | remove-item
link|improve this answer
@Sam: Specifying <AUTO> creates a file name dynamically using parent's directory name and current date stamp - Back to the main point, is it possible to call powershell scripts within SSIS package as you have suggested? – Sung Jan 20 '10 at 18:07
I suppose it would be a command line call you could put in a job step. Did you try the Maintenance Cleanup task? – Sam Jan 22 '10 at 0:23
Thanks Sam, I have decided to use PowerShell in Execute Process Task mentioned in this StackOverflow answer - stackoverflow.com/questions/1070050/powershell-in-ssis/… – Sung Jan 29 '10 at 14:19
Glad you got it sorted out. I might consider a .net script task solution as well, to keep all the code in one place. I think you can run powershell from inside .net as well, so the .net would just be a bit of a wrapper. – Sam Feb 1 '10 at 17:17
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.