Maintenance Task not deleting files

Last post 08-18-2008, 8:57 AM by gernblandston. 4 replies.
Sort Posts: Previous Next
  •  08-04-2008, 9:59 AM Post number 66206

    Maintenance Task not deleting files

    I am trying to delete old files using the Maintenance Cleanup Task after the Backup Database Task, but the files do not get deleted as they should.

    After the SQL backup job runs, I have a separate Windows Scheduled task (running several hours after the backups) that archives the .BAK files into .7z (7-Zip) files. The maintenance task should delete the .7z files if they are older than 1 week:

    EXECUTE master.dbo.xp_delete_file 0,N'D:\Database Backups',N'7z',N'2008-07-28T10:54:59',1

    The task is set to the correct folder, and it includes first-level subfolders. the file extension is set to:
    7z

    An example filename is:
    MyDatabase_backup_200808040600.7z

    What am I missing?

    Thanks!

    Chris

  •  08-11-2008, 3:36 AM Post number 67694 in reply to post number 66206

    Re: Maintenance Task not deleting files

    XP_Delete_File is an undocumented procedure that is used internally. xp_delete_file, in particular has all sorts of quirks. Having said that, have you tried changing the first parameter to a 1?
  •  08-18-2008, 8:46 AM Post number 69063 in reply to post number 67694

    Re: Maintenance Task not deleting files

    I changed the first parm to 1 and it still did not delete the files.

  •  08-18-2008, 8:53 AM Post number 69064 in reply to post number 69063

    Re: Maintenance Task not deleting files

    http://www.simple-talk.com/community/forums/thread/31948.aspx !

    I usually use xp_cmdshell for this. Naughty but dead reliable. The big problem is that the date in the DIR listing is of a different format depending on your country settings. This means that you can't just cut and paste a routine like this and expect it to work!
  •  08-18-2008, 8:57 AM Post number 69065 in reply to post number 69064

    Re: Maintenance Task not deleting files

    Thanks Phil.

    It seemed like a simple thing when I started...

View as RSS news feed in XML