Delete Old T-log Backup File

  • You're welcome

    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

  • Hi Geoff..

    Like to know one thing regrading to your script

    exec master.sys.xp_cmdshell 'PushD "\\YOUR\UNC\PATH" &&("forfiles.exe" /S /M "*.trn" /d -7 /c "cmd /c del @file") & PopD'

    GO

    to

    exec master.sys.xp_cmdshell 'PushD "\\YOUR\UNC\PATH" &&("forfiles.exe" /S /M "*.trn" /d -7 /c "cmd /c echo @file") & PopD'

    GO

    When i run 1st script with del option it deletes the files but when i run with echo option it is not deleting files. so like to know whats echo does in script if you or anyone know.

  • if you rememeber, i gave the 2nd option with the 'echo' statement so you could see what files would be deleted.

    i thought it might help you if you could see the files with an 'echo' command first so you knew exacly what would get 'del' later.

    you only need the first statement with the 'del' command once you are comfortable with it,

  • okay got you GEOFF ..thanks thanks...

    have a good day ahead if you are in USA..lol;)

  • i am and you're welcome.

  • Have you tried using xp_delete_file? Nothing wrong with the method Geoff suggested, personally I'd rather not enable xp_cmdshell unless it's absolutely necessary.

    EXECUTE master.dbo.xp_delete_file

    0-- 0 = backup file, 1 = report file

    ,@path-- base folder, i.e. '\\myserver\mybackupdir'

    ,@fileext-- file extension, i.e. 'trn'

    ,@deldate-- delete files older than this date

    ,1-- 1 = include first-level subfolders, 0 = don't include subfolders



    Colleen M. Morrow
    Cleveland DBA

Viewing 6 posts - 16 through 20 (of 20 total)

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