omb
asked on
ntbackup batch script problem
We use NTBACKUP, run each evening, as a cheap solution to backups. We have created, with the help of EE member pbarrette (see question https://www.experts-exchange.com/questions/20921686/ntbackup-batch-file-script.html) a script which runs ntbackup & emails the status of the ntbackup job. However, the subject & description of the emails never changes, eventhough there could be problems. FYI, the original script backed up to tape (4mm), this script backs up to external USB hard disks. We also use a German OS, hence the funny German words!
I believe the :CHECKLOGFORERRORS part of the script is the problem. The script always gives a Subj of "%computername% Sicherung Erfolgreich abgeschlossen" and Desc of "Backup ran OK for %computername% at %USERDOMAIN% on" - eventhough, this may not be the case i.e. I have manually stopped the script, checked the log which has the string "Benutzer abgebrochen" within, but the script does not change the Subj or Desc variables.
Here is the script, any ideas?:
========= paste ===========
set blat=c:\downloads\blat\bla t.exe
set Recipient=backup@domain.co m
set Subj="%computername% Sicherung Erfolgreich abgeschlossen"
set Desc=Backup ran OK for %computername% at %USERDOMAIN% on
set Subj1="%computername% Sicherung mit Ausnahmen abgeschlossen"
set Subj2="%computername% Sicherung abgebrochen"
set Subj3="%computername% Sicherung mit Ausnahmen abgeschlossen"
set Subj4="%computername% Sicherung abgebrochen"
set Desc1=Problems with Exchange backup on %computername% at %USERDOMAIN% on
set Desc2=No external hard disk found on %computername% at %USERDOMAIN% on
set Desc3=Problems with the hard disk found on %computername% at %USERDOMAIN% on
set Desc4=Backup broken up by user on %computername% at %USERDOMAIN% on
set ntbackup=C:\WINNT\system32 \NTBACKUP. EXE
set LOGDIR=%USERPROFILE%\Lokal e Einstellungen\Anwendungsda ten\Micros oft\Window s NT\NTBackup\data
set blatErrorFile="%temp%\%ran dom%%rando m%.txt"
set blatTEMPfile="%temp%\%rand om%%random %.txt"
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 %%a in (V W X Y) do if exist %%a:\ set BackupJob=%%a.bks
if /i "%BackupJob%"=="V.bks" (
set jobDescription=Voll Sicherung Montag bis Freitag
set DriveLetter=V
)
if /i "%BackupJob%"=="W.bks" (
set jobDescription=Freitag Sicherung
set DriveLetter=W
)
if /i "%BackupJob%"=="X.bks" (
set jobDescription=Montag und Mittwoch Sicherung
set DriveLetter=X
)
if /i "%BackupJob%"=="Y.bks" (
set jobDescription=Dienstag und Donnerstag Sicherung
set DriveLetter=Y
)
:RUNBACKUP
%ntbackup% backup "@c:\scripts\backup\%Backu pJob%" /n "%computername%-%dtt%" /d "%jobDescription%" /v:no /r:no /rs:no /m normal /j "%computername% voll Sicherung" /l:s /f "%DriveLetter%:\IHG-WTS & SV01.bkf"
:CHECKLOGFORERRORS
FOR /F %%F IN ('DIR /B /A-D /OD /TW "%LOGDIR%\Backup??.log"') DO (
SET LOGFILE=%%F
)
ECHO "%LOGDIR%\%LOGFILE%" | FINDSTR /C:"beschädigt oder unvollständig" > NUL
IF NOT ERRORLEVEL 1 (
set Subj=%Subj1%
set Desc=%Desc1%
GOTO BLAT
)
ECHO "%LOGDIR%\%LOGFILE%" | FINDSTR /C:"Medien nicht gefunden wurden" > NUL
IF NOT ERRORLEVEL 1 (
set Subj=%Subj2%
set Desc=%Desc2%
GOTO BLAT
)
ECHO "%LOGDIR%\%LOGFILE%" | FINDSTR /C:"Gerät meldete einen Fehler" > NUL
IF NOT ERRORLEVEL 1 (
set Subj=%Subj3%
set Desc=%Desc3%
GOTO BLAT
)
ECHO "%LOGDIR%\%LOGFILE%" | FINDSTR /C:"Benutzer abgebrochen" > NUL
IF NOT ERRORLEVEL 1 (
set Subj=%Subj4%
set Desc=%Desc4%
GOTO BLAT
)
:BLAT
echo %Desc% %dtt% > %blatTEMPfile%
%blat% %blatTEMPfile% -to %Recipient% -s %Subj% -attach "%LOGDIR%\%LOGFILE%"
del /q /f "%blatTEMPfile%"
goto :EOF
:EOF
exit
========= paste ===========
I believe the :CHECKLOGFORERRORS part of the script is the problem. The script always gives a Subj of "%computername% Sicherung Erfolgreich abgeschlossen" and Desc of "Backup ran OK for %computername% at %USERDOMAIN% on" - eventhough, this may not be the case i.e. I have manually stopped the script, checked the log which has the string "Benutzer abgebrochen" within, but the script does not change the Subj or Desc variables.
Here is the script, any ideas?:
========= paste ===========
set blat=c:\downloads\blat\bla
set Recipient=backup@domain.co
set Subj="%computername% Sicherung Erfolgreich abgeschlossen"
set Desc=Backup ran OK for %computername% at %USERDOMAIN% on
set Subj1="%computername% Sicherung mit Ausnahmen abgeschlossen"
set Subj2="%computername% Sicherung abgebrochen"
set Subj3="%computername% Sicherung mit Ausnahmen abgeschlossen"
set Subj4="%computername% Sicherung abgebrochen"
set Desc1=Problems with Exchange backup on %computername% at %USERDOMAIN% on
set Desc2=No external hard disk found on %computername% at %USERDOMAIN% on
set Desc3=Problems with the hard disk found on %computername% at %USERDOMAIN% on
set Desc4=Backup broken up by user on %computername% at %USERDOMAIN% on
set ntbackup=C:\WINNT\system32
set LOGDIR=%USERPROFILE%\Lokal
set blatErrorFile="%temp%\%ran
set blatTEMPfile="%temp%\%rand
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 %%a in (V W X Y) do if exist %%a:\ set BackupJob=%%a.bks
if /i "%BackupJob%"=="V.bks" (
set jobDescription=Voll Sicherung Montag bis Freitag
set DriveLetter=V
)
if /i "%BackupJob%"=="W.bks" (
set jobDescription=Freitag Sicherung
set DriveLetter=W
)
if /i "%BackupJob%"=="X.bks" (
set jobDescription=Montag und Mittwoch Sicherung
set DriveLetter=X
)
if /i "%BackupJob%"=="Y.bks" (
set jobDescription=Dienstag und Donnerstag Sicherung
set DriveLetter=Y
)
:RUNBACKUP
%ntbackup% backup "@c:\scripts\backup\%Backu
:CHECKLOGFORERRORS
FOR /F %%F IN ('DIR /B /A-D /OD /TW "%LOGDIR%\Backup??.log"') DO (
SET LOGFILE=%%F
)
ECHO "%LOGDIR%\%LOGFILE%" | FINDSTR /C:"beschädigt oder unvollständig" > NUL
IF NOT ERRORLEVEL 1 (
set Subj=%Subj1%
set Desc=%Desc1%
GOTO BLAT
)
ECHO "%LOGDIR%\%LOGFILE%" | FINDSTR /C:"Medien nicht gefunden wurden" > NUL
IF NOT ERRORLEVEL 1 (
set Subj=%Subj2%
set Desc=%Desc2%
GOTO BLAT
)
ECHO "%LOGDIR%\%LOGFILE%" | FINDSTR /C:"Gerät meldete einen Fehler" > NUL
IF NOT ERRORLEVEL 1 (
set Subj=%Subj3%
set Desc=%Desc3%
GOTO BLAT
)
ECHO "%LOGDIR%\%LOGFILE%" | FINDSTR /C:"Benutzer abgebrochen" > NUL
IF NOT ERRORLEVEL 1 (
set Subj=%Subj4%
set Desc=%Desc4%
GOTO BLAT
)
:BLAT
echo %Desc% %dtt% > %blatTEMPfile%
%blat% %blatTEMPfile% -to %Recipient% -s %Subj% -attach "%LOGDIR%\%LOGFILE%"
del /q /f "%blatTEMPfile%"
goto :EOF
:EOF
exit
========= paste ===========
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hello there pb - thanks for coming back to me so quickly!
I'll amend the script with "type" instead of "echo" and do some tests - makes sense what you say and no problems about the screw-up... without your efforts we would never have even had a script!
BTW, we are also in Germany, Munich... where did you move to?
I'll amend the script with "type" instead of "echo" and do some tests - makes sense what you say and no problems about the screw-up... without your efforts we would never have even had a script!
BTW, we are also in Germany, Munich... where did you move to?
Hi omb,
I'm in Wiesbaden. I have my personal email address in my profile.
Hopefully this fix works out for you,
pb
I'm in Wiesbaden. I have my personal email address in my profile.
Hopefully this fix works out for you,
pb
ASKER
Works great pbarrette... thanks so much for getting back to me so quickly.
Great job you two!! I enjoyed reading over and studying your progress. Here is the ENGLISH translation and FIXED script to your work. Hope it helps someone in the future.
---- cut -----
set blat=c:\downloads\blat\bla t.exe
set Recipient=backup@domain.co m
set Subj="%computername% Successfully completed backup"
set Desc=Backup ran OK for %computername% at %USERDOMAIN% on
set Subj1="%computername% Backup completed with exceptions"
set Subj2="%computername% Backup aborted"
set Subj3="%computername% Backup completed with exceptions"
set Subj4="%computername% Backup aborted"
set Desc1=Problems with Exchange backup on %computername% at %USERDOMAIN% on
set Desc2=No external hard disk found on %computername% at %USERDOMAIN% on
set Desc3=Problems with the hard disk found on %computername% at %USERDOMAIN% on
set Desc4=Backup broken up by user on %computername% at %USERDOMAIN% on
set ntbackup=C:\WINNT\system32 \NTBACKUP. EXE
set LOGDIR=%USERPROFILE%\Local Settings\Application Data\Microsoft\Windows NT\NTBackup\data
set blatErrorFile="%temp%\%ran dom%%rando m%.txt"
set blatTEMPfile="%temp%\%rand om%%random %.txt"
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 %%a in (V W X Y) do if exist %%a:\ set BackupJob=%%a.bks
if /i "%BackupJob%"=="V.bks" (
set jobDescription=Full backup Monday through Friday
set DriveLetter=V
)
if /i "%BackupJob%"=="W.bks" (
set jobDescription=Friday fuse
set DriveLetter=W
)
if /i "%BackupJob%"=="X.bks" (
set jobDescription=Monday and Wednesday backup
set DriveLetter=X
)
if /i "%BackupJob%"=="Y.bks" (
set jobDescription=Tuesday and Thursday backup
set DriveLetter=Y
)
:RUNBACKUP
%ntbackup% backup "@c:\scripts\backup\%Backu pJob%" /n "%computername%-%dtt%" /d "%jobDescription%" /v:no /r:no /rs:no /m normal /j "%computername% full backup" /l:s /f "%DriveLetter%:\IHG-WTS & SV01.bkf"
:CHECKLOGFORERRORS
FOR /F %%F IN ('DIR /B /A-D /OD /TW "%LOGDIR%\Backup??.log"') DO (
SET LOGFILE=%%F
)
ECHO "%LOGDIR%\%LOGFILE%" | FINDSTR /C:"damaged or incomplete" > NUL
IF NOT ERRORLEVEL 1 (
set Subj=%Subj1%
set Desc=%Desc1%
GOTO BLAT
)
ECHO "%LOGDIR%\%LOGFILE%" | FINDSTR /C:"Media can not be found" > NUL
IF NOT ERRORLEVEL 1 (
set Subj=%Subj2%
set Desc=%Desc2%
GOTO BLAT
)
ECHO "%LOGDIR%\%LOGFILE%" | FINDSTR /C:"Device reported an error" > NUL
IF NOT ERRORLEVEL 1 (
set Subj=%Subj3%
set Desc=%Desc3%
GOTO BLAT
)
ECHO "%LOGDIR%\%LOGFILE%" | FINDSTR /C:"User canceled" > NUL
IF NOT ERRORLEVEL 1 (
set Subj=%Subj4%
set Desc=%Desc4%
GOTO BLAT
)
:BLAT
echo %Desc% %dtt% > %blatTEMPfile%
%blat% %blatTEMPfile% -to %Recipient% -s %Subj% -attach "%LOGDIR%\%LOGFILE%"
del /q /f "%blatTEMPfile%"
goto :EOF
:EOF
exit
------- cut -------
---- cut -----
set blat=c:\downloads\blat\bla
set Recipient=backup@domain.co
set Subj="%computername% Successfully completed backup"
set Desc=Backup ran OK for %computername% at %USERDOMAIN% on
set Subj1="%computername% Backup completed with exceptions"
set Subj2="%computername% Backup aborted"
set Subj3="%computername% Backup completed with exceptions"
set Subj4="%computername% Backup aborted"
set Desc1=Problems with Exchange backup on %computername% at %USERDOMAIN% on
set Desc2=No external hard disk found on %computername% at %USERDOMAIN% on
set Desc3=Problems with the hard disk found on %computername% at %USERDOMAIN% on
set Desc4=Backup broken up by user on %computername% at %USERDOMAIN% on
set ntbackup=C:\WINNT\system32
set LOGDIR=%USERPROFILE%\Local
set blatErrorFile="%temp%\%ran
set blatTEMPfile="%temp%\%rand
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 %%a in (V W X Y) do if exist %%a:\ set BackupJob=%%a.bks
if /i "%BackupJob%"=="V.bks" (
set jobDescription=Full backup Monday through Friday
set DriveLetter=V
)
if /i "%BackupJob%"=="W.bks" (
set jobDescription=Friday fuse
set DriveLetter=W
)
if /i "%BackupJob%"=="X.bks" (
set jobDescription=Monday and Wednesday backup
set DriveLetter=X
)
if /i "%BackupJob%"=="Y.bks" (
set jobDescription=Tuesday and Thursday backup
set DriveLetter=Y
)
:RUNBACKUP
%ntbackup% backup "@c:\scripts\backup\%Backu
:CHECKLOGFORERRORS
FOR /F %%F IN ('DIR /B /A-D /OD /TW "%LOGDIR%\Backup??.log"') DO (
SET LOGFILE=%%F
)
ECHO "%LOGDIR%\%LOGFILE%" | FINDSTR /C:"damaged or incomplete" > NUL
IF NOT ERRORLEVEL 1 (
set Subj=%Subj1%
set Desc=%Desc1%
GOTO BLAT
)
ECHO "%LOGDIR%\%LOGFILE%" | FINDSTR /C:"Media can not be found" > NUL
IF NOT ERRORLEVEL 1 (
set Subj=%Subj2%
set Desc=%Desc2%
GOTO BLAT
)
ECHO "%LOGDIR%\%LOGFILE%" | FINDSTR /C:"Device reported an error" > NUL
IF NOT ERRORLEVEL 1 (
set Subj=%Subj3%
set Desc=%Desc3%
GOTO BLAT
)
ECHO "%LOGDIR%\%LOGFILE%" | FINDSTR /C:"User canceled" > NUL
IF NOT ERRORLEVEL 1 (
set Subj=%Subj4%
set Desc=%Desc4%
GOTO BLAT
)
:BLAT
echo %Desc% %dtt% > %blatTEMPfile%
%blat% %blatTEMPfile% -to %Recipient% -s %Subj% -attach "%LOGDIR%\%LOGFILE%"
del /q /f "%blatTEMPfile%"
goto :EOF
:EOF
exit
------- cut -------
I see where it all got screwed up from the beginning now.
My original script (from way back) was doing a line-by-line parsing of a FOR command:
--------------------------
FOR /F "SKIP=2 DELIMS=" %%F IN ('rsm view /cg%guiddisplay% /TPhysical_media') DO (
SET LINE=%%F
CALL :PROCESS
)
:PROCESS
ECHO %LINE% | FINDSTR "The command" > NUL
IF ERRORLEVEL 1 (
ECHO %LINE% | FINDSTR "Der Befehl" > NUL
IF ERRORLEVEL 1 (
SET MEDIA=%LINE%
)
)
--------------------------
Which worked because the "ECHO %LINE%" statements were being fed by the "FOR" command.
Sometime later, I screwed up and added the "ECHO %logfile%" instead of using the correct "TYPE %logfile%" syntax. It just grew out of my initial error.
Sorry about that.
pb