"PROBLEM WITH XP_DELETE_FILE IN SQL SERVER 2005"

  • I have a problem with a prc xp_delete_file. this procedure don´t delete old backups.

    In the log, I can see:

    DateTime: 2009-08-26 22:07:00

    Command: DECLARE @ReturnCode int EXECUTE @ReturnCode = master.dbo.xp_delete_file 0, N'\\SERVER01\BD1\FULL', 'bak', '2009-08-23T22:06:59' IF @ReturnCode <> 0 RAISERROR('Error deleting files.', 16, 1)

    Outcome: Succeeded

    Duration: 00:00:00

    DateTime: 2009-08-26 22:07:00

    But, it don´t delete olds backups.

    It work in the server with:

    ProductVersion ProductLevel Edition EngineEdition

    9.00.3077.00 SP2 Developer Edition 3

    And it don´t work in the server with:

    ProductVersion ProductLevel Edition EngineEdition

    9.00.3068.00 SP2 Standard Edition 2

    Can I solve this problem!!!!!

    Thank you very much.

  • Consider an example wherein i have to delete a backup file older than 2 days.I have a database named example whose backup is happening in D drive.The backup file name is example_db_date.bak.Today being 21st Jan 2010, i want to delete those example db backup files present on D drive which are older than 2 days.

    I use xp_cmdshell feature.

    Note: Before implementing the below code please ensure that xp_cmdshell feature is enabled in SQL Server 2005 Surface Area Configuration.

    DECLARE @DeleteOldDiff varchar(500);

    SET @DeleteOldDiff = 'xp_cmdshell ''del "D:\example_db_'+

    convert(char(8), getdate()-2,112) +'*.BAK'+'"''' ;

    exec (@DeleteOldDiff)

  • thanks satnam it really work...

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply