September 1, 2008 at 7:47 am
Does anyone know how I can delete specific files without using xp_cmdshell?
I backup a log file with a date and time stamp in it's name and then I run this as the second step of the job to remove the prevous days backups:
DECLARE @cmd varchar(255)
SET @cmd = 'del "G:\BACKUP\DBADB_BackUp_' + LEFT(REPLACE(REPLACE(CONVERT(VARCHAR,DATEADD(d,-1,GETDATE()), 13), ' ', '_'), ':', ''), 12) + '*.trn"'
EXEC master..xp_cmdshell @cmd
To run this on the servers I would have to enable xp_cmdshell in the SAC tool, I don't have a problem with this as only sysadmins can run it anyway but the people in charge of changes have different ideas and I'm not able to do that and wondered if there was any simple way of deleting files without using this option.
Thanks
September 1, 2008 at 8:42 am
you could call a VBScript/Powershell file to do this, calculate the date and delete the file. That might be easier.
Or use an SSIS package to do this. Maintenance plans have a task that will do this as well.
September 1, 2008 at 9:06 am
I've got a deep mistrust of maintenance plans, especially when it comes to deleting files.
I never thought of SSIS, thanks.
September 1, 2008 at 3:46 pm
There is a sneaky way of doing this described here:
September 1, 2008 at 5:31 pm
Richard Fryar (9/1/2008)
There is a sneaky way of doing this described here:
Heh... I love "sneaky". That's awesome! Thanks for the tip! 🙂
EDIT - BEWARE !!!! THE LINK ABOVE NO LONGER TAKES YOU TO THE RIGHT PLACE! IT NOW TAKES YOU TO A GAMING SITE !!!!
--Jeff Moden
Change is inevitable... Change for the better is not.
September 2, 2008 at 2:44 am
A CLR procedure maybe?
N 56°04'39.16"
E 12°55'05.25"
September 2, 2008 at 7:44 pm
Peso (9/2/2008)
A CLR procedure maybe?
Heh... better be limited to only the directory being worked on or you might as well open up xp_CmdShell.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply