1.

Solve : batch file to xcopy?

Answer»

we have a series of towers xp, sp2/sp3 that we back up every night to a server. i use the following code...

rasdial.exe (establishes VPN)
set folder=%date:~0,2% (every day it backs up, it makes a new folder for 31 DAYS and rewrites on the particular day)
net use.... \\server\...(maps drive to use, destination)
cd C:\Operations\Forms (source)
ECHO D| xcopy c: \\server\pll065\%folder% /s /E /h /D
rasdial.exe test /disconnect
shutdown -r

i have downloaded the sleep.exe file, and should that be in the system 32 folder, somewhere else, or does it really matter where it is located? what i would like is a series of pauses (after rasdial.exe and net use...) i know that i have to use sleep XX to stop the process for XX seconds, but location of sleep is what i need to know.

also, how can i get the above batch file to create a report INDICATING date, how long the vpn was establihsed or how long it took to run the batch and amount of files that were updated? something like yyyy-mm-dd, hh:mm:ss, X files updated or backedup?

thank you,

jat

System 32 is the correct place for Sleep.exe

And for the reporting document. try the following code.
Code: [Select]echo %date%, %time% VPN Established > Report.txtadd this right before the rasdial.exe

then

Code: [Select]echo %date%, %time% VPN Disconnected >> Report.txtadd this right before the shutdown -r command.

In Report.txt it should look like this.

, VPN Established
, VPN Disconnected

Quote from: macdad- on July 15, 2008, 05:10:41 PM

System 32 is the correct place for Sleep.exe

Anywhere on the PATH is the "correct" place for executables.thank you, echo command line works. but i need to bug you guys again for two things.

First: as the echo command runs, the file writes over itself so i would have to view the file daily. i started to surf again, and to fix that problem i used another line i found on this site to rename the ORIGINAL Report.txt file:

for /f "tokens=1-5 delims=/ " %%d in ("%date%") do rename "Report.txt" %%f-%%e-%%d.txt

this adds the date, but the problem is if the backup is run manually, and the file already exists with the current date, the error message "Duplicate file name exists, or the file cannot be found" comes up and the report is not updated. so i tried to get creative, and thought i'd add a time stamp to the rename and tried:

for /f "tokens=1-5 delims=/ " %%d in ("%date%") do rename "Report.txt" %%f-%%e-%%d%time%.txt

(there is a line to rename the file with the system time, but then no date is readily visible, that's why i am looking for a date, time format.) no formatting of the time, just stamp the time so that the two files (if necessary) can be made on the same day. but with this line, i get the message:

...>rename "Report.txt" 2008-07-16 9:22:19.05.txt The syntax of the command is incorrect."

how do i fix it so it accepts the system date time?

The second thing that i would like to do is have it report in the Report.txt file what if any files were copied. the screen does show the file names that were copied, and the number of files that were copied. Can that be an "echo" line after the xcopy... line?

thank you for your help.


jat
timestamp has spaces so filename will need quotes

for /f "tokens=1-5 delims=/ " %%d in ("%date%") do rename "Report.txt" "%%f-%%e-%%d%time%.txt"
tried recommended line, and error is "A duplicate file name exists, or the file cannot be found." thinking that maybe having the "" around just the time stamp, did not work either. thank you for your help though.

jat
The reason why you get that message is because you cannot have colon characters (':') in a filename. Since the %time% variable is of the form hh:mm:ss.cs (cs are hundredths of seconds), any attempt to use it as part of a filename will fail.

You need to replace each colon in %time% with an allowed character such as a dash.

Code: [Select]REM Replace a substring with another

REM 1. replace each a in %string% with a b
REM set string=%string:a=b%

REM 2. Replace cat with dog

REM set string=feed the cat every day
REM set string=%string:cat=dog%

REM Replace 1 char with nothing (i.e. remove each occurence)
REM 3. remove every character a from %string%
REM set string=%string:a=%

REM 1. Replace : with - in %time%
set ntime=%time::=-%

REM 2. Replace . with - in %ntime%
set ntime=%ntime:.=-%

REM Personally I think it looks better with a separator between the date and the time

for /f "tokens=1-5 delims=/ " %%d in ("%date%") do rename "Report.txt" "%%f-%%e-%%d %ntime%.txt"

Code: [Select]REM Personally I think it would look even better with only 1 separator between date and time

REM if you don't need the hundredths of seconds you can remove the last 3 chars from %time% by slicing it
set ntime=%time:~0,8%

set ntime=%ntime::=%

for /f "tokens=1-5 delims=/ " %%d in ("%date%") do rename "Report.txt" "%%f%%e%%d-%ntime%.txt"




Discussion

No Comment Found