Advertisement

There's no such thing as a stupid question, but they're the easiest to answer.
Login
Search

Advertisement

DOS/Other DOS/Other
Search Search
Search for:
Tech Support Guy > > >

Solved: output batch errors to log files


(!)

new tech guy's Avatar
new tech guy has a Photo Album
Computer Specs
Member with 5,178 posts.
THREAD STARTER
 
Join Date: Mar 2006
Location: NJ
Experience: Intermediate
12-Sep-2008, 03:46 PM #1
Solved: output batch errors to log files
Hello folks,
I have a batch script i use to backup files on the pcs in my network to a central NAS. Has an offsite tool too that runs fine but that is beside the point. What i have a problem with is that i have an xcopy line to backup files. And if it has an error i want the error to be displayed in the log file. But for some reason the redirect switch (>>pathtomyfile.txt) will not show that output nor give me the command that was used. I do not want my users to see the command but want to see it in the commandline. I hope everyone understands what im asking, anyway, here is a copy of what i am using and the scripts run on both winxp/windows vista machines.

Code:
@echo off
echo =======================NeMiSyS Filebackup Utility v4.0==========================
echo Logging into Server...
net use G: /d
net use H: /d
net use G: \\mybookworld\vincent /USER:vincent XXXXXXXXX
net use H: \\mybookworld\public
echo Modifying backup directories...
rmdir G:\laptop_backup\backup3 /s /q
rename G:\laptop_backup\backup2 backup3
rename G:\laptop_backup\backup1 backup2
rename G:\laptop_backup\backup backup1
mkdir G:\laptop_backup\backup
mkdir G:\laptop_backup\backup\firefox
echo Backing up files...
xcopy "C:\users\vincent" "G:\laptop_backup\backup\" /e /q /c /EXCLUDE:C:\backup\skipme.txt
echo Backing up firefox profiles...
xcopy "C:\Users\Vincent\AppData\Roaming\Mozilla\Firefox\Profiles" "G:\laptop_backup\backup\firefox\" /e /q /c
echo Backup complete!


::Originally coded by JStergis
::Modified by New Tech Guy
(the XXXXXXX is a password)
TheOutcaste's Avatar
Computer Specs
Member with 9,028 posts.
 
Join Date: Aug 2007
Location: Oregon, USA
Experience: Intermediate
13-Sep-2008, 06:21 AM #2
OK, I'm assuming the redirection is on the command line that calls this script, as I don't see it in the script itself. Which means all the echo commands like Logging into Server... etc go into the log file, is this correct? The only thing that will appear on the Command Prompt window are errors.

By default, the redirection only redirects STDOUT, not STDERR. You can redirect STDERR to a file as well, but not the same file to which the STDOUT is being sent.
And, you can't output to both a file and the Command Prompt window at the same time, at least not natively. There are several apps to allow this though, search the web for windows tee command.
You can do it in a batch file, but you have to capture the error, read it back in, then output to the screen and then to the log file.

It is fairly simple to set up a separate file to capture errors. Use this:
backup.cmd 1>logfile.txt 2>errorlog.txt
Best to also echo a day/date line to each file at the start so you can match errors to the same run.
One problem with this is that anything that requires a user response is written to STDOUT -- and since it is being redirected, you'll never see it; for example, a prompt to overwrite an existing file. The program will appear to have hung. This shouldn't happen with this file as you are creating a new folder to backup to each time. Same thing with Control C -- you'll never see the prompt asking if you want to terminate, but if you keep hitting CTRL+C it will stop

As far as outputting the command that caused the error, you would have to turn echo on. Even then, there would be no way to match the error to a specific command, as the commands would be echoed to the log file while the error goes to the error file.

I think the best approach would be to add error checking to the commands. Errors will be redirected to a temp file. After each command, check for errors, if an error occurs, you can read the error from the temp file and echo the error and the command to the screen, which will add it to the log as all output goes to the log.

errorlevels returned by xcopy are:
Errorlevels
  • 0 Files were copied without error
  • 1 No files were found to copy
  • 2 The user pressed CTRL+C (^C) to terminate XCOPY
  • 4 Initialization error occurred. There is not enough memory or disk space, or you entered an invalid drive name or invalid syntax on the command-line
  • 5 Disk write error occurred

I've never seen #1 -- xcopy has always returned 0 if no files were found to copy for me. # 4 can also mean that the specified file doesn't exist. If you just need to know that an error occurred, but not the specific one, use this:

Code:
xcopy "C:\users\vincent" "G:\laptop_backup\backup\" /e /q /c /EXCLUDE:C:\backup\skipme.txt 2>%temp%\tmp}1{.txt
If NOT ERRORLEVEL 1 GoTo _noerror1
 :: Echo the command and the error
for /f %%I in (%temp%\tmp}1{.txt) Do (
Echo This command -- xcopy "C:\users\vincent" "G:\laptop_backup\backup\" /e /q /c /EXCLUDE:C:\backup\skipme.txt
Echo caused this error -- %%I
)
:_noerror1
Do the same for each xcopy command.

I would also suggest you change these lines:
Code:
net use G: /d
net use H: /d
to this
Code:
If Exist G:\ net use G: /d
If Exist H:\ net use H: /d
This will avoid an error if the drive is NOT mapped.

You say this is run under WinXP and Vista, but the paths shown are Vista paths . If you are using two files, one for Vista and one for XP with the paths modified for each, you can simplify things by checking to see what OS you are running on, then set the paths appropriately. That way you only have one version to maintain. So the whole thing would look like this:
Code:
@echo off
echo =======================NeMiSyS Filebackup Utility v4.0==========================
:: Check OS version to set correct paths
ver |find /I "version 6" >Nul
If %ErrorLevel% == 0 goto _Vista[/b][/color]
ver |find /I "version 5" >Nul
If %ErrorLevel% == 0 goto _XPor2K
Echo Unsupported Operating system:&ver
Goto:EOF
:_XPor2K
:: OS is XP or 2K
Set source1=c:\Documents and Settings\Vincent
Set source2=%source1%\Application Data\Mozilla\Firefox\Profiles
Goto _backup
:_Vista
:: OS is Vista
Set source1=C:\users\vincent
Set source2=%source1%\AppData\Roaming\Mozilla\Firefox\Profiles
:_backup
echo Logging into Server...
If Exist G:\ net use G: /d
If Exist H:\ net use H: /d
net use G: \\mybookworld\vincent /USER:vincent XXXXXXXXX
net use H: \\mybookworld\public
echo Modifying backup directories...
rmdir G:\laptop_backup\backup3 /s /q
rename G:\laptop_backup\backup2 backup3
rename G:\laptop_backup\backup1 backup2
rename G:\laptop_backup\backup backup1
mkdir G:\laptop_backup\backup
mkdir G:\laptop_backup\backup\firefox
echo Backing up files...
xcopy "%source1%" "G:\laptop_backup\backup\" /e /q /c /EXCLUDE:C:\backup\skipme.txt 2>%temp%\tmp}1{.txt
If %ERRORLEVEL% == 0 GoTo _noerror1
:: Echo the command and the error to the screen so it will end up in the log
For /F %%I in (%temp%\tmp}1{.txt) Do (
Echo This command -- xcopy "%source1%" "G:\laptop_backup\backup\" /e /q /c /EXCLUDE:C:\backup\skipme.txt
Echo caused this error -- %%I
)
:_noerror1
echo Backing up firefox profiles...
xcopy "%source2%" "G:\laptop_backup\backup\firefox\" /e /q /c >%temp%\tmp}1{.txt
If %ERRORLEVEL% == 0 GoTo _noerror2
:: Echo the command and the error to the screen so it will end up in the log
For /F %%I in (%temp%\tmp}1{.txt) Do (
Echo This command -- xcopy "%source2%" "G:\laptop_backup\backup\firefox\" /e /q /c
Echo caused this error -- %%I
)
:_noerror2
echo Backup complete!

:: delete tmp files
Del /q %temp%\tmp}?{.txt


::Originally coded by JStergis
::Modified by New Tech Guy
If the above is named filebackup.cmd call it like this:

Code:
filebackup >>C:\pathtomyfile\BackupLogFile.txt
It's late and I haven't created a file structure to test this with your paths, so there may be typos or glitches I missed, so test carefully

HTH

Jerry

Edit -- Made corrections to the code, they are shown in Red

Last edited by TheOutcaste; 13-Sep-2008 at 10:57 PM.. Reason: Corrections to code
new tech guy's Avatar
new tech guy has a Photo Album
Computer Specs
Member with 5,178 posts.
THREAD STARTER
 
Join Date: Mar 2006
Location: NJ
Experience: Intermediate
13-Sep-2008, 12:57 PM #3
Thanks the outcaste, i had it running under a .bat file. Also thanks alot for explaining how to combine the two versions as as you stated, i have an xp and vista version of them for each machine on the network depending which OS im using. Also, usually the old drive mapping is there which is why i have the
net use G: /d...etc line in there. I sent you the current version that was out which is why there was no logging going on. Also, the reason for the logging is because i have novice users who run the batch and usually dont tell me when its broken and it would take me working on the pc to find out somthing is amiss. The posted version was the one for my laptop which is vista particularly. Also, i had no logging on the one i sent you yet as i was not sure how to get the stderr part. Finally just to point out, i have a script on the machine which starts the main backup script through another batch which all it does is blast out the current backup file it has and it copies over the file from a directory on the server by logging onto it, mapping it so it can copy, then after changing the files drops the extra network connection and proceeds to the backup. Will your posted version run in a bat file or will i need some other filetype to execute it? And what would also greatly simplify things is if there is a way to just use a variable with that os check you have so that it just uses the variable to get to the active user"s backup directory. This way i dont need to chase the code around and see who im working on. I know this is a little confusing but thanks for bearing with me. And yes i want to see on the screen certain echo lines for the users (want to keep the interface simple). Therefore the front end would look like this (well what the current code shows)

[frontend]
=====================Nemisys filebackup utility v4.0======================
Logging into server....
Modifying backup directories....
Backing up files.....
Backing up firefox profiles....
Backup Complete![/frontend]
new tech guy's Avatar
new tech guy has a Photo Album
Computer Specs
Member with 5,178 posts.
THREAD STARTER
 
Join Date: Mar 2006
Location: NJ
Experience: Intermediate
13-Sep-2008, 05:55 PM #4
Ok an update, i found out how to combine the two text files into one using the type command. So i figure i can capture the stdin,stdout, and stderr command of each and after each command add a type command to combine the error file with the main log. Also that code you posted for the os choice is good, but i think i found an easier solution. However, its untested but an idea nonetheless (ive had a dummy batch i made which is being used for testing). I found out and remember it originally from the firefox help file on the location of the profile folder. I found that instead of having to use either the C:\user or C:\documents and settings , you could just type %userprofile% . And it automatically jumps to that users directory. This works in both xp and vista. I am considering parts of what you have given me however, like the if string you have for the network directories. Thirdly i have an idea for security, once the batch code is executed i am thinking of having it launch another script again which will clear the backup folder this way it helps protect the NAS logons by removing the script file which contains the logon password. Also it ensures it is always running the latest version of the script.
new tech guy's Avatar
new tech guy has a Photo Album
Computer Specs
Member with 5,178 posts.
THREAD STARTER
 
Join Date: Mar 2006
Location: NJ
Experience: Intermediate
13-Sep-2008, 06:40 PM #5
Another question for you as well, when i write this code, should I write the log for every line with action, just so i know if anything breaks down or just keep it to the copy lines? I was thinking of doing everything so i know if any line anywhere blows up for some reason but it may not be needed or necessary.
TheOutcaste's Avatar
Computer Specs
Member with 9,028 posts.
 
Join Date: Aug 2007
Location: Oregon, USA
Experience: Intermediate
13-Sep-2008, 08:56 PM #6
I see you found the %userprofile% variable, very handy
type Set in a command prompt to see many others, computer name, domain name, username, user profile, logon server, appdata path, program files location, etc
Using %userprofile% and %appdata% you don't even need to check which OS it is.

You can run the file as a .bat or .cmd, either works.

Lots of variations on finding the current OS.
What I posted above actually won't work as I messed up the errorlevel check.
IF Errorlevel 0 actually does this: If %errorlevel% GEQ 0
so that code will always think it's on Vista.
Should check it this way (And I really should have added the Nul so the find result doesn't end up in the log):

Code:
:: Check OS version to set correct paths
ver |find /I "version 6" >Nul
If %ErrorLevel% == 0 goto _Vista
ver |find /I "version 5" >Nul
If %ErrorLevel% == 0 goto _XPor2K
Echo Unsupported Operating system:&ver
Goto:EOF
Here's a handy mnemonic to remember the Errorlevel Find returns -- f0und/m1ssing
Same with the other error checks
I also left out a label. I've edited the above post to correct that.

If the error message happens to be more than one line, a better way to output the command and error to the log is to use type.
I've done a little more tweaking and come up with this the code below.
It starts a temp log file %temp%\tmp}0{.txt
Command output is sent to %temp%\tmp}1{.txt
Errors are sent to %temp%\tmp}2{.txt
Numbers match the stdout and stderr numbers to help keep them straight

The output and errors are copied to the temp log after each command
When done, the temp log is copied to c:\Backups\TmpBackup.log
The script that starts this file can then append it to the master log on the server, or on this PC, then delete the TmpBackup.log file and the batch file to help secure the password. Note that if the user presses CTRL+C, they can stop the script, then read the file to see the password though.
You could have the script download and call a separate batch file from the server that will actually do the drive mapping, then delete it. That way the file with the password won't be on the system that long. Of course, they can always read the batch file to find the name and location of the file that has the password, but at least it wouldn't be on the system that long.

Note that I added a Set xcopycmd=xcopy /ceq variable at the start. You then use %xcopycmd% instead of xcopy
This makes it easy to change the switches for the command as you only have to do it in one place.
and if a particular command needs an added switch, you just add it for that one command %xcopycmd%m
You can also use Set switches=/ceq then xcopy %switches%

Code:
@echo off
echo =======================NeMiSyS Filebackup Utility v4.0==========================
Set source1=%Userprofile%
Set source2=%AppData%\Mozilla\Firefox\Profiles
Set Destination=G:\laptop_backup\backup
Set xcopycmd=xcopy /ceq
echo Logging into Server...
If Exist G:\ net use G: /d
If Exist H:\ net use H: /d
net use G: \\mybookworld\vincent /USER:vincent XXXXXXXXX
net use H: \\mybookworld\public
echo Modifying backup directories...
rmdir %Destination%3 /s /q
rename %Destination%2 backup3
rename %Destination%1 backup2
rename %Destination% backup1
mkdir %Destination%
mkdir %Destination%\firefox
echo Backing up files...
>%temp%\tmp}0{.txt Echo ==============================
>>%temp%\tmp}0{.txt Echo Backup Job on %Computername% for %Username%
>>%temp%\tmp}0{.txt Echo Started on %date% at %time%
>>%temp%\tmp}0{.txt Echo ==============================
%xcopycmd% "%source1%" "%Destination%" 1>%temp%\tmp}1{.txt 2>%temp%\tmp}2{.txt
If %ERRORLEVEL% == 0 GoTo _noerror1
:: Echo the command and the error to the %temp%\tmp}3{.txt file
>%temp%\tmp}3{.txt Echo ==============================
>>%temp%\tmp}3{.txt Echo This command -- %xcopycmd% "%source1%" "%Destination%" -- caused this error:
>>%temp%\tmp}3{.txt Type %temp%\tmp}2{.txt
>>%temp%\tmp}3{.txt Echo It's output was:
>>%temp%\tmp}3{.txt Type %temp%\tmp}1{.txt
>>%temp%\tmp}3{.txt Echo ==============================
Del %temp%\tmp}1{.txt
Ren %temp%\tmp}3{.txt tmp}1{.txt
:_noerror1
 :: Add output of the command (and errors if any) to the log file
>>%temp%\tmp}0{.txt Type %temp%\tmp}1{.txt
echo Backing up firefox profiles...
%xcopycmd% "%source2%" "%Destination%\firefox\" 1>%temp%\tmp}1{.txt 2>%temp%\tmp}2{.txt
If %ERRORLEVEL% == 0 GoTo _noerror2
:: Echo the command and the error to the %temp%\tmp}3{.txt file
>%temp%\tmp}3{.txt Echo ==============================
>>%temp%\tmp}3{.txt Echo This command -- %xcopycmd% "%source2%" "%Destination%\firefox" -- caused this error:
>>%temp%\tmp}3{.txt Type %temp%\tmp}2{.txt
>>%temp%\tmp}3{.txt Echo It's output was:
>>%temp%\tmp}3{.txt Type %temp%\tmp}1{.txt
>>%temp%\tmp}3{.txt Echo ==============================
Del %temp%\tmp}1{.txt
Ren %temp%\tmp}3{.txt tmp}1{.txt
:_noerror2
:: Add output of the command (and errors if any) to the log file
>>%temp%\tmp}0{.txt Type %temp%\tmp}1{.txt
>>%temp%\tmp}0{.txt Echo ==============================
>>%temp%\tmp}0{.txt Echo Backup Job on %Computername% for %Username%
>>%temp%\tmp}0{.txt Echo Completed on %date% at %time%
>>%temp%\tmp}0{.txt Echo ==============================
copy %temp%\tmp}0{.txt c:\Backups\TmpBackup.log
echo Backup complete!

:: delete all tmp files
Del /q %temp%\tmp}?{.txt


::Originally coded by JStergis
::Modified by New Tech Guy
Jerry

Last edited by TheOutcaste; 13-Sep-2008 at 10:40 PM.. Reason: Added missing code shown in Red
TheOutcaste's Avatar
Computer Specs
Member with 9,028 posts.
 
Join Date: Aug 2007
Location: Oregon, USA
Experience: Intermediate
13-Sep-2008, 10:54 PM #7
Quote:
Originally Posted by new tech guy View Post
Another question for you as well, when i write this code, should I write the log for every line with action, just so i know if anything breaks down or just keep it to the copy lines? I was thinking of doing everything so i know if any line anywhere blows up for some reason but it may not be needed or necessary.
You can call the file like this:
Backup 2>errlog.txt
any errors from commands that do NOT have STDERR redirected will end up here. It will only be the error message though, and not include the command.
But at least you would know that there was an error
The file will always be created, but if there are no errors, it will have a length of zero. You could check that and if it's not zero copy the error to the main log and create a file on the server you would check to see if an error occurred.

A trick you can use is to use variables for the redirection and errorlevel check for commands you don't need to log on a regular basis. These variables would be set depending on the value of a debug variable, which can be set in the file or directly in the command prompt. With Debug set to 0, they won't be redirected. Set Debug to 1 and they will.
You'd definitely want to use a subroutine to output the error log info rather than having the same echo commands for each command in the file.
In that case you could use this:
Code:
Set debug=1
If [%debug%]==[0] (
    set debugf=9999
    set redir=
    ) Else (
    Set debugf=0
    Set redir=1^>%temp%\tmp}1{.txt 2^>%temp%\tmp}2{.txt
    )


Then use this

rename %Destination%2 backup3 %redir%
If NOT %Errorlevel%==%debugf% Call:debugerror "rename %Destination%2 backup3"
rename %Destination%1 backup2 %redir%
If NOT %Errorlevel%==%debugf% Call:debugerror "rename %Destination%1 backup2"
.
.
.
%xcopycmd% "%source1%" "%Destination%" 1>%temp%\tmp}1{.txt 2>%temp%\tmp}2{.txt
If NOT %ERRORLEVEL%==0 Call:errorsubroutine "%xcopycmd% "%source1%" "%Destination%""
:: Add output of the command (and errors if any) to the log file
>>%temp%\tmp}0{.txt Type %temp%\tmp}1{.txt
echo Backing up firefox profiles...
%xcopycmd% "%source2%" "%Destination%\firefox" 1>%temp%\tmp}1{.txt 2>%temp%\tmp}2{.txt
If NOT %ERRORLEVEL% ==0 Call:errorsubroutine "%xcopycmd% "%source2%" "%Destination%\firefox""
:: Add output of the command (and errors if any) to the log file
 >>%temp%\tmp}0{.txt Type %temp%\tmp}1{.txt
.
.
.
echo Backup complete!

:: delete all tmp files
Del /q %temp%\tmp}?{.txt
Goto:EOF
:Errorsubroutine
:: Echo the command and the error to the %temp%\tmp}3{.txt file
Set Errtmp=%*
>%temp%\tmp}3{.txt Echo ==============================
>>%temp%\tmp}3{.txt Echo This command -- %Errtmp:~1,-1% -- caused this error:
>>%temp%\tmp}3{.txt Type %temp%\tmp}2{.txt
>>%temp%\tmp}3{.txt Echo It's output was:
>>%temp%\tmp}3{.txt Type %temp%\tmp}1{.txt
>>%temp%\tmp}3{.txt Echo ==============================
Del %temp%\tmp}1{.txt
Ren %temp%\tmp}3{.txt tmp}1{.txt
Goto:EOF
:debugerror
Call:Errorsubroutine %*
:: Add output of the command (and errors if any) to the log file
>>%temp%\tmp}0{.txt Type %temp%\tmp}1{.txt
GOTO:EOF
The Rename commands would only be logged when debug is set to 1
the xcopy command will always be logged.

HTH

Jerry
new tech guy's Avatar
new tech guy has a Photo Album
Computer Specs
Member with 5,178 posts.
THREAD STARTER
 
Join Date: Mar 2006
Location: NJ
Experience: Intermediate
14-Sep-2008, 12:19 AM #8
Ok what i thought of for keeping the logs was to do somthing like you said, have a directory on the hd which holds them temporarily and then at the end moves it to the server on the users directory. Really the server is a NAS and i control it from a pc which has an always on account which acts like an admin center for it (does offsite backup so all user folders are mapped to that server) and i would have the batch copy the text file to it. This is more secure than an open directory everyone can see. This way they can only see their own profile which they are already logged onto. I am starting to work on a batch for my vista account as well. Only problem i have is that i cant write text files to the root directory of the drive and make a folder as vista would have a hissy fit and ask for admin privledges. XP does not mind but vista does not like the idea of changes being made to it, especially by scripts. But yes im thinking of making cleanup scripts for the machines so that the batches are cleaned up after running.
TheOutcaste's Avatar
Computer Specs
Member with 9,028 posts.
 
Join Date: Aug 2007
Location: Oregon, USA
Experience: Intermediate
14-Sep-2008, 01:18 AM #9
While you can't create files in the root, you should be able to make a folder in the root from a batch file, even as a Standard User, unless the permissions have been modified from the default.

Jerry
new tech guy's Avatar
new tech guy has a Photo Album
Computer Specs
Member with 5,178 posts.
THREAD STARTER
 
Join Date: Mar 2006
Location: NJ
Experience: Intermediate
14-Sep-2008, 10:54 AM #10
I also had a code request....sort of. I was wondering if you could provide me code for the log files so that if for some reason the log upload fails, it does not delete the log file, instead it keeps the local copy. Also it would need a cleanup for its next run so it cleans out the old file before building a new one. Also, im not going to put the logon command into log because it has a password, instead label it with echo lines and give the stdout and stderr.
new tech guy's Avatar
new tech guy has a Photo Album
Computer Specs
Member with 5,178 posts.
THREAD STARTER
 
Join Date: Mar 2006
Location: NJ
Experience: Intermediate
14-Sep-2008, 05:35 PM #11
Hi Jerry,
Wrote some code but cannot get it working for some reason, just kinda pukes out with all kinds of crazy errors. Here is the code that i wrote:

Code:
@echo off
echo =======================NeMiSyS Filebackup Utility v5.0==========================
echo Backup starting... >>C:\backup\log.txt
echo Logging into Server...
echo If Exist G:\ net use G: /d >>C:\backup\log.txt
If Exist G:\ net use G: /d 1>>C:\backup\log.txt 2>C:\backup\error.txt
type C:\backup\error.txt>>C:\backup\log.txt
echo If Exist H:\ net use H: /d >>C:\backup\log.txt
If Exist H:\ net use H: /d 1>>C:\backup\log.txt 2>C:\backup\error.txt
type C:\backup\error.txt>>C:\backup\log.txt
echo Server logon command output for G and H mapping >>G:\logs\laptop\log.txt
net use G: \\mybookworld\vincent /USER:vincent XXXXXXXX>>G:\logs\laptop\log.txt
net use H: \\mybookworld\public >>G:\logs\laptop\log.txt
echo Setting up server directories, if no entries appear in this area, the commands completed without any errors >>C:\backup\log.txt
echo Modifying backup directories...
rmdir G:\laptop_backup\backup3 /s /q >>C:\backup\log.txt 2>C:\backup\error.txt
type C:\backup\error.txt>>C:\backup\log.txt
rename G:\laptop_backup\backup2 backup3 >>C:\backup\log.txt 2>C:\backup\error.txt
type C:\backup\error.txt>>C:\backup\log.txt
rename G:\laptop_backup\backup1 backup2 >>C:\backup\log.txt 2>C:\backup\error.txt
type C:\backup\error.txt>>C:\backup\log.txt
rename G:\laptop_backup\backup backup1 >>C:\backup\log.txt 2>C:\backup\error.txt
type C:\backup\error.txt>>C:\backup\log.txt
mkdir G:\laptop_backup\backup 1>>C:\backup\log.txt 2>C:\backup\error.txt
type C:\backup\error.txt>>C:\backup\log.txt
mkdir G:\laptop_backup\backup\firefox >>C:\backup\log.txt 2>C:\backup\error.txt
type C:\backup\error.txt>>C:\backup\log.txt
echo NOW the system atcually backs up the files, or does it? heh heh... >>G:\logs\laptop\log.txt
echo Backing up files...
echo xcopy %userprofile% "G:\laptop_backup\backup\" /e /q /c /EXCLUDE:C:\backup\skipme.txt >>C:\backup\log.txt
xcopy %userprofile% "G:\laptop_backup\backup\" /e /q /c /EXCLUDE:C:\backup\skipme.txt >>C:\backup\log.txt 2>C:\backup\error.txt
type C:\backup\error.txt>>C:\backup\log.txt
echo Now we back up firefox... >>C:\backup\log.txt
echo Backing up firefox profiles...
echo xcopy %appdata&\Mozilla\firefox\profiles "G:\laptop_backup\backup\firefox\" /e /q /c >>C:\backup\log.txt
xcopy %appdata&\Mozilla\firefox\profiles "G:\laptop_backup\backup\firefox\" /e /q /c >>C:\backup\log.txt 2>C:\backup\error.txt
type C:\backup\error.txt>>C:\backup\log.txt
echo Backup complete!
echo Cleaning up... >>C:\backup\log.txt
echo Cleaning up...
pause
If Exist C:\backup\*.bat del C:\backup\*.bat 1>>C:\backup\log.txt 2>C:\backup\error.txt
del C:\backup\error.txt
copy C:\backup\log.bat G:\
exit
I cant understand why it fails, it does not even map the directory right, if you want i can give the log output.

Last edited by new tech guy; 15-Sep-2008 at 09:09 AM..
new tech guy's Avatar
new tech guy has a Photo Album
Computer Specs
Member with 5,178 posts.
THREAD STARTER
 
Join Date: Mar 2006
Location: NJ
Experience: Intermediate
14-Sep-2008, 05:52 PM #12
Ok i found the problem, i mistyped a few log commands in the beginning . I still get a bunch of errors on the window however, not sure why comes up twice on file, once on path.
TheOutcaste's Avatar
Computer Specs
Member with 9,028 posts.
 
Join Date: Aug 2007
Location: Oregon, USA
Experience: Intermediate
15-Sep-2008, 03:14 AM #13
I'm guessing the lines in green are the typos you found?
It's the little stuff like that, and hitting & for % (which I've been doing all day) that will drive ya nuts
Quote:
Originally Posted by new tech guy View Post
Code:
@echo off
echo =======================NeMiSyS Filebackup Utility v5.0==========================
echo Backup starting... >>C:\backup\log.txt
echo Logging into Server...
echo If Exist G:\ net use G: /d >>C:\backup\log.txt
If Exist G:\ net use G: /d 1>>C:\backup\log.txt 2>C:\backup\error.txt
  The IF Command itself can't be redirected, as the only error it can cause is a syntax error.
  The redirection applies only to the command if it gets executed
type C:\backup\error.txt>>C:\backup\log.txt
Use If EXIST C:\backup\error.txt type C:\backup\error.txt>>C:\backup\log.txt 
echo If Exist H:\ net use H: /d >>C:\backup\log.txt
If Exist H:\ net use H: /d 1>>C:\backup\log.txt 2>C:\backup\error.txt
 type C:\backup\error.txt>>C:\backup\log.txt
Use If EXIST C:\backup\error.txt type C:\backup\error.txt>>C:\backup\log.txt 
echo Server logon command output for G and H mapping >>G:\logs\laptop\log.txt
Should be C:\backup\log.txt
net use G: \\mybookworld\vincent /USER:vincent XXXXXXX >>G:\logs\laptop\log.txt
Should be C:\backup\log.txt
net use H: \\mybookworld\public >>G:\logs\laptop\log.txt
Should be C:\backup\log.txt
echo Setting up server directories, if no entries appear in this area, the commands completed without any errors >>C:\backup\log.txt
echo Modifying backup directories...
rmdir G:\laptop_backup\backup3 /s /q >>C:\backup\log.txt 2>C:\backup\error.txt
type C:\backup\error.txt>>C:\backup\log.txt
rename G:\laptop_backup\backup2 backup3 >>C:\backup\log.txt 2>C:\backup\error.txt
type C:\backup\error.txt>>C:\backup\log.txt
rename G:\laptop_backup\backup1 backup2 >>C:\backup\log.txt 2>C:\backup\error.txt
type C:\backup\error.txt>>C:\backup\log.txt
rename G:\laptop_backup\backup backup1 >>C:\backup\log.txt 2>C:\backup\error.txt
type C:\backup\error.txt>>C:\backup\log.txt
mkdir G:\laptop_backup\backup 1>>C:\backup\log.txt 2>C:\backup\error.txt
type C:\backup\error.txt>>C:\backup\log.txt
mkdir G:\laptop_backup\backup\firefox >>C:\backup\log.txt 2>C:\backup\error.txt
type C:\backup\error.txt>>C:\backup\log.txt
echo NOW the system atcually backs up the files, or does it? heh heh... >>G:\logs\laptop\log.txt
Should be C:\backup\log.txt
echo Backing up files...
echo xcopy %userprofile% "G:\laptop_backup\backup\" /e /q /c /EXCLUDE:C:\backup\skipme.txt >>C:\backup\log.txt
xcopy "%userprofile%" "G:\laptop_backup\backup\" /e /q /c /EXCLUDE:C:\backup\skipme.txt >>C:\backup\log.txt 2>C:\backup\error.txt
type C:\backup\error.txt>>C:\backup\log.txt
echo Now we back up firefox... >>C:\backup\log.txt
echo Backing up firefox profiles...
echo xcopy "%appdata&\Mozilla\firefox\profiles" "G:\laptop_backup\backup\firefox\" /e /q /c >>C:\backup\log.txt
xcopy "%appdata&\Mozilla\firefox\profiles" "G:\laptop_backup\backup\firefox\" /e /q /c >>C:\backup\log.txt 2>C:\backup\error.txt
Should be %, will cause File Not found to be put in log by next command
Also, quotes are missing, the space in Documents and Setting or a username will cause errors
 type C:\backup\error.txt>>C:\backup\log.txt
echo Backup complete!
echo Cleaning up... >>C:\backup\log.txt
echo Cleaning up...
pause
If Exist C:\backup\*.bat del C:\backup\*.bat 1>>C:\backup\log.txt 2>C:\backup\error.txt
del C:\backup\error.txt
Missing line -- any error from the copy command will not be saved
type c:\Test1\backup\error.txt>>c:\Test1\backup\log.txt
copy C:\backup\log.bat G:\
Should be txt
exit
This copies the log to the root folder instead of appending it, so you will only have a log for the last backup.
I'd suggest putting the log into G:\laptop_backup\backup\ so you will have the log for each of the 3 backups. I would also copy the user profile to G:\laptop_backup\backup\profile.

Since you are not using the H switch with xcopy, hidden files will not be copied. If the users systems are set to not show hidden/system files, the Application Data and Local Settings trees will not be copied. Since you are copying firefox separately I'm guessing that's how it's setup.
Couple of things -- If you are depending on hidden files not being copied, make sure the user can't change that setting. Or make sure the exclude file covers everything, even hidden folders.
If you use Outlook or Outlook Express, they do store their data in those trees unless you've changed the path(at least on XP, not sure about Outlook or Windows Mail on Vista), so if your users use either, you may want to add commands to specifically back them up as well.

Jerry
new tech guy's Avatar
new tech guy has a Photo Album
Computer Specs
Member with 5,178 posts.
THREAD STARTER
 
Join Date: Mar 2006
Location: NJ
Experience: Intermediate
15-Sep-2008, 10:44 AM #14
Yeah i have been making silly typos in the code, i was picking off lines cause i had class the next day before putting the code down for a bit. My main thing was later during the night yesterday was to just get the main backup running again so at least schoolwork would be saved. As for hidden files/system, i dont back those up. All users of the house are on outlook and i moved the .pst files to the contacts folder so that they are right in the scripts path. I actually did that when i first wrote this thing so emails are fine. As far as i understand outlook, pretty much everything is saved in there although i never saw account settings anywhere, gotta look for a way to output a file of that too to simplify an outlook restore. Right now for that when i first set up a pc, i set up outlook then image it. It then copies the .pst files and if a restore is done, all i need to do is switch the pst in the system from time of image (it was already moved and everything in the image) with one from the script output. I stopped working on the code last night because as you said it was making me a little crazy and i just had to step away from it for a bit after getting mine to work (albeit buggy but actual backups work). I will look at what you gave me and give it a try, now if i understand correctly the code you gave me will work for all users, just need to change usernames and some paths possibly?
new tech guy's Avatar
new tech guy has a Photo Album
Computer Specs
Member with 5,178 posts.
THREAD STARTER
 
Join Date: Mar 2006
Location: NJ
Experience: Intermediate
16-Sep-2008, 03:53 PM #15
Sorry i have not done much in terms of the script lately. Its been because ive been busy during the week between school and work, will start working on it again as soon as i have some free time.
As Seen On

BBC, Reader's Digest, PC Magazine, Today Show, Money Magazine
WELCOME TO TECH SUPPORT GUY!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.


(clock)
THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Search Tech Support Guy

Find the solution to your
computer problem!




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


WELCOME
You Are Using: Server ID
Trusted Website Back to the Top ↑