I certainly can't find any options on the NTbackup schedule tab - please can you let me know where they are hidden. Thx
Main Topics
Browse All TopicsWe would like to use NTBACKUP as a cheap solution to backups. Scheduled to run every evening is easy. However, we also would like the .log file to be printed out or emailed and the tape to be ejected on completion. Probably best to use a batch file or script - any ideas?
Thanks.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Hi omb,
Look here for some ideas on Win2k's NTBACKUP scripting:
http://www.jsiinc.com/SUBE
A good example of dealing with tape mounting problems. Also includes a link on how to use BLAT for emailing:
http://www.jsiinc.com/SUBL
pb
Thanks for the feedback pbarrette - some great links and I'm getting a lot further with the backup script now!
Once slight problem.. any idea how I determine the name of the ntbackup log file so that this can also be attached with the email I send use BLAT? Can a variable be used to determine the new log file name? Or how about getting ntbackup to always use the name log file name? but how?
Thanks for all your help.
omb,
In my blat+ntbackup batch script i determine most recent log after ntbackup ends and email it if ntbackup succeed.
Like this:
---cut---
set bkpp="%USERPROFILE%\Local Settings\Application Data\Microsoft\Windows NT\NTBackup\data"
set subj="Daily backup report"
set blatbody="%temp%\%random%%
set recipient=my@email.com
pushd %bkpp%
for /f "tokens=1 delims=" %%I in ('dir /B /O-D') do (
if "%%~xI"==".log" (
type "%%~fI" > %blatbody%
goto :eof
)
)
popd
C:\bin\blat.exe %blatbody% -s %subj% -to %recipient%
del /q /f "%blatbody%"
---cut---
Hi omb,
You will have to use something like the following to find the log file that was modified last:
:: ------------EXAMPLE.BAT---
@ECHO OFF
SET LOGDIR=C:\Documents and Settings\%USERNAME%\Local Settings\Application Data\Microsoft\Windows NT\NTBackup\Data
FOR /F %%F IN ('DIR /B /A-D /O-D /TW "%LOGDIR%\Backup??.log"') DO (
SET LOGFILE=%%F
GOTO GOTLOG
)
:GOTLOG
ECHO Last modified logfile is "%LOGDIR%\%LOGFILE%"
:: ------------EXAMPLE.BAT---
Hope this helps,
pb
Hi 4auHuk,
Didn't see your post before I replied..
Anyway, it isn't necessary to create another file for this. You can just use something like:
BLAT -t me@myemail.com -s "Backup Log for %DATE%-%TIME%" -attach "%LOGDIR%\%LOGFILE%"
This, of course, is based on my above example, but will work for any BLAT message, provided you have a path and filename.
pb
No problem,
I cut-paste these parts from my script in wich i have a reason to create another file for blat message body. In case of ntbackup failure body gets error notification, in case of success it gets header, backup log content and footer.
If you send backup log as attachment sure you do not need to create an extra file.
4auHuk.
Just as addon:
If ntbackup fails, depending on a stage at wich failure occurs (say, ntbackup fails to start completely due to error in switches which are composed dynamically or for some other reason) ntbackup may not create log. In this case you can recieve wrong log file. You should handle this possible behaviour in your script.
4auHuk
Just noticed my example will not send an e-mail since "goto :eof" will skip blat command. Did not change this when psted sub from my script. Should be
pushd %bkpp%
for /f "tokens=1 delims=" %%I in ('dir /B /O-D') do (
if "%%~xI"==".log" (
type "%%~fI" > %blatbody%
goto send
)
)
:send
popd
C:\bin\blat.exe %blatbody% -s %subj% -to %recipient%
del /q /f "%blatbody%"
Wow guys, what tremendous feeback... so here are a few more points ;o)... having 'played' with both scripts, I have several questions:
4auHuk: I like the idea of having a 'blatbody' variable in order to customise messages depending on backup outcome. However, I can't get it to work?! Every time the script runs, it says that the file cannot be found. Blat then fails as it can't find the blatbody message text. The bits I am looking at are:
set blatbody="%temp%\%random%%
type "%%~fI" > %blatbody%
del /q /f "%blatbody%"
pbarrette: Your script which finds the log file that was modified last works great. For some reason, I couldn't get 4auHuk's to work. BTW, I am a scripting novice so go easy on me. However, I kind of understand your scripts and they kind of work!
I use the following to send the email (variables defined above):
%blat% %blatbody1% -to %recipient% -s %subj1% -attach "%LOGDIR%\%LOGFILE%"
I have used a combination of both scripts and also tried to include a little error checking (check for a tape) as in article http://www.jsiinc.com/SUBL
if not "%%a"=="The command completed successfully." set media="%%a"
rem (or in German...)
if not "%%a"=="Der Befehl wurde ausgeführt." set media="%%a"
Thanks so much for your invaluable feedback and support.
I've just had another look at the error checking script and am totally confused :o(... With a tape in the drive, I run:
rsm view /cg%guiddisplay% /TPhysical_media
and receive a display:
PHYSICAL_MEDIA
Tape_label_name - 1
The command completed successfully.
When I run the same command without a tape in the drive, I receive:
PHYSICAL_MEDIA
The command completed successfully.
I can't make sense of the the script (below). Which part of the script is looking for my blank line, which is where the tape label would be if there was a tape in the drive?
:checkmedia
set media=
for /f "Tokens=*" %%a in ('rsm view /cgC888E08900454C4C956DF84
if not "%%a"=="The command completed successfully." set media="%%a"
)
if /i %media% EQU "Unable to open session with the RSM server." goto checkmedia
if /i %media% EQU "PHYSICAL_MEDIA" goto notape
if not defined media goto notape
All I want to be able to test is whether there is a tape in the drive or not - if yes, run the backup and send email with backup log, if no, abort backup and send email saying backup failed. So close, but yet so far! Thanks again for your comments...
Not sure what is the prolbem.
You can remove @echo off in your script for troublrshooting.
At which line(s) you get this error?
You can also insert "echo %blatbody% & pause" after "set blatbody" to see what you get in variable. Same for other variables.
If for some reason "%temp%\%random%%random%.t
4auHuk
Hi omb,
Try this instead:
:: ----------EXAMPLE.BAT-----
@ECHO OFF
SET MEDIA=
SET LINE=
FOR /F "SKIP=2 DELIMS=" %%F IN ('rsm view /cg%guiddisplay% /TPhysical_media') DO (
SET LINE=%%F
CALL :PROCESS
)
GOTO GOTTAPE
:PROCESS
ECHO %LINE% | FINDSTR "The command" > NUL
IF ERRORLEVEL 1 (
ECHO %LINE% | FINDSTR "Der Befehl" > NUL
IF ERRORLEVEL 1 (
SET MEDIA=%LINE%
)
)
GOTO :EOF
:NOTAPE
ECHO Where's my Tape?
ECHO BLAT -Send-Me-A-Nastygram-Now
GOTO :EOF
:GOTTAPE
IF NOT DEFINED MEDIA ( GOTO NOTAPE )
ECHO Media Name = "%MEDIA%"
:: ----------EXAMPLE.BAT-----
You will need to replace %guiddisplay% with your GUID, of course.
Both the original script and mine aren't looking for the media name explicitly. Both are actually looking at the line immediately preceeding the "Successful" text. This line contains the media name in mine (Since I am SKIPping the PHYSICAL_MEDIA text) and contains either the media name or "PHYSICAL_MEDIA" in the original.
Hope this helps,
pb
Great stuff guys...
4auHuk, I changed:
type "%%~fI" > %blatbody%
to
echo "%%~fI" > %blatbody%
...works great with the temp files & msg variables.
pbarrette, I changed:
ECHO %LINE% | FINDSTR "The command" > NUL
to
ECHO %LINE% | FINDSTR "Der Befehl" > NUL
...the script works perfect and sends different messages depending on if there is a tape in the drive or not - yeee haaa! Will this also work if I insert a brand new tape (which has been never used before)?
FYI, my script now looks like this:
:: ----------BACKUP.BAT------
set LOGDIR=%USERPROFILE%\Lokal
set subj1="%computername% Backup Failure"
set subj2="%computername% Backup Successful"
set recipient=alias@domain.de
set blatErrorText=Backup error text for %computername% at %USERDOMAIN% on
set blatOKtext=Backup ran OK text for %computername% at %USERDOMAIN% on
set guiddisplay=E759FC802D6140
set ntbackup=d:\WINNT\system32
set bks=d:\backup\daily.bks
set blat=d:\downloads\blat\bla
set DDSdevice=HP C1537A SCSI Sequential Device
set blatErrorFile="%temp%\%ran
set blatOKfile="%temp%\%random
SET MEDIA=
SET LINE=
rsm.exe inventory /LF"%DDSdevice%" /AFULL
sleep 30
for /f "Tokens=1-4 Delims=/ " %%i in ('date /t') do set dt=%%i-%%j%%k%%l
for /f "Tokens=1" %%i in ('time /t') do set tm=-%%i
set dtt=%dt%%tm%
FOR /F "SKIP=2 DELIMS=" %%F IN ('rsm view /cg%guiddisplay% /TPhysical_media') DO (
SET LINE=%%F
CALL :PROCESS
)
GOTO :GOTTAPE
:PROCESS
ECHO %LINE% | FINDSTR "Der Befehl" > NUL
IF ERRORLEVEL 1 (
ECHO %LINE% | FINDSTR "Der Befehl" > NUL
IF ERRORLEVEL 1 (
SET MEDIA=%LINE%
)
)
GOTO :EOF
:NOTAPE
echo %blatErrorText% %dtt% > %blatErrorFile%
%blat% %blatErrorFile% -to %recipient% -s %subj1%
del /q /f "%blatErrorFile%"
GOTO :EOF
:GOTTAPE
IF NOT DEFINED MEDIA ( GOTO NOTAPE )
ECHO Media Name = "%MEDIA%"
:RUNBACKUP
%ntbackup% backup "@%bks%" /n "%computername%-%dtt%" /d "%computername% voll Sicherung" /v:no /r:no /rs:no /hc:on /m normal /j "%computername% voll Sicherung" /l:s /p "4mm DDS" /UM
rsm.exe eject /PF"%computername%-%dtt% - 1" /astart
:BACKUPRAN
FOR /F %%F IN ('DIR /B /A-D /O-D /TW "%LOGDIR%\Backup??.log"') DO (
SET LOGFILE=%%F
)
ECHO Last modified logfile is "%LOGDIR%\%LOGFILE%"
echo %blatOKtext% %dtt% > %blatOKfile%
%blat% %blatOKfile% -to %recipient% -s %subj2% -attach "%LOGDIR%\%LOGFILE%"
del /q /f "%blatOKfile%"
goto :EOF
:EOF
exit
:: ----------BACKUP.BAT------
Any final comments or suggestions on my script? Just a thought, what would happen if the scheduled task is manually stopped or automatically ended after x hours (option in scheduler)? Do I also need error checking here? Thanks so much for all your tremendous help... and more points for my appreciation :0)
Hi omb,
You didn't need to change the line from my script. I set it up such that it should work correctly on both english and german systems.
Also, ":EOF" is a special label that states "End of File" so you don't actually need a label in your batchfile for it since it will be ignored.
Finally, your logfile routine will send the oldest log instead of the newest one.
It should be:
:: --------------------------
:BACKUPRAN
FOR /F %%F IN ('DIR /B /A-D /O-D /TW "%LOGDIR%\Backup??.log"') DO (
SET LOGFILE=%%F
GOTO GOTLOG
)
:GOTLOG
ECHO Last modified logfile is "%LOGDIR%\%LOGFILE%"
echo %blatOKtext% %dtt% > %blatOKfile%
%blat% %blatOKfile% -to %recipient% -s %subj2% -attach "%LOGDIR%\%LOGFILE%"
del /q /f "%blatOKfile%"
:: --------------------------
Alternately, it could be:
:: --------------------------
:BACKUPRAN
FOR /F %%F IN ('DIR /B /A-D /OD /TW "%LOGDIR%\Backup??.log"') DO (
SET LOGFILE=%%F
)
ECHO Last modified logfile is "%LOGDIR%\%LOGFILE%"
echo %blatOKtext% %dtt% > %blatOKfile%
%blat% %blatOKfile% -to %recipient% -s %subj2% -attach "%LOGDIR%\%LOGFILE%"
del /q /f "%blatOKfile%"
:: --------------------------
Hope this helps,
pb
Thanks for the EOF label info - nice to know! The correct log is now emailed - great. Batch file now tried and tested in a live environment and it works perfect.
After lots and lots of testing, just found 1 problem... if one of the tapes in the drive had not been "prepared" in Computer Manager, Removable devices etc... although it was in the drive, and NTbackup tried to write to it, the whole process failed. The log file mentioned something about not being able to find correct media. However, the email that was sent said that the backup was successful (of course it did, 'coz it only checks to see if a tape is in the drive) - only looking into the attached log file could I see that the back was unsuccessful. Is there a way I can also error-trap this type of message?
Many thanks and more points!
Hi omb,
If you could post the exact message that occurs when ntbackup determines that the tape isn't prepared, that message could probably be filtered and parsed to alter the email notification.
Alternately, you could add an additional step to parse the backup log to search for an error condition, then add that error condition to the email.
Something like:
:: -------EXAMPLE--------
:CHECKLOGFORERRORS
ECHO "%LOGDIR%\%LOGFILE%" | FINDSTR "ErrorCode1 ErrorCode2 ErrorCode3 Etc" > NUL
IF NOT ERRORLEVEL 1 (
ECHO "We found an errorcode in the backup logs"
GOTO DoSomethingAboutIt
)
:: -------EXAMPLE--------
Since you are emailing the log file, you can decide if you want to add additional parsing to get the exact error line, but a general error condition in the subject line is probably enough.
If not, you could probably get the error string itself by parsing the log using "FOR /F".. Something like this, perhaps:
:: -------EXAMPLE--------
FOR /F "DELIMS=" %%F IN ("%LOGDIR%\%LOGFILE%") DO (
SET LINE=%%F
CALL :PROCLOGERRCHECK
)
GOTO NEXTFUNCTION
:PROCLOGERRCHECK
ECHO %LINE% | FINDSTR "ErrorCode1 ErrorCode2 ErrorCode3 Etc" > NUL
IF NOT ERRORLEVEL 1 (
SET LASTERRCODE = %LINE%
)
GOTO :EOF
:: -------EXAMPLE--------
With this, %LASTERRCODE% would contain the text of the line with the last error condition found in the logfile. You could then incorporate that into your BLAT subject.
A better way of handling this specific error might be to see if there is a way you can determine if the tape is "prepared" for use using RSM. If RSM can output parsable data that signifies a tape's "preparedness" then that could be used to abort the backup attempt and send an email. It could possibly even be used to select a different backup location depending upon your setup.
Hope this helps,
pb
Hi pb. I liked the idea of checking bits within the actual log files so that different messages could be parsed to the emails. I used your first example to check for 2 different conditions within the backup log file, as follows:
:CHECKLOGFORERRORS
ECHO "%LOGDIR%\%LOGFILE%" | FINDSTR "Die gesicherten Daten sind beschädigt oder unvollständig" > NUL
IF NOT ERRORLEVEL 1 (
ECHO "%BackupError1%"
set BackupErrorText=%BackupErr
GOTO BACKUPnotOK
)
ECHO "%LOGDIR%\%LOGFILE%" | FINDSTR "Der Vorgang wurde nicht durchgeführt, da die angegebenen Medien nicht gefunden wurden" > NUL
IF NOT ERRORLEVEL 1 (
ECHO "%BackupError2%"
set BackupErrorText=%BackupErr
GOTO BACKUPnotOK
)
GOTO :BACKUPOK
Does FINDSTR search for the complete text between the 2 quotes "..." or any word? It is important that it finds the whole sentence. I also wasn't sure how to combine both search in 1 command line, hence the FINDSTR twice. This script is getting real cool - thanks so much for all of your help and patience with my non-existent programming skills!
Hi omb,
FINDSTR by default will match any space delimited keywords. To get it to match exact sentances, complete with spaces, you must use "/C" like this:
FINDSTR /C:"Der Vorgang wurde nicht durchgeführt, da die angegebenen Medien nicht gefunden wurden"
You can also use multiple occurrences of "/C" to search for multiple items, like this:
FINDSTR /C:"Medien nicht gefunden" /C:"Daten sind beschädigt"
In this example, I used the relevent portions of each search string since there is a command-line length limit and the line is easier to read when editing the batchfile later.
Hope this helps,
pb
calling pbarrette... help me please! I've discovered the script that you wrote for me does NOT 100% work - my fault. I would really appreciate your help again, please see a new call I've opened "http://www.experts-exchan
Business Accounts
Answer for Membership
by: diggisaurPosted on 2004-03-17 at 06:41:34ID: 10615471
You should be able to schedule all this and all these options with the NTBACKUP schedule tab.