Re: Daily Backup Without Overwrite
- --- In firstname.lastname@example.org, Aristos Vasiliou <aristos@...> wrote:
>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:
> 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?
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
A simpler way would be to deference the ERRORLEVEL pseudo environment variable, like this:
Here's another way to get a similar result, without the WeekDay.exe program.
FOR /F "usebackq delims==" %%i IN (`DATE /T`) DO SET WeekDay=%%i
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.
- On Tue, 29 Jun 2010 17:27:39 +0000, Aristos Vasiliou
>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
I think it was a case of using this as below (remove the > again)
"MD "C:\webserver\wwwroot\%2-%dow2%\" 2>nul"
> %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"