Loading ...
Sorry, an error occurred while loading the content.
 

Re: [BATCH WORLD] Simple deletion script not working correctly under Server 2003

Expand Messages
  • foxidrive
    ... This has a couple of changes but should keep 10 of the latest folders. The syntax should be to remove the folders using RD rather than deleting files.
    Message 1 of 3 , Aug 24, 2011
      On 25/08/2011 10:02, Bushy wrote:

      >
      > Very quickly, the following is a location where backups are dumped
      > nightly, into directory names that are date generated.
      > Under each of these directories are around 4 gig of nightly SQL backup
      > files.
      > Each of the dated directory names are created at 10pm on that particular
      > date, so they each have a creation date based on their filename.
      > At the moment there is around two months worth, and the need to remember
      > to manually go in and delete chunks.
      > My goal is to automate the process and just to keep the last ten days worth.
      >
      >
      > Direction location example:
      > \\tamarang\e$\lpscadmin\e\sql\22082011\model.bak
      > \\tamarang\e$\lpscadmin\e\sql\22082011\tracerassets.bak
      > \\tamarang\e$\lpscadmin\e\sql\22082011\PowerBudgetNew.bak
      > \\tamarang\e$\lpscadmin\e\sql\22082011\SoftwareSupport.bak
      > \\tamarang\e$\lpscadmin\e\sql\23082011\model.bak
      > \\tamarang\e$\lpscadmin\e\sql\23082011\tracerassets.bak
      > \\tamarang\e$\lpscadmin\e\sql\23082011\PowerBudgetNew.bak
      > \\tamarang\e$\lpscadmin\e\sql\23082011\SoftwareSupport.bak
      > \\tamarang\e$\lpscadmin\e\sql\24082011\model.bak
      > \\tamarang\e$\lpscadmin\e\sql\24082011\tracerassets.bak
      > \\tamarang\e$\lpscadmin\e\sql\24082011\PowerBudgetNew.bak
      > \\tamarang\e$\lpscadmin\e\sql\24082011\SoftwareSupport.bak
      > \\tamarang\e$\lpscadmin\e\sql\25082011\model.bak
      > \\tamarang\e$\lpscadmin\e\sql\25082011\tracerassets.bak
      > \\tamarang\e$\lpscadmin\e\sql\25082011\PowerBudgetNew.bak
      > \\tamarang\e$\lpscadmin\e\sql\25082011\SoftwareSupport.bak
      >

      This has a couple of changes but should keep 10 of the latest folders.
      The syntax should be to remove the folders using RD rather than deleting files.

      (untested)

      @echo off & setlocal enableextensions

      set targetdir_=e:\lpscadmin\e\sql

      if not exist "%targetdir_%\" (
      echo Folder "%targetdir_%" not found
      goto :EOF)

      set script_="c:\scripts\cleanup_sql_dir.cmd"
      if exist %script_% del %script_%

      for /f "skip=10 delims=" %%f in (
      'dir /a:d /b /o:-d "%targetdir_%"') do (
      echo rd /s /q "%targetdir_%\%%~nxf">>%script_%
      )

      endlocal & goto :EOF
    • Bushy
      ... That worked a treat. Your a legend. Thankyou! (Flippin stupid me trying to do it with DEL. I didn t even put any thought into that at all; didnt even think
      Message 2 of 3 , Aug 25, 2011
        >Posted by: "foxidrive"

        > This has a couple of changes but should keep 10
        > of the latest folders. The syntax should be to
        > remove the folders using RD rather than deleting files.

        That worked a treat. Your a legend. Thankyou!

        (Flippin stupid me trying to do it with DEL. I didn't even put any
        thought into that at all; didnt even think about RD /S.)
      Your message has been successfully submitted and would be delivered to recipients shortly.