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

Re: Daily Backup Without Overwrite

Expand Messages
  • GBL
    ... WeekDay IF ERRORLEVEL 7 GOTO Sat IF ERRORLEVEL 6 GOTO Fri IF ERRORLEVEL 5 GOTO Thu IF ERRORLEVEL 4 GOTO Wed IF ERRORLEVEL 3 GOTO Tue IF ERRORLEVEL 2 GOTO
    Message 1 of 10 , Jun 25, 2010
    • 0 Attachment
      --- In batchworld@yahoogroups.com, Aristos Vasiliou <aristos@...> wrote:
      >
      > I am currently using this batch file to daily backup my documents on my second hard disk. XCOPY /Y /E /D /C %USERPROFILE%\Documents\*.* D:\Backup\Documents
      >
      > What I need to do is modify the batch file so that it won't overwrite D:\Backup\Documents, but create a new folder named D:\Backup\Documents_Monday and then on Tuesday create a new folder named D:\Backup\Documents_Tuesday and so on.
      >
      > It should do this for the whole week, so that if I make a mistake today, and discover it after two days, I can restore from three days back. And then on Monday it can overwrite again.
      >
      > How can I do this?
      >
      > Thanks

      Many years ago, I wrote a very small command line program named Weekday.exe (see http://www.incodesystems.com/PRODUCTS/WEEKDAY.HTM) that sets the ERRORLEVEL to a number that corresponds to the day of the week. We use that to create batch files that behave differently based on the day of the week. All you do is:
      ----------- clip
      WeekDay
      IF ERRORLEVEL 7 GOTO Sat
      IF ERRORLEVEL 6 GOTO Fri
      IF ERRORLEVEL 5 GOTO Thu
      IF ERRORLEVEL 4 GOTO Wed
      IF ERRORLEVEL 3 GOTO Tue
      IF ERRORLEVEL 2 GOTO Mon
      IF ERRORLEVEL 1 GOTO Sun
      ----------- clip
      A simpler way would be to deference the ERRORLEVEL pseudo environment variable, like this:
      ----------- clip
      WeekDay
      GOTO Day%ERRORLEVEL%
      :Day1
      :Day2
      :Day3
      :Day4
      :Day5
      :Day6
      :Day7
      ----------- clip

      Here's another way to get a similar result, without the WeekDay.exe program.
      ----------- clip
      FOR /F "usebackq delims==" %%i IN (`DATE /T`) DO SET WeekDay=%%i
      SET WeekDay=%WeekDay:~0,3%
      GOTO %WeekDay%
      :Mon
      :Tue
      :Wed
      :Thu
      :Fri
      :Sat
      :Sun
      ----------- clip

      We have written a large number of helper programs that effectively extend the functionality of batch files (see http://www.incodesystems.com/PRODUCTS/BATCH.HTM). These programs can be used to create batch files that appear to the user like they are running a Windows program. A relatively new one, named Echox.exe (see http://www.incodesystems.com/PRODUCTS/ECHOX.HTM), can be used to echo text to the screen in color and at X,Y locations specified on the command line. It also allows you to echo text without ending with a carriage return, line feed sequence, so the cursor remains on the end of the text. We are always looking for suggestions to improve our offering of batch file helper programs.

      Glenn Lawler
      www.incodesystems.com
      mailto:gblawler@...
    Your message has been successfully submitted and would be delivered to recipients shortly.