Cleaning up transaction log backups

  • Guys,

    I have used litespeed to do my T-log backups... I want to do a cleanup of my backups older than 3 days programmatically.. These backups are with the name 'C:\MSSQL\TRAN\dbname_YYYYMMDD_HHMMSS.trn'. What is the best way I can do this job.

    Cheers,

    Happy Holidays To Ya ALL

  • Look in the SQL Litespeed help file on the command line utility - and extended procedures. I don't have the reference available right now - but there is an extended procedure you can call that will delete SQL Litespeed backup files.

    Jeffrey Williams
    “We are all faced with a series of great opportunities brilliantly disguised as impossible situations.”

    ― Charles R. Swindoll

    How to post questions to get better answers faster
    Managing Transaction Logs

  • You can try this code in the test environment. If this works fine in your case the use it.

    DECLARE @DeleteFiles NVARCHAR(4000)

    DECLARE file_cursor CURSOR FOR

    SELECT 'exec xp_cmdshell ''DEL "'

    + physical_device_name + '"''' +CHAR(13)+CHAR(10)

    FROM msdb.dbo.backupmediafamily ms

    JOIN msdb.dbo.backupset us ON ms.media_set_id = us.media_set_id

    WHERE backup_finish_date < GETDATE() - 7

    AND backup_finish_date > GETDATE() - 9

    OPEN file_cursor

    FETCH NEXT FROM file_cursor INTO @DeleteFiles

    WHILE @@FETCH_STATUS = 0

    BEGIN

    EXEC (@DeleteFiles)

    FETCH NEXT FROM file_cursor INTO @DeleteFiles

    END

    CLOSE file_cursor

    DEALLOCATE file_cursor

  • srawant (12/19/2008)


    Guys,

    I have used litespeed to do my T-log backups... I want to do a cleanup of my backups older than 3 days programmatically.. These backups are with the name 'C:\MSSQL\TRAN\dbname_YYYYMMDD_HHMMSS.trn'. What is the best way I can do this job.

    Cheers,

    Happy Holidays To Ya ALL

    U can get Physical path of databases backup from querying of backup history which have older then use xp_cmdshell command to delete them.

    _____________________________________________________________________________________________________________
    Paresh Prajapati
    ➡ +919924626601
    http://paresh-sqldba.blogspot.com/[/url]
    LinkedIn | Tweet Me | FaceBook | Brijj

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

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