Netbackup Scripts – client-last-backup

Quick report on the last backup for a client of your choice..

(Your mileage may vary with this one… I made some assumptions along the way that reflect my environment… But you can always use it as a starting point for your own version…)

#!/bin/ksh

[ $# != 1 ] &&
    echo "Usage: $0 {CLIENT_NAME}" &&
    exit 99

CLIENT=$1
/usr/openv/netbackup/bin/admincmd/bpplclients
    -allunique -noheader | awk '{print $NF}' |
    grep ${CLIENT} > /dev/null
[ $? -ne 0 ] &&
    echo "Error: ${CLIENT} is not a valid client." &&
    exit 99

TMP_FILE=/tmp/`basename $0`.${PPID}
bperror -client ${CLIENT} > ${TMP_FILE}

JOBID=`grep "nbjm started backup job" ${TMP_FILE} |
    egrep -v "oracle|catalog|DSSU" |tail -1 |awk '{print $7}'`

TYPE=`grep ${JOBID} ${TMP_FILE} |
    grep "nbjm started backup job" |
    tail -1 | awk '{print $20}'`

START=`grep ${JOBID} ${TMP_FILE} |head -1 |awk '{print $1}'`
START_PRETTY=`bpdbm -ctime ${START} |cut -c18-`

FINISH=`grep ${JOBID} ${TMP_FILE} |tail -1 |awk '{print $1}'`
FINISH_PRETTY=`bpdbm -ctime ${FINISH} |cut -c18-`

JOB_COUNT=`grep ${JOBID} ${TMP_FILE} |
    grep "successfully wrote backup" |
    wc -l | sed 's/ //g'`

TOTAL_SIZE=0
for SIZE in `grep ${JOBID} ${TMP_FILE} |
    grep "bptm successfully wrote backup" |
    awk '{print $20}' `
do
    TOTAL_SIZE=$((${SIZE}+${TOTAL_SIZE}))
done

SIZE_UNIT="KB"
if [ ${TOTAL_SIZE} -ge 10000 ];
then
    TOTAL_SIZE=$((${TOTAL_SIZE}/1024))
    SIZE_UNIT="MB"
fi

if [ ${TOTAL_SIZE} -ge 10000 ];
then
    TOTAL_SIZE=$((${TOTAL_SIZE}/1024))
    SIZE_UNIT="GB"
fi

echo " Client: ${CLIENT} "
echo " Start: ${START_PRETTY}"
echo " Finish: ${FINISH_PRETTY}"
echo " Backup Type: ${TYPE}"
echo " Backup Size: ${TOTAL_SIZE} ${SIZE_UNIT}"
echo " Job Count: ${JOB_COUNT}"
echo " File Systems/Volumes:"
for FILE_SYSTEM in `grep ${JOBID} ${TMP_FILE} |
    grep "handling path" |
    sed 's/Shadow Copy Components/Shadow_Copy_Components/' |
    grep -v "SNAP_ID" | awk '{print $NF}' | sort `
do
    echo ${FILE_SYSTEM} | grep MNTPOINT > /dev/null
    if [ $? -eq 0 ]; then
        FILE_SYSTEM=`echo ${FILE_SYSTEM} |
            awk -F"=" '{print $3}' |
            awk -F"," '{print $1}'`
    fi
    echo "    ${FILE_SYSTEM}"
done

rm -f ${TMP_FILE}

exit 0

And the output…

Client: xxxxx
 Start: Aug 30 18:01:21 2012
 Finish: Aug 30 18:07:41 2012
 Backup Type: Incremental_Backup
 Backup Size: 1380 MB
 Job Count: 5
 File Systems/Volumes:
    /
    /boot
    /home
    /usr
    /var