Delete unneeded transaction logs

  • I have a job that copies transaction log to a remote location. However since I dont want to copy the same logs again when the job runs I would like to delete them after I am doing copying with them.

    Does anyone know how can I accomplish this task from within SQL Server?

     

    thanks

  • Personally, I'd leave the files in place and only copy the files that haven't been copied before, but that's just me.

    There are several ways to do this. What's easiest will depend on the method that you're using to copy the files.

    For now, I'll assume that you're using a SQLAgent job with an OS Command step that does something like:

      copy d:\source\logs\*.trn \\remote\shared\dir\

    You can make that an xcopy, using the /M option, which will only copy files that have the archive bit set ON, and flip it OFF after the copy:

    xcopy /M d:\source\logs\*.trn \\remote\shared\dir\

    Then follow it up with a delete routine based on the archive bit:

    for /f "usebackq" %i in (`dir /b /A:-d-a d:\source\logs\*.trn`) do del d:\source\logs\%i

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

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