Welcome to Sign in | Join | Help
in
Home Blogs Files

Richard's Infrastructure Blog

SQL Server 2005 Clean up maintenance plan not deleting files?

If you set up a maintenance plan to cleanup and delete old files from a folder and it doens't delete the files (a common problem as it turns out), create a new maintenance plan and add an 'Execute T-SQL Statement' task.

The following will delete BAK and TRN files, enter it in the T-SQL statement window:

declare @dt datetime
select @dt=getdate()-[number of day's files to keep, i.e. 14 to delete files over 14 days old]
EXECUTE master.dbo.xp_delete_file 0,N'[file folder]',N'BAK',@dt
EXECUTE master.dbo.xp_delete_file 0,N'[file folder]',N'TRN',@dt

Set up a reccuring schedule to run once a day and save the new plan.

Old files will now be deleted and your hard drive won't fill up.

Published 12 July 2007 15:10 by richardk

Comments

No Comments
Anonymous comments are disabled

This Blog

Post Calendar

<July 2007>
MoTuWeThFrSaSu
2526272829301
2345678
9101112131415
16171819202122
23242526272829
303112345

Syndication

Powered by Community Server, by Telligent Systems