Most organizations are tryng to move out from NTbackup for better managed backup software solutions. However, the legacy software applications and the cost involved in implementing a managed backup solution have forced the organizations to use ntbackups.
One of the biggest challenges faced in automating ntbackup is the error reporting functionality. By default, ntbackup does not support error handling. In otherwords, it cannot execute set of instructions upon error. Therefore, a workaround is necessary to overcome the situation. I was thinking all possible solutions and felt the following as the best suitable solution,
Read the backup log file and count the number of "Backup completed" text. "Backup completed" is written to the logfile for each folder/drive backup item it backups. Therefore, if the count is not equal to the number of folder/drive backup items you could come to a conclusion that there is some issue with the backup.
Following is a sample backup script used for the automation,
echo %date% %time%
echo Initiate backup job
C:\WINDOWS\system32\ntbackup.exe backup "@C:\SCRIPTS\DAILY.bks" /t "Friday_File_SVR_BKP" /n "Friday_File_SVR_BKP" /d "Friday_File_SVR_BKP" /v:no /r:no /rs:no /hc:on /SNAP:off /m normal /j "Friday_File_SVR_BKP" /l:s
echo Copy last backup job log to a seperate folder for the emailing purpose.
set srcDir=C:\Documents and Settings\itops\Local Settings\Application Data\Microsoft\Windows NT\NTBackup\data\
for /f "tokens=*" %%a in ('dir /b /od 2^>NUL') do set lastmod=%%a
if "%lastmod%"=="" echo Could not locate files.&goto :eof
copy "%lastmod%" "%destDir%"\backup.log
echo if the backup job is unsuccessful send the log via email (7 is the count of backup items)
for /f "tokens=3" %%f in ('find /c /i "Backup completed" "C:\Scripts\backup.log"') do set isComplete=%%f
if %isComplete% LSS 7 C:\Scripts\sendEmail.exe -f <from email> -t <to email> -s 192.168.1.2:25 -u <email subject withing quotes> -m <email body withing quotes> -a "C:\Scripts\backup.log"
echo %date% %time%
Hope the article will help you to save your valuable time spent going through the logs to ensure the backup is successful !!! Cheers!!!