Delete old Backup files using T-sql script

  • It seems to be a powerful script . i tried on local machine and it has deleted all backup files.

    so u mean to say if i want to delete 7 day older backup t-log backup files only i have to put 7 instead of 5?

    I just want to delete T-log backup file so how i can set in script?

    WHERE a.backup_start_date

    < GETDATE()-5

  • Yes change the 5 to a 7

    Jason...AKA CirqueDeSQLeil
    _______________________________________________
    I have given a name to my pain...MCM SQL Server, MVP
    SQL RNNR
    Posting Performance Based Questions - Gail Shaw[/url]
    Learn Extended Events

  • Thanks Jason

    any idea about to specify path for t-log backup file.

    my t-log backup file is on network drive.

  • i am trying your SP and it's not deleting the old file..

    can you explain in detail if have to setup differently?

    Thanks

  • Here's an alternative

    http://www.sqlservercentral.com/articles/Integration+Services+(SSIS)/87652/

    Jason...AKA CirqueDeSQLeil
    _______________________________________________
    I have given a name to my pain...MCM SQL Server, MVP
    SQL RNNR
    Posting Performance Based Questions - Gail Shaw[/url]
    Learn Extended Events

  • use "forfiles" with xp_cmdshell and it will serve your purpose

    forfiles [/p <Path>] [/m <SearchMask>] [/s] [/c "<Command>"] [/d [{+|-}][{<Date>|<Days>}]]

    http://technet.microsoft.com/en-us/library/cc753551(v=ws.10)

    Musab
    http://www.sqlhelpline.com

  • I hope you don't mind but I posted this about you on facebook 🙂

    "I like this guys code very robust and feature complete....."

  • This is an old thread, but here is the solution for using a UNC path for anyone searching and finding this:

    exec xp_cmdshell 'PushD "\\UNCPath" &&(forfiles /m FileName*.* /d -180 /c "cmd /c del @FILE") & PopD'

    \\UNCPath is the complete UNC Path of the directory you are searching for

    FileName*.* is the file name you are searching for. Use Search arguments such as *

    -180 is the number of days to keep

    Francis
    -----------------
    SQLRanger.com

Viewing 8 posts - 46 through 52 (of 52 total)

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