Aristos Vasiliou | 24 Jun 2010 21:32
Favicon

Daily Backup Without Overwrite

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 

------------------------------------

To Post a message, send it to:   batchworld@...

To Unsubscribe, send a blank message to: batchworld-unsubscribe@...
foxidrive | 25 Jun 2010 10:10

Re: Daily Backup Without Overwrite

On Thu, 24 Jun 2010 19:32:19 +0000, 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?

Use this batch file and on the last line use this (remove the leading >)

> XCOPY /Y /E /D /C "%USERPROFILE%\Documents\*.*" "D:\Backup\Documents-%dow2%\"

  :: DateTime using WSH
  :: datetime.bat V4
  ::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  ::
  :: This uses Windows Scripting Host to set variables
  :: to the current date/time/day/day_number
  :: for Win9x/ME/NT/W2K/XP etc
  :: Thanks go to Todd Vargo for his scripting
  ::::::::::::::::::::::::::::::::::::::::::::::::::::::::
   <at> echo off
  set TmpFile="%temp%.\tmp.vbs"
(Continue reading)

Aristos Vasiliou | 28 Jun 2010 20:15
Favicon

RE: Daily Backup Without Overwrite

Hi,

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.

Thanks
________________________________
From: batchworld@...
[batchworld@...] on behalf of
foxidrive@... [foxidrive@...]
Sent: Friday, June 25, 2010 11:10 AM
To: batchworld@...
Subject: Re: [BATCH WORLD] Daily Backup Without Overwrite

On Thu, 24 Jun 2010 19:32:19 +0000, Aristos Vasiliou
<aristos@...<mailto:aristos%40aristos.net>> 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?

(Continue reading)

foxidrive | 29 Jun 2010 13:10

Re: Daily Backup Without Overwrite

On Mon, 28 Jun 2010 18:15:43 +0000, Aristos Vasiliou
<aristos@...> 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

------------------------------------

To Post a message, send it to:   batchworld@...

To Unsubscribe, send a blank message to:
batchworld-unsubscribe@...! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/batchworld/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/batchworld/join
    (Yahoo! ID required)
(Continue reading)

Aristos Vasiliou | 29 Jun 2010 02:48
Favicon

RE: Daily Backup Without Overwrite

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)
(Continue reading)

foxidrive | 30 Jun 2010 03:37

Re: Daily Backup Without Overwrite

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. :)

------------------------------------

To Post a message, send it to:   batchworld@...

To Unsubscribe, send a blank message to:
batchworld-unsubscribe@...! Groups Links

(Continue reading)

foxidrive | 30 Jun 2010 04:00

Re: Daily Backup Without Overwrite

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.
(Continue reading)

Aristos Vasiliou | 29 Jun 2010 19:27
Favicon

RE: Daily Backup Without Overwrite

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@...
[batchworld@...] on behalf of
foxidrive@... [foxidrive@...]
Sent: Wednesday, June 30, 2010 5:00 AM
To: batchworld@...
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
(Continue reading)

foxidrive | 30 Jun 2010 10:07

Re: Daily Backup Without Overwrite

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"

------------------------------------

To Post a message, send it to:   batchworld@...

To Unsubscribe, send a blank message to:
batchworld-unsubscribe@...! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/batchworld/

(Continue reading)

GBL | 25 Jun 2010 20:06
Favicon

Re: Daily Backup Without Overwrite

--- In batchworld@..., Aristos Vasiliou <aristos <at> ...> 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
(Continue reading)


Gmane