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@...
    • Aristos Vasiliou
      This is probably one of the most useful batch files I’ve worked on, and of course it wouldn’t exist without this group. So thanks for that. I currently
      Message 2 of 10 , Jun 28, 2010
      • 0 Attachment
        This is probably one of the most useful batch files I�ve worked on, and of course it wouldn�t exist without this group. So thanks for that.

        I currently host eleven websites on Bluehost and to be on the safe site I wanted to have local backups of those websites. But I don�t really trust backups, so I wanted to have live and working duplicates of those eleven sites on my home computer on a webserver virtual machine.

        So what can this batch file do?

        First it downloads the MySQL databases from Bluehost and saves them in a folder. Then it takes those downloaded database dumps and imports them on the local database. After that, it starts downloading each website folder placing it in wwwroot, adding to the folder name, the current day, for seven days, so that I can go back to previous backups. It also creates log files for each website downloaded, just to make sure there were no errors.

        I run this batch file every night, so now I know that I have all my websites locally, and I know that they are working because I can look at them through my browser and everything is working perfectly.
        It�s working, but I know it can be improved by more experienced people than me, so I�m posting it below. Any suggestions/modifications are welcome. And of course you can use it also.

        ::Create Day Variable
        ::------------------------------------------------------------------------
        set TmpFile="%temp%.\tmp.vbs"
        echo> %TmpFile% n=Now
        echo>>%TmpFile% With WScript
        echo>>%TmpFile% .Echo "set year=" + CStr(Year(n))
        echo>>%TmpFile% .Echo "set yr=" + Right(Year(n),2)
        echo>>%TmpFile% .Echo "set month="+ Right(100+Month(n),2)
        echo>>%TmpFile% .Echo "set day=" + Right(100+Day(n),2)
        echo>>%TmpFile% .Echo "set hour=" + Right(100+Hour(n),2)
        echo>>%TmpFile% .Echo "set min=" + Right(100+Minute(n),2)
        echo>>%TmpFile% .Echo "set sec=" + Right(100+Second(n),2)
        echo>>%TmpFile% .Echo "set dow=" + WeekDayName(Weekday(n),1)
        echo>>%TmpFile% .Echo "set dow2=" + WeekDayName(Weekday(n))
        echo>>%TmpFile% .Echo "set iso=" + CStr(1 + Int(n-2) mod 7)
        echo>>%TmpFile% .Echo "set iso2=" + CStr(Weekday(n,2))
        echo>>%TmpFile% End With
        cscript //nologo "%temp%.\tmp.vbs" > "%temp%.\tmp.bat"
        call "%temp%.\tmp.bat"
        del "%temp%.\tmp.bat"
        del %TmpFile%
        set TmpFile=
        set stamp=%year%-%month%-%day%_%hour%.%min%.%sec%

        echo The year (YYyy) is "%year%"
        echo The year (yy) is "%yr%"
        echo The month is "%month%"
        echo The day (%dow%) is "%day%"
        echo The full weekday name is "%dow2%"
        echo.
        echo ISO 8601 Day-Of-Week number is "%iso%"
        echo.
        echo The hour is "%hour%"
        echo The minute is "%min%"
        echo The second is "%sec%"
        echo.

        echo The date and time stamp is "%stamp%"
        echo.
        echo time (hhmmss) (%hour%%min%%sec%)
        echo.
        echo date A (yyyymmdd) (%year%%month%%day%)
        echo date B (mmddyyyy) (%month%%day%%year%)
        echo date C (ddmmyyyy) (%day%%month%%year%)
        echo.
        echo date D [yymmdd] [%yr%%month%%day%]
        echo date E [mmddyy] [%month%%day%%yr%]
        echo date F [ddmmyy] [%day%%month%%yr%]
        ::------------------------------------------------------------------------

        ::Set Database Variables
        ::------------------------------------------------------------------------
        set mysqldump="C:\webserver\mysql\bin\mysqldump.exe"
        set mysql="C:\webserver\mysql\bin\mysql.exe"
        set path="C:\webserver\custom\dbasedump"
        set sqlswitches=--opt

        set remotehost=remotehost.com
        set remoteuser=myremoteusername
        set remotepass=myremotepassword
        set localuser=mylocalusername
        set localpass=mylocalpassword

        set db1=myfirstdatabase
        set db2=myseconddatabase
        set db3=mythirddatabase
        set db4=myforthdatabase
        set db5=myfifthdatabase
        set db6=mysixthdatabase
        set db7=myseventhdatabase
        set db8=myeighthdatabase
        set db9=myninthdatabase
        set db10=mytenthdatabase
        set db11=myeleventhdatabase
        ::------------------------------------------------------------------------

        ::Download Databases
        ::------------------------------------------------------------------------
        %mysqldump% %sqlswitches% -h%remotehost% -u%remoteuser% -p%remotepass% %db1% > %path%\%db1%
        %mysqldump% %sqlswitches% -h%remotehost% -u%remoteuser% -p%remotepass% %db2% > %path%\%db2%
        %mysqldump% %sqlswitches% -h%remotehost% -u%remoteuser% -p%remotepass% %db3% > %path%\%db3%
        %mysqldump% %sqlswitches% -h%remotehost% -u%remoteuser% -p%remotepass% %db4% > %path%\%db4%
        %mysqldump% %sqlswitches% -h%remotehost% -u%remoteuser% -p%remotepass% %db5% > %path%\%db5%
        %mysqldump% %sqlswitches% -h%remotehost% -u%remoteuser% -p%remotepass% %db6% > %path%\%db6%
        %mysqldump% %sqlswitches% -h%remotehost% -u%remoteuser% -p%remotepass% %db7% > %path%\%db7%
        %mysqldump% %sqlswitches% -h%remotehost% -u%remoteuser% -p%remotepass% %db8% > %path%\%db8%
        %mysqldump% %sqlswitches% -h%remotehost% -u%remoteuser% -p%remotepass% %db9% > %path%\%db9%
        %mysqldump% %sqlswitches% -h%remotehost% -u%remoteuser% -p%remotepass% %db10% > %path%\%db10%
        %mysqldump% %sqlswitches% -h%remotehost% -u%remoteuser% -p%remotepass% %db11% > %path%\%db11%

        ::------------------------------------------------------------------------
        ::Import Databases
        ::------------------------------------------------------------------------
        %mysql% -u%localuser% -p%localpass% %db1% < %path%\%db1%
        %mysql% -u%localuser% -p%localpass% %db2% < %path%\%db2%
        %mysql% -u%localuser% -p%localpass% %db3% < %path%\%db3%
        %mysql% -u%localuser% -p%localpass% %db4% < %path%\%db4%
        %mysql% -u%localuser% -p%localpass% %db5% < %path%\%db5%
        %mysql% -u%localuser% -p%localpass% %db6% < %path%\%db6%
        %mysql% -u%localuser% -p%localpass% %db7% < %path%\%db7%
        %mysql% -u%localuser% -p%localpass% %db8% < %path%\%db8%
        %mysql% -u%localuser% -p%localpass% %db9% < %path%\%db9%
        %mysql% -u%localuser% -p%localpass% %db10% < %path%\%db10%
        %mysql% -u%localuser% -p%localpass% %db11% < %path%\%db11%
        ::------------------------------------------------------------------------

        ::Set WinSCP Variables
        ::------------------------------------------------------------------------
        set winscp=C:\webserver\custom\files\winscp\winscp.exe
        set switches=option batch on
        set credentials=open username:password@...
        set execute=synchronize local

        set logpath1=C:\webserver\custom\logs\winscp\myfirstdatabase.log
        set logpath2=C:\webserver\custom\logs\winscp\myseconddatabase.log
        set logpath3=C:\webserver\custom\logs\winscp\mythirddatabase.log
        set logpath4=C:\webserver\custom\logs\winscp\myforthdatabase.log
        set logpath5=C:\webserver\custom\logs\winscp\myfifthdatabase.log
        set logpath6=C:\webserver\custom\logs\winscp\mysixthdatabase.log
        set logpath7=C:\webserver\custom\logs\winscp\myseventhdatabase.log
        set logpath8=C:\webserver\custom\logs\winscp\myeighthdatabase.log
        set logpath9=C:\webserver\custom\logs\winscp\myninthdatabase.log
        set logpath10=C:\webserver\custom\logs\winscp\mytenthdatabase.log
        set logpath11=C:\webserver\custom\logs\winscp\myeleventhdatabase.log
        ::------------------------------------------------------------------------

        ::Make Directories For Each Day
        ::------------------------------------------------------------------------
        MD "C:\webserver\wwwroot\myfirstwebsite-%dow2%\" 2>nul
        MD "C:\webserver\wwwroot\mysecondwebsite-%dow2%\" 2>nul
        MD "C:\webserver\wwwroot\mythirdwebsite-%dow2%\" 2>nul
        MD "C:\webserver\wwwroot\myforthwebsite-%dow2%\" 2>nul
        MD "C:\webserver\wwwroot\myfifthwebsite-%dow2%\" 2>nul
        MD "C:\webserver\wwwroot\mysixthwebsite-%dow2%\" 2>nul
        MD "C:\webserver\wwwroot\myseventhwebsite-%dow2%\" 2>nul
        MD "C:\webserver\wwwroot\myeightthwebsite-%dow2%\" 2>nul
        MD "C:\webserver\wwwroot\myninthwebsite-%dow2%\" 2>nul
        MD "C:\webserver\wwwroot\mytenthwebsite-%dow2%\" 2>nul
        MD "C:\webserver\wwwroot\myeleventhwebsite-%dow2%\" 2>nul
        ::------------------------------------------------------------------------

        ::Set Folder Variables
        ::------------------------------------------------------------------------
        set lfolder1=C:\webserver\wwwroot\myfirstwebsite-%dow2%
        set lfolder2=C:\webserver\wwwroot\mysecondwebsite-%dow2%
        set lfolder3=C:\webserver\wwwroot\mythirdwebsite-%dow2%
        set lfolder4=C:\webserver\wwwroot\myforthwebsite-%dow2%
        set lfolder5=C:\webserver\wwwroot\myfifthwebsite-%dow2%
        set lfolder6=C:\webserver\wwwroot\mysixthwebsite-%dow2%
        set lfolder7=C:\webserver\wwwroot\myseventhwebsite-%dow2%
        set lfolder8=C:\webserver\wwwroot\myeightthwebsite-%dow2%
        set lfolder9=C:\webserver\wwwroot\myninthwebsite-%dow2%
        set lfolder10=C:\webserver\wwwroot\mytenthwebsite-%dow2%
        set lfolder11=C:\webserver\wwwroot\myeleventhwebsite-%dow2%

        set rfolder1=/home1/remotehostusername/public_html/myfirstwebsite
        set rfolder2=/home1/remotehostusername/public_html/mysecondwebsite
        set rfolder3=/home1/remotehostusername/public_html/mythirdwebsite
        set rfolder4=/home1/remotehostusername/public_html/myforthwebsite
        set rfolder5=/home1/remotehostusername/public_html/myfifthwebsite
        set rfolder6=/home1/remotehostusername/public_html/mysixthwebsite
        set rfolder7=/home1/remotehostusername/public_html/myseventhwebsite
        set rfolder8=/home1/remotehostusername/public_html/myeightthwebsite
        set rfolder9=/home1/remotehostusername/public_html/myninthwebsite
        set rfolder10=/home1/remotehostusername/public_html/mytenthwebsite
        set rfolder11=/home1/remotehostusername/public_html/myeleventhwebsite
        ::------------------------------------------------------------------------

        ::Download Files
        ::------------------------------------------------------------------------
        %winscp% /log=%logpath1% /console /command "%switches%" "%credentials%" "%execute% %lfolder1% %rfolder1%" "close" "exit"
        %winscp% /log=%logpath2% /console /command "%switches%" "%credentials%" "%execute% %lfolder2% %rfolder2%" "close" "exit"
        %winscp% /log=%logpath3% /console /command "%switches%" "%credentials%" "%execute% %lfolder3% %rfolder3%" "close" "exit"
        %winscp% /log=%logpath4% /console /command "%switches%" "%credentials%" "%execute% %lfolder4% %rfolder4%" "close" "exit"
        %winscp% /log=%logpath5% /console /command "%switches%" "%credentials%" "%execute% %lfolder5% %rfolder5%" "close" "exit"
        %winscp% /log=%logpath6% /console /command "%switches%" "%credentials%" "%execute% %lfolder6% %rfolder6%" "close" "exit"
        %winscp% /log=%logpath7% /console /command "%switches%" "%credentials%" "%execute% %lfolder7% %rfolder7%" "close" "exit"
        %winscp% /log=%logpath8% /console /command "%switches%" "%credentials%" "%execute% %lfolder8% %rfolder8%" "close" "exit"
        %winscp% /log=%logpath9% /console /command "%switches%" "%credentials%" "%execute% %lfolder9% %rfolder9%" "close" "exit"
        %winscp% /log=%logpath10% /console /command "%switches%" "%credentials%" "%execute% %lfolder10% %rfolder10%" "close" "exit"
        %winscp% /log=%logpath11% /console /command "%switches%" "%credentials%" "%execute% %lfolder11% %rfolder11%" "close" "exit"
        ::------------------------------------------------------------------------

        ________________________________
        From: batchworld@yahoogroups.com [batchworld@yahoogroups.com] on behalf of foxidrive@... [foxidrive@...]
        Sent: Tuesday, June 29, 2010 2:10 PM
        To: batchworld@yahoogroups.com
        Subject: Re: [BATCH WORLD] Daily Backup Without Overwrite



        On Mon, 28 Jun 2010 18:15:43 +0000, Aristos Vasiliou
        <aristos@...<mailto:aristos%40aristos.net>> wrote:

        >Is there a way to tell the batch file to create the day's folder if it does not exist, before getting to the xcopy command? I'm asking because I plan on also using it with other programs that don't create the folders like XCOPY does.

        Use this line before the xxcopy or whatever line. Once %dow2% is set
        then this line will create the folder, whether it exists or not. The
        "2>nul" portion of the command merely hides the harmless error message
        when the folder already exists.

        MD "D:\Backup\Documents-%dow2%\" 2>nul





        [Non-text portions of this message have been removed]
      • Aristos Vasiliou
        Hello, It s not really about saving space. I m just curious to see how it can be improved :) And I must say what you did to it, sure made it simpler. It seems
        Message 3 of 10 , Jun 29, 2010
        • 0 Attachment
          Hello,

          It's not really about saving space. I'm just curious to see how it can be improved :) And I must say what you did to it, sure made it simpler.

          It seems that MD "C:\webserver\wwwroot\%1-%dow2%\" 2>nul creates the local folder based on the database1 name instead of the website1 name. Then winscp tries to download files based on the website1 name, and since the folder does not exist, it stops. How can I fix this?

          Thanks
          ________________________________
          From: batchworld@yahoogroups.com [batchworld@yahoogroups.com] on behalf of foxidrive@... [foxidrive@...]
          Sent: Wednesday, June 30, 2010 5:00 AM
          To: batchworld@yahoogroups.com
          Subject: Re: [BATCH WORLD] Daily Backup Without Overwrite



          On Wed, 30 Jun 2010 11:37:38 +1000, foxidrive@...<mailto:foxidrive%40lavabit.com> wrote:

          >On Tue, 29 Jun 2010 00:48:17 +0000, Aristos Vasiliou
          ><aristos@...<mailto:aristos%40aristos.net>> wrote:
          >
          >>So what can this batch file do?
          >>
          >>First it downloads the MySQL databases from Bluehost and saves them in a folder. Then it takes those downloaded database dumps and imports them on the local database. After that, it starts downloading each website folder placing it in wwwroot, adding to the folder name, the current day, for seven days, so that I can go back to previous backups. It also creates log files for each website downloaded, just to make sure there were no errors.
          >>
          >>I run this batch file every night, so now I know that I have all my websites locally, and I know that they are working because I can look at them through my browser and everything is working perfectly.
          >>It�s working, but I know it can be improved by more experienced people than me, so I�m posting it below. Any suggestions/modifications are welcome.
          >
          >The old saying applies here hehe
          >"If it's not broken then don't try to fix it."
          >
          >You could put the steps in a single routine and call the routine with a
          >single forindo command, but it will only save you a kilobyte on your
          >HDD. :)

          If you want to explore this though, here's something that should work
          but I haven't tested it.

          The four lines in the :routine at the bottom have a > at the start of
          the line which needs to be removed.

          @echo off
          ::Create Day Variable
          ::----------------------------------------------------------
          set TmpFile="%temp%.\tmp.vbs"
          echo> %TmpFile% n=Now
          echo>>%TmpFile% With WScript
          echo>>%TmpFile% .Echo "set year=" + CStr(Year(n))
          echo>>%TmpFile% .Echo "set yr=" + Right(Year(n),2)
          echo>>%TmpFile% .Echo "set month="+ Right(100+Month(n),2)
          echo>>%TmpFile% .Echo "set day=" + Right(100+Day(n),2)
          echo>>%TmpFile% .Echo "set hour=" + Right(100+Hour(n),2)
          echo>>%TmpFile% .Echo "set min=" + Right(100+Minute(n),2)
          echo>>%TmpFile% .Echo "set sec=" + Right(100+Second(n),2)
          echo>>%TmpFile% .Echo "set dow=" + WeekDayName(Weekday(n),1)
          echo>>%TmpFile% .Echo "set dow2=" + WeekDayName(Weekday(n))
          echo>>%TmpFile% .Echo "set iso=" + CStr(1 + Int(n-2) mod 7)
          echo>>%TmpFile% .Echo "set iso2=" + CStr(Weekday(n,2))
          echo>>%TmpFile% End With
          cscript //nologo "%temp%.\tmp.vbs" > "%temp%.\tmp.bat"
          call "%temp%.\tmp.bat"
          del "%temp%.\tmp.bat"
          del %TmpFile%
          set TmpFile=
          set stamp=%year%-%month%-%day%_%hour%.%min%.%sec%

          ::----------------------------------------------------------

          ::Set Database Variables
          ::----------------------------------------------------------
          set mysqldump="C:\webserver\mysql\bin\mysqldump.exe"
          set mysql="C:\webserver\mysql\bin\mysql.exe"
          set pth="C:\webserver\custom\dbasedump"
          set sqlswitches=--opt

          set remotehost=remotehost.com
          set remoteuser=myremoteusername
          set remotepass=myremotepassword
          set localuser=mylocalusername
          set localpass=mylocalpassword

          ::----------------------------------------------------------

          ::Set WinSCP Variables
          ::----------------------------------------------------------
          set winscp=C:\webserver\custom\files\winscp\winscp.exe
          set switches=option batch on
          set credentials=open username:password@...<mailto:password%40remotehost.com>
          set execute=synchronize local
          set logpath=C:\webserver\custom\logs\winscp
          set lfolder=C:\webserver\wwwroot
          set rfolder=/home1/remotehostusername/public_html

          call :routine database1 website1
          call :routine database2 website2
          call :routine database3 website3
          call :routine database4 website4
          call :routine database5 website5
          call :routine database6 website6
          call :routine database7 website7
          call :routine database8 website8
          call :routine database9 website9
          call :routine database10 website10
          call :routine database11 website11
          goto :EOF

          :routine
          > %mysqldump% %sqlswitches% -h%remotehost% -u%remoteuser% -p%remotepass% %1 > %pth%\%1
          > %mysql% -u%localuser% -p%localpass% %1 < %pth%\%1
          > MD "C:\webserver\wwwroot\%1-%dow2%\" 2>nul
          > %winscp% /log=%logpath%\%1.log /console /command "%switches%" "%credentials%" "%execute% %lfolder%\%2-%dow2% %rfolder%/%2" "close" "exit"





          [Non-text portions of this message have been removed]
        • foxidrive@lavabit.com
          On Tue, 29 Jun 2010 00:48:17 +0000, Aristos Vasiliou ... The old saying applies here hehe If it s not broken then don t try to fix it. You could put the
          Message 4 of 10 , Jun 29, 2010
          • 0 Attachment
            On Tue, 29 Jun 2010 00:48:17 +0000, Aristos Vasiliou
            <aristos@...> wrote:

            >So what can this batch file do?
            >
            >First it downloads the MySQL databases from Bluehost and saves them in a folder. Then it takes those downloaded database dumps and imports them on the local database. After that, it starts downloading each website folder placing it in wwwroot, adding to the folder name, the current day, for seven days, so that I can go back to previous backups. It also creates log files for each website downloaded, just to make sure there were no errors.
            >
            >I run this batch file every night, so now I know that I have all my websites locally, and I know that they are working because I can look at them through my browser and everything is working perfectly.
            >It’s working, but I know it can be improved by more experienced people than me, so I’m posting it below. Any suggestions/modifications are welcome.

            The old saying applies here hehe
            "If it's not broken then don't try to fix it."

            You could put the steps in a single routine and call the routine with a
            single forindo command, but it will only save you a kilobyte on your
            HDD. :)
          • foxidrive@lavabit.com
            ... If you want to explore this though, here s something that should work but I haven t tested it. The four lines in the :routine at the bottom have a at the
            Message 5 of 10 , Jun 29, 2010
            • 0 Attachment
              On Wed, 30 Jun 2010 11:37:38 +1000, foxidrive@... wrote:

              >On Tue, 29 Jun 2010 00:48:17 +0000, Aristos Vasiliou
              ><aristos@...> wrote:
              >
              >>So what can this batch file do?
              >>
              >>First it downloads the MySQL databases from Bluehost and saves them in a folder. Then it takes those downloaded database dumps and imports them on the local database. After that, it starts downloading each website folder placing it in wwwroot, adding to the folder name, the current day, for seven days, so that I can go back to previous backups. It also creates log files for each website downloaded, just to make sure there were no errors.
              >>
              >>I run this batch file every night, so now I know that I have all my websites locally, and I know that they are working because I can look at them through my browser and everything is working perfectly.
              >>It’s working, but I know it can be improved by more experienced people than me, so I’m posting it below. Any suggestions/modifications are welcome.
              >
              >The old saying applies here hehe
              >"If it's not broken then don't try to fix it."
              >
              >You could put the steps in a single routine and call the routine with a
              >single forindo command, but it will only save you a kilobyte on your
              >HDD. :)

              If you want to explore this though, here's something that should work
              but I haven't tested it.

              The four lines in the :routine at the bottom have a > at the start of
              the line which needs to be removed.



              @echo off
              ::Create Day Variable
              ::------------------------------------------------------------------------
              set TmpFile="%temp%.\tmp.vbs"
              echo> %TmpFile% n=Now
              echo>>%TmpFile% With WScript
              echo>>%TmpFile% .Echo "set year=" + CStr(Year(n))
              echo>>%TmpFile% .Echo "set yr=" + Right(Year(n),2)
              echo>>%TmpFile% .Echo "set month="+ Right(100+Month(n),2)
              echo>>%TmpFile% .Echo "set day=" + Right(100+Day(n),2)
              echo>>%TmpFile% .Echo "set hour=" + Right(100+Hour(n),2)
              echo>>%TmpFile% .Echo "set min=" + Right(100+Minute(n),2)
              echo>>%TmpFile% .Echo "set sec=" + Right(100+Second(n),2)
              echo>>%TmpFile% .Echo "set dow=" + WeekDayName(Weekday(n),1)
              echo>>%TmpFile% .Echo "set dow2=" + WeekDayName(Weekday(n))
              echo>>%TmpFile% .Echo "set iso=" + CStr(1 + Int(n-2) mod 7)
              echo>>%TmpFile% .Echo "set iso2=" + CStr(Weekday(n,2))
              echo>>%TmpFile% End With
              cscript //nologo "%temp%.\tmp.vbs" > "%temp%.\tmp.bat"
              call "%temp%.\tmp.bat"
              del "%temp%.\tmp.bat"
              del %TmpFile%
              set TmpFile=
              set stamp=%year%-%month%-%day%_%hour%.%min%.%sec%

              ::------------------------------------------------------------------------

              ::Set Database Variables
              ::------------------------------------------------------------------------
              set mysqldump="C:\webserver\mysql\bin\mysqldump.exe"
              set mysql="C:\webserver\mysql\bin\mysql.exe"
              set pth="C:\webserver\custom\dbasedump"
              set sqlswitches=--opt

              set remotehost=remotehost.com
              set remoteuser=myremoteusername
              set remotepass=myremotepassword
              set localuser=mylocalusername
              set localpass=mylocalpassword

              ::------------------------------------------------------------------------

              ::Set WinSCP Variables
              ::------------------------------------------------------------------------
              set winscp=C:\webserver\custom\files\winscp\winscp.exe
              set switches=option batch on
              set credentials=open username:password@...
              set execute=synchronize local
              set logpath=C:\webserver\custom\logs\winscp
              set lfolder=C:\webserver\wwwroot
              set rfolder=/home1/remotehostusername/public_html

              call :routine database1 website1
              call :routine database2 website2
              call :routine database3 website3
              call :routine database4 website4
              call :routine database5 website5
              call :routine database6 website6
              call :routine database7 website7
              call :routine database8 website8
              call :routine database9 website9
              call :routine database10 website10
              call :routine database11 website11
              goto :EOF

              :routine
              > %mysqldump% %sqlswitches% -h%remotehost% -u%remoteuser% -p%remotepass% %1 > %pth%\%1
              > %mysql% -u%localuser% -p%localpass% %1 < %pth%\%1
              > MD "C:\webserver\wwwroot\%1-%dow2%\" 2>nul
              > %winscp% /log=%logpath%\%1.log /console /command "%switches%" "%credentials%" "%execute% %lfolder%\%2-%dow2% %rfolder%/%2" "close" "exit"
            • foxidrive@lavabit.com
              On Tue, 29 Jun 2010 17:27:39 +0000, Aristos Vasiliou ... %1 is replaced with the database name and %2 is replaced with the website name I think it was a case
              Message 6 of 10 , Jun 30, 2010
              • 0 Attachment
                On Tue, 29 Jun 2010 17:27:39 +0000, Aristos Vasiliou
                <aristos@...> wrote:

                >It seems that MD "C:\webserver\wwwroot\%1-%dow2%\" 2>nul creates the local folder based on the database1 name instead of the website1 name. Then winscp tries to download files based on the website1 name, and since the folder does not exist, it stops. How can I fix this?


                %1 is replaced with the database name and %2 is replaced with the
                website name

                I think it was a case of using this as below (remove the > again)
                "MD "C:\webserver\wwwroot\%2-%dow2%\" 2>nul"


                :routine
                > %mysqldump% %sqlswitches% -h%remotehost% -u%remoteuser% -p%remotepass% %1 > %pth%\%1
                > %mysql% -u%localuser% -p%localpass% %1 < %pth%\%1
                > MD "C:\webserver\wwwroot\%2-%dow2%\" 2>nul
                > %winscp% /log=%logpath%\%1.log /console /command "%switches%" "%credentials%" "%execute% %lfolder%\%2-%dow2% %rfolder%/%2" "close" "exit"
              Your message has been successfully submitted and would be delivered to recipients shortly.