Custom NetBackup Daily Report Script for Windows
I have created/modified some NetBackup scripts to be used for a Daily Status Report, which can be emailed to the NetBackup administrator every morning or whenever convenient (automatically running the script would need to be done through “Scheduled Tasks”). The below scripts will need to be copied exactly as text files to the same directory on the NetBackup Master server. Also, please name the scripts exactly what is in quotations, as other scripts may refer to that script by name.
“daily_err_report.cmd” Script
@echo off
:: daily_err_report v1r1 Ed Gurski 07/10/02
:: Fixed bugs and Latest Updates, Converted by Dennis Laube, http://3.135.210.113, 11/09
:: Added additional features and updates - Dennis Laube 1/10
::
:: *******************************************************************************************
:: * * * * * * * *
:: * * * * The purpose of this command is to report all errors that occured on * * * *
:: * * * * the previous evening's backup. This script will eliminate all successful * * * *
:: * * * * and partially successful backups. This command can be ran from a sched * * * *
:: * * * * task. A log (S<DATE>) of the output can be viewed in the directory * * * *
:: * * * * C:\netbackup_scripts * * * *
:: * * * * * * * *
:: *******************************************************************************************
::
::
:: *******************************************************************************************
:: * * * * * * * *
:: * * * * We will now set the system variables for the usage of the commands. * * * *
:: * * * * The initial settings for these variables will be set to their defaults * * * *
:: * * * * but can be changed during the command call... * * * *
:: * * * * All variables do not need to be reset since they are set as LOCAL to * * * *
:: * * * * command itself... * * * *
:: * * * * * * * *
:: *******************************************************************************************
::
:R0000_Set
SETLOCAL ENABLEEXTENSIONS
set CONAME=My Company
set NBDIR=C:\progra~1\VERITAS\Netbackup\bin\admincmd
set BPDIR=C:\netbackup_scripts
set BPERROUT=%BPDIR%\stat.out
set BPTEMP=%BPDIR%\tmp.out
set BPWORK=%BPDIR%\dir.out
set NOERROR=%BPDIR%\noerr
set MSGHDR=%BPDIR%\hdr
set SPACING=%BPDIR%\spacing
:: You can additional email addresses separated by commas
set OPER1=netbackupadmin@mycompany.com
set OPER2=anotherperson@mycompany.com
SET Get_Date_Cmd=C:\netbackup_scripts\getdate.cmd
set HOURS=14
set Mail_Priority=0
:: *******************************************************************************************
::
:: We will now get the system date and from this will be be able to define the name of our
:: log file and email subject. The log file name has the format of Smmddyy.log..
::
:: *******************************************************************************************
:R0010_Set
cd %BPDIR%
Call %Get_Date_Cmd% %BPDIR%
set Err_Log=%BPDIR%\LOGS\S%Today%.log
set MAIL_SUBJECT=%CONAME% Daily Backup Error Report %Today%
:: *******************************************************************************************
:: * * * * * * * *
:: * * * * We will now check to see if any errors occurred in last night's * * * *
:: * * * * backups... * * * *
:: * * * * * * * *
:: *******************************************************************************************
:R0100_Error_Report
%NBDIR%\bperror -backstat -l -U -hoursago %HOURS% >%BPERROUT%
:: *******************************************************************************************
:: * * * * * * * *
:: * * * * We will now extract the header line for later use and eliminate all * * * *
:: * * * * successful and partially successful backups from the report. Then * * * *
:: * * * * we will eliminate all status codes of 0 and 1 from the report... * * * *
:: * * * * * * * *
:: *******************************************************************************************
:R0200_Hdr_Errors
findstr /v "STATUS partially" %BPERROUT%|findstr /vc:" 0 "|findstr /vc:" 1 " >%BPTEMP%
cat %BPTEMP%|findstr /v /b /c:" " >%BPWORK%
:: *******************************************************************************************
::
:: We will now check to see if any errors occurred and a message will be built with all the
:: errors that occurred.
::
:: *******************************************************************************************
:R0320_Errors
copy %MSGHDR% + %BPTEMP% %Err_Log%
:: *******************************************************************************************
::
:: The purpose of this section is to gather an overrall summary of jobs and list those in the
:: report that gets emailed. This summary shows how many jobs completed, failed and are active.
::
:: *******************************************************************************************
:R0350_Summary
type %SPACING% >>%Err_Log%
%NBDIR%\bpdbjobs -summary -L >>%Err_Log%
set Mail_Priority=1
pushd %BPDIR%
touch S%Today%.log
popd
:: *******************************************************************************************
::
:: Now we'll email this file using the blat utility to the specified operators.
::
:: *******************************************************************************************
:R0375_Mail
blat %Err_Log% -subject "%MAIL_SUBJECT%" -to %OPER1% -cc %OPER2% -priority %Mail_Priority%
:: If you want to only send the email to 1 person, comment out the above command and uncomment out the below
:: blat %Err_Log% -subject "%MAIL_SUBJECT%" -to %OPER1% -priority %Mail_Priority%
:: *******************************************************************************************
::
:: We will delete all work files used in this script...
::
:: *******************************************************************************************
:R9900_Clean_Up
del %BPDIR%\*.out
:EndMain
endlocal
“daily_success_report.cmd” Script
@echo off
::
:: daily_success_report v1r1 Orig by Ed Gurski 07/10/02
:: Fixed bugs and Latest Updates, Converted by Dennis Laube, http://3.135.210.113, 11/09
:: Added additional features and updates – Dennis Laube 1/10
::
:: *******************************************************************************************
:: The purpose of this script is to report on all successful backups that have ran during the
:: the past nights backup.
::
:: *******************************************************************************************
::
::
:: *******************************************************************************************
::
:: We will now set the system variables for the usage of the commands.
:: The initial settings for these variables will be set to their defaults
:: but can be changed during the command call…
:: All variables do not need to be reset since they are set as LOCAL to
:: command itself…
::
:: *******************************************************************************************
::
:R0000_Set
SETLOCAL ENABLEEXTENSIONS
set CONAME=My Company
set NBDIR=C:\progra~1\VERITAS\Netbackup\bin\admincmd
set BPDIR=C:\netbackup_scripts
set BPERROUT=%BPDIR%\stat.txt
set BPGOOD=%BPDIR%\good.txt
set BPWORK=%BPDIR%\dir.txt
set NOERROR=%BPDIR%\noerr
set MSGHDR=%BPDIR%\hdr
set SPACING=%BPDIR%\spacing
:: You can additional email addresses separated by commas
set OPER1=netbackupadmin@mycompany.com
set OPER2=someoneelse@mycompany.com
SET Get_Date_Cmd=C:\netbackup_scripts\getdate.cmd
set HOURS=14
set Mail_Priority=0
:: *******************************************************************************************
::
:: We will now get the system date and from this will be be able to define the name of our
:: log file and email subject. The log file name has the format of Gmmddyy.log..
::
:: *******************************************************************************************
:R0010_Set
cd %BPDIR%
Call %Get_Date_Cmd% %BPDIR%
set Good_Report=%BPDIR%\LOGS\G%Today%.log
set MAIL_SUBJECT=%CONAME% Daily Backup Success Report %Today%
:: *******************************************************************************************
:: * * * * * * * *
:: * * * * We will now check to see if any errors occurred in last night’s * * * *
:: * * * * backups… * * * *
:: * * * * * * * *
:: *******************************************************************************************
:R0100_Error_Report
%NBDIR%\bperror -backstat -l -U -hoursago %HOURS% >%BPERROUT%
:: *******************************************************************************************
::
:: We will now extract the header line for later use and eliminate all errored backups from
:: the report and only keep successful and partially successful backups.
::
:: *******************************************************************************************
:R0200_Hdr_Errors
findstr /c:” 0 ” %BPERROUT% >>%BPGOOD%
findstr /c:” 1 ” %BPERROUT% >>%BPGOOD%
:: *******************************************************************************************
::
:: We will now copy the header back into the report and take the successful and partial backups
:: and put them into a single file that will be emailed. Then we’ll also write this file to a
:: log file for later use.
::
:: *******************************************************************************************
:R0320_Good
copy %MSGHDR% + %BPGOOD% %Good_Report%
:: *******************************************************************************************
::
:: The purpose of this section is to gather an overrall summary of jobs and list those in the
:: report that gets emailed. This summary shows how many jobs completed, failed and are active.
::
:: *******************************************************************************************
:R0350_Summary
type %SPACING% >>%Good_Report%
%NBDIR%\bpdbjobs -summary -L >>%Good_Report%
set Mail_Priority=1
pushd %BPDIR%
touch G%Today%.log
popd
:: *******************************************************************************************
::
:: Now we’ll email this file using the blat utility to the specified operators.
::
:: *******************************************************************************************
:R0375_Mail
blat %Good_Report% -subject “%MAIL_SUBJECT%” -to %OPER1% -cc %OPER2% -priority %Mail_Priority%
:: blat %Good_Report% -subject “%MAIL_SUBJECT%” -to %OPER1% -priority %Mail_Priority%
:: *******************************************************************************************
::
:: We will delete all work files used in this script…
::
:: *******************************************************************************************
:R9900_Clean_Up
del %BPDIR%\*.txt
:EndMain
endlocal
“getdate.cmd” Script
@echo off
::
:: EBS_GETDATE v1r0 Ed Gurski 05/29/02
:: Updates by Dennis Laube, http://3.135.210.113, 11/09
::
:: *******************************************************************************************
:: * * * * * * * *
:: * * * * The purpose of this command is to obtain the date and time that will * * * *
:: * * * * be used by all commands in the EBS to suffix their log files… * * * *
:: * * * * Additionally, this command will also obtain variables for day month and * * * *
:: * * * * whcih can be used by any of the calling commands… * * * *
:: * * * * This is a called script and it will ensure that it is being * * * *
:: * * * * called with the appropriate parameters… * * * *
:: * * * * * * * *
:: *******************************************************************************************
::
::
:: *******************************************************************************************
:: * * * * * * * *
:: * * * * We will now set the system variables for the usage of the commands. * * * *
:: * * * * The initial settings for these variables will be set to their defaults * * * *
:: * * * * but can be changed during the command call… * * * *
:: * * * * All varaiables do not need to be reset since they are set as LOCAL to * * * *
:: * * * * command itself… * * * *
:: * * * * * * * *
:: *******************************************************************************************
::
:R0000_Set
if %1d==d goto R0110_Not_Called
goto R0099_Set
:R0110_Not_Called
echo ******* GETDATE cannot be started from a command line ********
goto R9999
:R0099_Set
SET GETDATE_DIR=%1
SET GETDATE=%GETDATE_DIR%\date.txt
::
:: *******************************************************************************************
:: * * * * * * * *
:: * * * * The purpose of this routine is to obtain the current date and day of * * * *
:: * * * * week from the system. The format of the date is “ddd mm/dd/yyyy”… * * * *
:: * * * * We will also set the global variables DOW (Day of Week), YEAR, * * * *
:: * * * * MONTH and DAY. We will also set the DATESTAMP and TODAY global variables * * * *
:: * * * * that are used for producing all log messages… * * * *
:: * * * * * * * *
:: *******************************************************************************************
::
:R0100_GetDate
date /t >>%GETDATE%
for /F “tokens=1” %%i in (%GETDATE%) do set DOW=%%i
for /F “tokens=2 delims=/ ” %%i in (%GETDATE%) do set Month=%%i
for /F “tokens=3 delims=/ ” %%i in (%GETDATE%) do set Day=%%i
for /F “tokens=4 delims=/ ” %%i in (%GETDATE%) do set Year=%%i
del %GETDATE%
set Today=%Year%%Month%%Day%
set Datestamp=%DOW% %Month%/%Day%/%Year%
::
:: *******************************************************************************************
:: * * * * * * * *
:: * * * * The purpose of this routine is to obtain the current time of day * * * *
:: * * * * and then convert it to an HOUR and MINUTE variable… * * * *
:: * * * * We will need to ensure a zero-fill on the hour, so a check will be * * * *
:: * * * * be made to determine if we are a single digit hour and change it * * * *
:: * * * * accordingly… * * * *
:: * * * * * * * *
:: *******************************************************************************************
::
:R0200_GetTime
echo %TIME%>%GETDATE%
for /f “tokens=1 delims=:” %%i in (%GETDATE%) do set HOUR=%%i
if %HOUR% == 0 set HOUR=00
if %HOUR% == 1 set HOUR=01
if %HOUR% == 2 set HOUR=02
if %HOUR% == 3 set HOUR=03
if %HOUR% == 4 set HOUR=04
if %HOUR% == 5 set HOUR=05
if %HOUR% == 6 set HOUR=06
if %HOUR% == 7 set HOUR=07
if %HOUR% == 8 set HOUR=08
if %HOUR% == 9 set HOUR=09
for /f “tokens=2 delims=:” %%i in (%GETDATE%) do set MINUTE=%%i
del %GETDATE%
::
:: ********************************************************************************************
:: * * * * * * * *
:: * * * * The duplication process has now been completed and we will reset all * * * *
:: * * * * the variables used in this script and return control to the system… * * * *
:: * * * * * * * *
:: ********************************************************************************************
::
:R9900
:R9999
:EndMain
endlocal
“hdr” File
Netbackup Reporting automagically on the last 14 hours for all backups. Please do not reply
to this email. Thanks!
***************************************************************************
STATUS CLIENT POLICY SCHED SERVER TIME COMPLETED
—————————————————————————
“spacing” File
***************************************************************************
6 Comments
Hi,
Great scripts and just what I needed to automate this task…only had one problem. On our installation of Netbackup v7.1 on a Windows 2003 server the “cat” command doesn’t work. My assumption is this is a concatenation of files, so I replaced the cat command with copy and the script worked great after that.
Hi Fernando, thanks for the reply. Yes, the copy command should work. I forget if I installed something like Cygwin (http://www.cygwin.com/) onto the server so that cat and the like would work..
Just to add on few things which might be useful in this windows based script. Create an html file using following commands if required.
REM ============= HTML Report Format ============
echo “” > %BPHTMLRPT%
echo “” >> %BPHTMLRPT%
echo “Daily Report” >> %BPHTMLRPT%
echo “Example Server Name” >> %BPHTMLRPT%
echo “——————————————–” >> %BPHTMLRPT%
echo “Backup Status Failed backups Successful Backups” >> %BPHTMLRPT%
echo “” >> %BPHTMLRPT%
echo “Backup All Log Status for 24 Hrs” >> %BPHTMLRPT%
echo “——————————————–” >> %BPHTMLRPT%
type %TOTALFailS% >> %BPHTMLRPT%
REM echo >> %BPHTMLRPT%
type %TOTALSUCCS% >> %BPHTMLRPT%
type %TOTALJOBS% >> %BPHTMLRPT%
echo “” >> %BPHTMLRPT%
echo “Failed Backups” >> %BPHTMLRPT%
echo “——————————————–” >> %BPHTMLRPT%
type %BPTEMP% >> %BPHTMLRPT%
echo “” >> %BPHTMLRPT%
echo “Successful Backups” >> %BPHTMLRPT%
echo “——————————————–” >> %BPHTMLRPT%
type %BPSECSS% >> %BPHTMLRPT%
echo “” >> %BPHTMLRPT%
REM echo Backup All Log Status for 24 Hrs >> %BPHTMLRPT%
REM echo “——————————————–” >> %BPHTMLRPT%
REM type %BPERROUT% >> %BPHTMLRPT%
echo “” >> %BPHTMLRPT%
Thanks!
I used this following script to count the lines of failures/success and accumulate it to overall HTML report.
May be you could utilize it for summarized view of the jobs.
Example:
Const ForReading = 1
Set objFSO = CreateObject(“Scripting.FileSystemObject”)
Set objTextFile = objFSO.OpenTextFile _
(“e:\VERITAS\Report\failures.txt”, ForReading)
objTextFile.ReadAll
Wscript.Echo “Number of Fails: ” & objTextFile.Line
Thanks!!