11/3/2008 · EXEC xp_cmdshell ‘FORFILES /p c:BACKUP /s /m F_*.sql /d -30 /c CMD /C del /Q /F @FILE’ Next Steps. Modify the code above to fit your retention policy, file structure and needs. Add the modified code to a subsequent job step in the.
12/13/2012 · EXEC xp_cmdshell ‘FORFILES /p I: /m *.* /d -30 /c CMD /C del /Q /F @FILE’ ERROR: The specified directory does not exist.:w00t: I hope you might know the risk about cmdshell. You can use the …
I have script that works except I can’t use @Path in EXEC xp_cmdshell ‘ FORFILES . –Delete Files if backup Successful EXEC xp_cmdshell ‘FORFILES /p @PATH /s /m *.bak* /d -1 /c CMD /C del /Q /F @FILE’ Is there a way I can declare my path before and use it with EXEC xp_cmdshell and with FORFILES ? My full code is below, 3/2/2009 · EXEC xp_cmdshell ‘forfiles /p G:MSSQLSERVERReportServerTempDBDIFFERENTIAL /m *.bak /c del @file /d -2′. I think the you intended to pass @file as variable. But it is taken as file name. Check this method. declare @str varchar(200),@file varchar(100) set @file=’yourfilename’ set @str=’ forfiles / p d:.
use xp_cmdshell command along with the FORFILES command. e.g Delete all .sql files in the C:Backup directory and its subfolders where the file modified date is more than 30 days old. EXEC xp_cmdshell ‘FORFILES /p c:BACKUP /s /m *.sql /d -30 /c CMD /C del /Q /F @FILE’, 9/21/2010 · You’ll need to use a T-SQL step type to run the command with xp_cmdshell. That said, you are probably better off running the Windows command directly using a CmdExec step without xp_cmdshell. forfiles / p z:backup -d 15 /c cmd /c if @isDir==True echo RD /Q /S @FILE&RD /Q /S @FILE, EXEC xp_cmdshell bcp select ‘a_id’,’b_id’,’c_id’ union select a_id,b_id,c_id from tablename out ‘\network_patha.txt’ -c -Uusername -Ppassword -Sservername I have successfully used the below command to export the table,however I also need the column names.
5/9/2013 · Sometimes there is a need to delete backup files via tSQL. Here is a script that can do the trick. -d represents number of days, 2 represents file older than 2 days set the parameter as needed exec xp_CMDShell Forfiles -p C:Program FilesMicrosoft SQL ServerMSSQL10.MSSQLSERVERMSSQLDATA -s -m *.trc -d -2 -c Cmd /C [ ], Here use the below script to delete the backup file by use of xp_cmdshell command from sql server. Delete all .sql files in the C:Backup directory and its subfolders where the file modified date is older than 1/20/2013. EXEC xp_cmdshell FORFILES /p c:BACKUP /s /m *.sql /d 1/20/2013 /c CMD /C del /Q /F @FILE