Video Screencast Help
Symantec Appoints Michael A. Brown CEO. Learn more.

Useful scripts for netbackup 7.5

Created: 19 Dec 2012 | 3 comments

I would like to share scripts and help if anyone wants a script via this forum which could be continuing if interested. :)

The following scripts still need to be improved. Open to any feedback.

#script name : bk_size.sh

#usage : bk_size.sh ( no argument )

#            It shows total backup size by policy or by client or by date 

LOGFILE=/log/bk_size.log

bpcatlist -policy POLICY_NAME > $LOGFILE
#bpcatlist -since Dec 6 2012 -client CLIENT_NAME | grep Full > $LOGFILE
#bpcatlist -since Dec 19 18:00:00 2012 > $LOGFILE
cat $LOGFILE | egrep '[0-9][k |M |G |T ]' | awk '{print $7}' | awk '{if ( $1 ~ /T$/ ) Total+=substr($1,1,length($1)-1)*1000000; else if ( $1 ~/G$/ ) Total+=substr($1,1,length($1)-1)*1000; else if ( $1 ~/k$/ ) Total+=substr($1,1,length($1)-1)/1000;  else Total+=substr($1,1,length($1)-1) } END { print Total/1024 "GB"}'

#script name : rm_bk.sh

#usage : rm_bk.sh client_name

#            It will delete all backups of a client

echo "########################################"
echo "The following backupids will be removed"
echo "########################################"
echo "--------------------------------- $1 ---------------------------------------------"
bpcatlist -client $1
echo "----------------------------------------------------------------------------------"
for Backup_id in `bpcatlist -client $1 | grep $1  | awk '{print $1}'`
do
        bpimage -deletecopy 1 -backupid $Backup_id && echo "$Backup_id deleted";
done
 

#script name : all_info.sh

#usage : all_info.sh ( no argument )

#             It generates logfiles which have backup time and backup size for each client and extract unix servers from all info

V_Date=`date +%Y-%m-%d`

UNIX_SVR=unix.svr
LOGFILE1=/log/KB_TIME.$V_Date
LOGFILE2=/log/all.svr.$V_Date
LOGFILE3=/log/all_info.$V_Date
LOGFILE4=/log/unix.$V_Date
LOGFILE5=/log/all_info_sh.$V_Date

bpimagelist -hoursago 24 -U -A | egrep '^Client:' | sort -u +1 | awk '{print $2}' > $LOGFILE2
bpimagelist -hoursago 24 -U -A | egrep '^Client:|^Policy:|^Kilobytes|^Backup Time|^Elapsed|^Number of Files' > $LOGFILE3
echo "Client                            GB"  > $LOGFILE5
echo "============================================="  >> $LOGFILE5
cat $LOGFILE3 | awk '/^Client:/{print $2} /^Kilo/{print $2/1024000} /^Elapsed/{print $3} /^Backup Time/{print $3 " " $4} /^Number of Files/{print $4}' | paste - - - - - | sort -n +4 > $LOGFILE1
cat $LOGFILE1 | awk '{ V_CLT[$1]++; V_CLT[$1]+=$5; } END { for ( i in V_CLT ) print i, "\t\t\t",V_CLT[i]}' | sort -n +1  >> $LOGFILE5
echo "============================================"  >> $LOGFILE5
cat $LOGFILE3 | grep ^Kilo | awk '{ V_K+=$2 } END { print "Total Size : " V_K/1024/1024 " GB" }'  >> $LOGFILE5
for Vunix in `cat $UNIX_SVR`; do grep $Vunix $LOGFILE1 >> $LOGFILE4 ; done

Hope you get useful things from them.

Happy to help you make any script you want.

 

Cheers,

Discussion Filed Under:

Comments 3 CommentsJump to latest comment

RamNagalla's picture

hi Joseph,

Thanks for sharing.. 

you can post this on the blogs area for the same, that would be very help full..

Nicolai's picture

And a you earn 5 connect points instead of only 1 smiley

I recommend you use the script with the shebang expression. Script may behave different depending on the shell you use. So if you wrote the script in bash you can instruct the OS to interpret the script withe the same shell. That ensure the script behave the same.

Examples:

#!/bin/bash Bash shell

#!/usr/bin/ksh Korn Shell

#!/usr/bin/perl The Perl language

 

Assumption is the mother of all mess ups.

If this post answered your'e qustion -  Please mark as a soloution.

Joseph_TKLee's picture

# usage : bk_size.sh DATE (Example: bk_size.sh "Dec 20 2012"

#             It shows the backup amounts of each policy since the Date.

#!/bin/bash
LOGFILE=/log/bk_size_pl.log

for V_PL in `bppllist`;
do
        bpcatlist -since $1 -policy $V_PL > $LOGFILE  2>/dev/null
        if [ $? -eq 0 ]
        then
                cat $LOGFILE | egrep '[0-9][k |M |G |T ]' | awk '{print $7 " " $9}' | awk '{if ( $1 ~ /T$/ ) Total+=substr($1,1,length($1)-1)*1024000; else if ( $1 ~/G$/ ) Total+=substr($1,1,length($1)-1)*1024; else if ( $1 ~/k$/ ) Total+=substr($1,1,length($1)-1)/1024;  else Total+=substr($1,1,length($1)-1) } END { print $2 " :            "  int(Total/1024) " GB"}'
        fi
done