Announcement

Collapse
No announcement yet.

How can I use FOR FILES to delete old backup files from a remote server

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • How can I use FOR FILES to delete old backup files from a remote server

    I do have the need of running a TSQL job from a remote server in order to delete old backup files. The command runs fine when running via command prompt, same remote server. But it fails when it's being executed as an added step inside a TSQL job.

    Here is the screenshot of the TSQL job and step:



    The job runs and gives no errors but it does not delete any file. Why?

  • #2
    Re: How can I use FOR FILES to delete old backup files from a remote server

    Try changing the command to this:

    forfiles /s /m *DIFF*.sqb /d -1 /c "cmd /c del /q @patch"

    Comment


    • #3
      Re: How can I use FOR FILES to delete old backup files from a remote server

      Should that be "@path" ?
      Tom Jones
      MCT, MCSE (2000:Security & 2003), MCSA:Security & Messaging, MCDBA, MCDST, MCITP(EA, EMA, SA, EDA, ES, CS), MCTS, MCP, Sec+
      PhD, MSc, FIAP, MIITT
      IT Trainer / Consultant
      Ossian Ltd
      Scotland

      ** Remember to give credit where credit is due and leave reputation points where appropriate **

      Comment


      • #4
        Re: How can I use FOR FILES to delete old backup files from a remote server

        Yep. Sorry my bad.

        Comment


        • #5
          Re: How can I use FOR FILES to delete old backup files from a remote server

          Ok had a little play around with this and this works for me

          Code:
          pushd "ChangeThisToMeetYourRequirments" &&(forfiles /S /M *.txt /D -0 /C "cmd /c del /s /q @path") & popd
          It has been tested on a share with text files created today, hence the /D -0

          This has all been done in cmd from my local system.

          I created a job on our SQL server and again it worked perfectly for me.

          I did notice however that your command is spread over a few lines. Min isn't. Is that possibly an issue?
          Attached Files

          Comment


          • #6
            Sorry for the late reply, lol...

            This was my solution, which works like a charm:

            PushD "\\server1.xx.com\Share\share_server1" &&("forfiles.exe" /S /M "*DIFF*.sqb" /d -1 /c "cmd /c del @file") & PopD
            It runs on my SQL server via TSQL job against the backup server.


            Comment

            Working...
            X