Virtual Dennis

Custom NetBackup Daily Report Script for Unix/Linux

Manuals & How-To's NetBackup

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 “crond” or some other scheduler). 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-Backup-Status-Report” Script

#!/bin/bash  
#########################################################################  
#  
# Script to generate a Daily Backup Status Report  
# Original Creation Date by David A. Chapa: 11/19/97  
# Modification by Dennis L. & Roger Y.: 12/02/97  
# 1/2010 & 9/2010 Major Update & Modification by Dennis Laube, http://3.135.210.113  
#  
# This script generates a status report with the following info:  
# -Status of all client backups within the specified timeframe  
# -Per Policy Data amount for the last 7 days  
# -Per Policy Data amount for the last 24 hours  
# -Tape Library Status including number of tapes inside & outside the library  
# -Mails the complete report to the "someone_who_cares" variable.  
#  
# Requires this script as well as "amountprclass", "amountprclass24" and # "tapestat" to be placed under the "WORKINGDIR" location.  
#  
# When running this script manually, you will see multiple "no entity found" messages. This is normal.  
#  
#########################################################################  
#  
#Change this value to email a group or individual  
someone_who_cares=backupadmin@mycompany.com  
COMPANY="My Company"

#Change this value to search further back into the error reports  
HOURSAGO=18

#Specify the location of the required scripts, including this one  
WORKINGDIR=/root/netbackup_scripts

#The remaining stuff below shouldn't need to be edited  
COUNT=0  
OUTPUT=/tmp/unixstats1  
OUTPUT1=/tmp/goodunix  
ADMCMD=/usr/openv/netbackup/bin/admincmd  
FORM1=" Successful Backup Jobs"  
FORM2=" *************************************************"  
FORM7=" Code"  
FORM3="Status Client Policy SCHED Server Time "  
FORM4="==============================================================================="  
FORM5=" Detailed Error Report"  
FORM6="_______________________________________________________________________________"  
#  
# Get rid of any old output files if they are there.

if [ -s $OUTPUT ]  
then  
rm $OUTPUT  
fi  
if [ -s $OUTPUT1 ]  
then  
rm $OUTPUT1  
fi

# Format Report with Title, etc.  
echo "`date +%m/%d/%y` `date +%H:%M`" > $OUTPUT echo "Netbackup Reporting automagically on the last "$HOURSAGO" hours for all backups. Please do not reply to this email. Thanks! "Ran at: `date +%m/%d/%Y`" ("`date +%H:%M`")" > $OUTPUT echo >> $OUTPUT echo "$FORM6" >> $OUTPUT echo >> $OUTPUT echo "$FORM1" >> $OUTPUT echo "$FORM2" >> $OUTPUT echo "" >> $OUTPUT echo "$FORM4" >>$OUTPUT echo "$FORM3" >> $OUTPUT echo "$FORM7" >> $OUTPUT echo "$FORM4" >>$OUTPUT echo >> $OUTPUT

# Begin Main Script  
for i in `$ADMCMD/bpplclients | grep -v "Hardware" | (tee) | cut -c35-68` do  
    $ADMCMD/bperror -U -backstat -hoursago $HOURSAGO -client $i | fgrep " 0 ">> $OUTPUT  
    $ADMCMD/bperror -U -backstat -hoursago $HOURSAGO -client $i | fgrep " 0 " | cut -c8-20 >> $OUTPUT1  
    $ADMCMD/bperror -U -backstat -hoursago $HOURSAGO -client $i | fgrep " 1 ">> $OUTPUT  
    $ADMCMD/bperror -U -backstat -hoursago $HOURSAGO -client $i | fgrep " 1 " | cut -c8-20 >> $OUTPUT1 done #  
# Looking for Backups with Status code 1 too because those are  
# partially successful and a backup image was created for them  
############################################################################  
############################################################################  
# Now that the successful backups were reported,  
# its time to log the errors  
echo >> $OUTPUT  
echo >> $OUTPUT  
echo >> $OUTPUT  
echo >> $OUTPUT  
echo "$FORM5" >> $OUTPUT  
echo "$FORM6" >> $OUTPUT  
echo >> $OUTPUT

for i in `$ADMCMD/bpplclients | grep -v "Hardware" | (tee) | cut -c35-68` do  
    fgrep "$i" "$OUTPUT1" > /dev/null 2>&1  
    if [ $? = 0 ]  
    then  
        continue  
    fi

    $ADMCMD/bperror -U -backstat -hoursago $HOURSAGO -client $i | egrep -v STATUS | egrep -v " 0 " > /dev/null  
    if [ $? = 0 ]  
    then  
        echo >> $OUTPUT  
        echo >> $OUTPUT  
        echo "Error Log Report for Client $i" >> $OUTPUT  
        echo >> $OUTPUT  
        echo >> $OUTPUT  
        $ADMCMD/bperror -U -backstat -hoursago $HOURSAGO -client $i | egrep -v STATUS | egrep -v " 0 " >> $OUTPUT  
        echo $FORM6 >> $OUTPUT  
        $ADMCMD/bperror -U -problems -hoursago $HOURSAGO -client $i >> $OUTPUT  
        echo >> $OUTPUT  
        echo $FORM4 >> $OUTPUT  
        echo >> $OUTPUT  
        COUNT=`echo "$COUNT+1" | bc`  
    fi  
done

# Run "amountprclass24" script and insert into report  
echo "Amount of Data Backed Up for the last 24 hours" >> $OUTPUT  
$WORKINGDIR/amountprclass24 >> $OUTPUT  
echo >> $OUTPUT  
echo >> $OUTPUT

# Run "amountprclass" script and insert into report  
echo "Amount of Data Backed Up for the last 7 days" >> $OUTPUT $WORKINGDIR/amountprclass >> $OUTPUT echo >> $OUTPUT echo >> $OUTPUT

# Run "tapestat" script to show number of tapes in each pool and if either onsite/offsite  
echo "Tape Status & Location" >> $OUTPUT $WORKINGDIR/tapestat >> $OUTPUT echo >> $OUTPUT echo >> $OUTPUT

# Now we can e-mail it to the right person  
today=`date +%m/%d/%y`  
#  
# Uncomment if you want this to be sent to someone_who_cares  
cat $OUTPUT | mail -s "$COMPANY Morning Backup Report ( $today $COUNT bad )" $someone_who_cares

 

“amountprclass” Script

#!/bin/ksh  
#  
################################################################################  
# This script will list the amount of data that was backed up in the last 7 days  
# listed per policy.  
#  
# Updates 2010 by Dennis Laube, http://3.135.210.113  
################################################################################  
#  
# Variables  
BPPATH=/usr/openv/netbackup/bin/admincmd  
DBPATH=/usr/openv/netbackup/db  
sumtotkb=0

# list classes  
$BPPATH/bppllist |  
while read class  
do

# calculating sum of the kilobytes  
sumkb=0  
$BPPATH/bpimagelist -A -L -class $class -hoursago 168 2>/dev/null | grep "^Kilobytes" |  
while read txt kb  
do  
let sumkb=${sumkb}+${kb}  
done # calculating sum of kilobytes

# Make the output more human readable  
outtxt="$sumkb kb"  
echo "$sumkb/1024" | bc -l | read sumMB  
if [ $sumMB -gt 0 ]; then  
printf "%7.2f %s" $sumMB "MB" | read outtxt  
fi  
echo "$sumMB/1024" | bc -l | read sumGB  
if [ $sumGB -gt 0 ]; then  
printf "%7.2f %s" $sumGB "GB" | read outtxt  
fi  
printf "%-40s %6s %2s\n" $class $outtxt  
let sumtotkb=${sumtotkb}+${sumkb}  
done # reading classes  
outtxt="$sumtotkb kb"  
echo "$sumtotkb/1024" | bc -l | read sumMB  
if [ $sumMB -gt 0 ]; then  
printf "%7.2f %s" $sumMB "MB" | read outtxt  
fi  
echo "$sumMB/1024" | bc -l | read sumGB  
if [ $sumGB -gt 0 ]; then  
printf "%7.2f %s" $sumGB "GB" | read outtxt  
fi  
echo "$sumGB/1024" | bc -l | read sumTB  
if [ $sumTB -gt 0 ]; then  
printf "%7.2f %s" $sumTB "TB" | read outtxt  
fi  
# Print results  
printf "%-45s %6s %2s\n" "Total Amount" $outtxt

 

“amountprclass24” Script

#!/bin/ksh  
#  
################################################################################  
# This script will list the amount of data that was backed up in the last 24 hrs  
# listed per policy.  
#  
# Various Updates 2010 by Dennis Laube, http://3.135.210.113  
################################################################################  
#  
# Variables  
BPPATH=/usr/openv/netbackup/bin/admincmd  
DBPATH=/usr/openv/netbackup/db  
sumtotkb=0

# list classes  
$BPPATH/bppllist |  
while read class  
do

# calculating sum of the kilobytes  
sumkb=0  
$BPPATH/bpimagelist -A -L -class $class -hoursago 24 2>/dev/null | grep "^Kilobytes" |  
while read txt kb  
do  
let sumkb=${sumkb}+${kb}  
done # calculating sum of kilobytes

# Make the output more human readable  
outtxt="$sumkb kb"  
echo "$sumkb/1024" | bc -l | read sumMB  
if [ $sumMB -gt 0 ]; then  
printf "%7.2f %s" $sumMB "MB" | read outtxt  
fi  
echo "$sumMB/1024" | bc -l | read sumGB  
if [ $sumGB -gt 0 ]; then  
printf "%7.2f %s" $sumGB "GB" | read outtxt  
fi  
printf "%-40s %6s %2s\n" $class $outtxt  
let sumtotkb=${sumtotkb}+${sumkb}  
done # reading classes  
outtxt="$sumtotkb kb"  
echo "$sumtotkb/1024" | bc -l | read sumMB  
if [ $sumMB -gt 0 ]; then  
printf "%7.2f %s" $sumMB "MB" | read outtxt  
fi  
echo "$sumMB/1024" | bc -l | read sumGB  
if [ $sumGB -gt 0 ]; then  
printf "%7.2f %s" $sumGB "GB" | read outtxt  
fi  
echo "$sumGB/1024" | bc -l | read sumTB  
if [ $sumTB -gt 0 ]; then  
printf "%7.2f %s" $sumTB "TB" | read outtxt  
fi  
# Print results  
printf "%-45s %6s %2s\n" "Total Amount" $outtxt

 

“tapestat” Script

#!/usr/bin/ksh  
#  
# This script shows the current tape status by pool. It will show how many tapes are in the  
# robot versus how many tapes are outside the robot as well as the overall total of tapes  
# per pool.  
# Written by Dennis Laube, http://3.135.210.113 with initial help from Roger Yarrow.  
# 1/10 - Updates to script performed, testing with NBU 6.5  
# 10/10 - Updates for RedHat, Testing with NBU 7  
#  
#  
# Variables  
#  
#Change the below variables to reflect the hostnames of your Master and Media Servers  
MASTER=netbackup1.mycompany.com  
MEDIA=NBU-media2.mycompany.com  
VMQUERY=/tmp/vmquery.$$.out  
VMPOOL=/tmp/vmpool.$$.out  
VMHOST=`/usr/openv/volmgr/bin/tpconfig -d | grep "robot control host" | sed 's/^.*host = //'`  
RTYPE=TLD  
VOLMGR=/usr/openv/volmgr/bin

# Its sloppy but it works!, Leave commented out  
#DL RTYPE=`/usr/openv/volmgr/bin/tpconfig -d | tail -2 | sed 's/(0).*$//' | awk '{print $1}' | head -n 1`  
#typeset -l rt=$RTYPE

/bin/rm -f $VMQUERY $VMPOOL

# List out formating for data  
echo "Poolname\t\t outside \t inside \t total"  
echo " \t\t robot \t robot \t number"  
echo "---------------------------------------------------------------"  
$VOLMGR/vmcheckxxx -h $MASTER -list -rt $RTYPE -rn 0 -rh $MEDIA > /tmp/inrobot  
$VOLMGR/vmpool -h $MASTER -listall -b | tail | sort > $VMPOOL  
cat $VMPOOL |  
while read POOLNAME line  
do  
if [ "$POOLNAME" = "DONTUSE" ]; then  
continue  
fi

#DL $VOLMGR/vmquery -h $MASTER -pn $POOLNAME -b | tail +4 > $VMQUERY  
$VOLMGR/vmquery -h $MASTER -pn $POOLNAME -b > $VMQUERY  
POOLNAME=`echo "$POOLNAME " | cut -c -20`  
ntapestot=`cat $VMQUERY | wc -l`  
echo $ntapestot | read tal1  
let sumtot=${sumtot}+${tal1}  
ntapesin=`cat $VMQUERY | grep $RTYPE | wc -l`  
echo $ntapesin | read tal1  
let sumin=${sumin}+${tal1}  
ntapesin=${tal1}  
ntapesout=`cat $VMQUERY | grep NONE | wc -l`  
echo $ntapesout | read tal1  
let sumout=${sumout}+${tal1}  
ntapesout=${tal1}  
inrobot=0  
cat $VMQUERY | grep NONE |  
while read mediaid line  
do  
INROBOT=`grep $mediaid /tmp/inrobot`  
if [ -n "$INROBOT" ]; then  
let inrobot=${inrobot}+1  
fi  
done

let ntapesout=${ntapesout}-${inrobot}  
let ntapesin=${ntapesin}+${inrobot}  
let sumout=${sumout}-${inrobot}  
let sumin=${sumin}+${inrobot}  
tapesin=`echo "${ntapesin}"`  
#printf "%20s%10d%16d%16d\n" "$POOLNAME" ${ntapesout} ${ntapesin} ${ntapestot}  
DISYES=`echo $POOLNAME | grep -i disaster`  
if [ -n "$DISYES" ]; then  
POOLNAME=`echo "$POOLNAME(scratch) " | cut -c -20`  
count=0  
cat $VMQUERY |  
while read mediaid mediatype robottype robotnum robotslot side op vol mnts lmntdate lmnttime asgndate asgntime pool  
do  
if [ "${asgndate}" = "---" -a "${asgntime}" = "---" -a "${robottype}" != "NONE" ]; then  
let count=${count}+1  
fi  
done  
tapesin=`echo "${ntapesin}($count)"`  
fi  
printf "%20s%10d%16s%16d\n" "$POOLNAME" ${ntapesout} $tapesin ${ntapestot}  
done  
echo "---------------------------------------------------------------"  
printf "%20s%8d%16d%16d\n" "Total number of tapes:" $sumout $sumin $sumtot  
echo "==============================================================="

#Clean up after ourselves  
/bin/rm -f $VMQUERY $VMPOOL
#netbackup scripts