Create a Backup from batch

March 18, 2010 at 12:15:44
Specs: Windows XP
Hello,
Am not that good with dos/programming...
Only worked with HTML-CSS!

I wanted to create a backup batch file. It has to copy the files\folder from the user workstation to a mapped drive on the network. Then have it create a log file (Logfile.txt) with the date and time of last backup. When the back up runs again add to the log file content with out over writing it!

My problem is the log file am sure i can work out the Copying Part.

:: Logfile
:: Create Backup logfile
::
C:
CD\batch\
Echo Backup ran at %time% %date% > logfile.txt
::
COPY logfile.txt c:\Temp
::
REN C:\Temp\logfile.txt %date%-%time%.txt

My PC counts only from 0-1 yet still it those math better then me!!! Help me please!!!!


See More: Create a Backup from batch

Report •


#1
March 18, 2010 at 12:51:32
Its not working because you can not have "/" in files names and the date has them. You need to pars the "/" out with the following code...

Set Day=%Date:~-7,2%
Set Month=%Date:~-10,2%
Set Year=%Date:~-4,4%
Set TodaysDate=%Month%-%Day%-%Year%

echo %TodaysDate%

Replaces the / with -.


Report •

#2
March 18, 2010 at 14:37:30
Great! &BUT

"Yes" There is a but lower down.

At first I was lost, I tried it out and it didn't Work.
Due to a mistake I made in batch file.
Then i worked fine!

So I altered it to give me what I wanted.
...........................................................................
:: Logfile
:: Create Backup logfile
::
C:
CD\batch\
Echo Backup ran at %time% %date% > logfile.txt
::
COPY logfile.txt c:\lll
::
Set Hour=%Time:~-11,-9%
Set Min=%Time:~-8,-6%
Set sec=%Time:~-5,-3%
Set Day=%Date:~-7,2%
Set Month=%Date:~-10,2%
Set Year=%Date:~-4,4%
Set TodaysDate=%Month%-%Day%-%Year%
Set TodaysTime=%Hour%-%Min%-%Sec%
REN C:\lll\logfile.txt %TodaysDate%_%TodaysTime%.txt
..........................................................................
But I need to know how to add content with out over writing whats already in the log file text file!

"Thanks" for the first bit of code Ace_Omega!


Report •

#3
March 19, 2010 at 03:54:10
Replace the single carot (>) with a double carot (>>).

The first replaces the file each time and the second appends to the file.

-- kptech


Report •

Related Solutions

#4
March 19, 2010 at 07:39:23
Yes you are right use ">>" to append instead of over right but they are Greater Than signs or Chevrons. This is a carrot "^".

! - Bang or Explication
@ - At
# - Pound or Number
$ - String or Dollar
% - Percent
^ - Carrot
& - Ampersand
* - Astrix or Star
~ - Tilda or Tildi
/ - Slash
\ - Back Slash
. - Dot or Period
> - Chevron or Greterthan
#! - Shabang
| - Pipe

Thats all I can think of. :-p

Oh ya emotacon - ;-)


Report •

#5
March 21, 2010 at 17:25:05
ace_omega

Yea, I know, but I've been doing this for over 30 years and you wouldn't believe how many (thousands) of confused looks I get when I tell folks to use the greater than sign. Not many math majors out there I guess...

I was just trying to keep it simple. It doesn't really matter much what you call it as long as you type it correctly.

-- kptech


Report •

#6
March 22, 2010 at 00:55:01
"doesn't really matter much what you call it as long as you type it correctly."

I wonder where 'ace' got some of those names.

'Shabang' sounds like Pilipino comic book-speak.

LOL


=====================================
Helping others achieve escape felicity

M2


Report •

#7
March 22, 2010 at 07:41:47
Most come from the old school days of UNIX and have carried over to the Linux guys but if you double check them they are the except able names for the characters.

Yes, greater than sign can be confusing so most people say chevrons.


Report •

Ask Question