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 Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA” -s -m *.trc -d -2 -c “Cmd /C del @FILE”‘
enjoy!
SQL Server - Use T-SQL to delete files older than X days
No comments:
Post a Comment