Thursday, April 9, 2009

A Few More Obscure NetBackup Command Line Quickies

Hey There,

To finish off a Hellish week, or so, of NetBackup insanity (that's gone from not too slickly creating a command line NetBackup Activity Monitor to copying and modifying policies, schedules and clients between NetBackup hosts all the way to a simple way to get better NetBackup support for VCS), we bring you the final NetBackup post of the week (and, probably, for a while :)

Today's subject is going to be a little more scatter-brained than I usually am (??? ;) The following are a few extra little command lines you can use to make your NetBackup (Linux and Unix) command line experience somewhat less unenjoyable :) The location of the the binaries (though spelled out fully here) may differ depending on your installation. This post contains the standard defaults for NetBackup on Solaris 10 and OpenSolaris:

1. List out all your backup pools:

host # /usr/openv/volmgr/bin/vmpool -list_all -bx
pool index max partially full description
---------------------------------------------------------------------------------------------
None 0 0 the None pool
NetBackup 1 0 the NetBackup pool


2. Create new backup pools:

host # /usr/openv/volmgr/bin/vmpool -create -pn MY_Backups -description "Not Yours" -mpf 0
host # /usr/openv/volmgr/bin/vmpool -create -pn MY_Database_Backups -description "I said MINE" -mpf 0


and then make sure they're there:

host # /usr/openv/volmgr/bin/vmpool -list_all -bx
pool index max partially full description
---------------------------------------------------------------------------------------------
None 0 0 the None pool
NetBackup 1 0 the NetBackup pool
MY_backups 4 0 Not Yours
MY_Database_backups 5 0 I Said MINE


3. Inventory your robot (the robot type is tld and the robot number is 0):

host # /usr/openv/volmgr/bin/vmcheckxxx -rt tld -rn 0 -list

Robot Contents

Slot Tape Barcode
==== ==== ============
1 Yes CLN099
2 Yes CLN098
3 Yes C04440
4 Yes C04441
5 Yes C04442


4. List out your tape pools and the number of tapes each has:

host # while read a b c;do echo "Pool no. $b = $a";/usr/openv/volmgr/bin/vmquery -p $b -b|awk '{print $1}'|egrep -v '^media|^ID'|echo $(expr `echo $(wc -l)` - 1);done <<<"`/usr/openv/volmgr/bin/vmpool -list_all -bx|sed 1,2d`"

Pool no. 0 = None
2
Pool no. 1 = NetBackup
0
Pool no. 2 = MY_backups
1
Pool no. 3 = My_Database_backups
2


5. Do the same thing a different way:

host # while read a b c;do echo -n "$b ";/usr/openv/volmgr/bin/vmquery -p $b -b|awk '{print $1}'|egrep -v '^media|^ID'|echo $(expr `echo $(wc -l)` - 1);done <<<"`/usr/openv/volmgr/bin/vmpool -list_all -bx|sed 1,2d`"
0 2
1 0
2 1
3 2


6. And again (All this "proof of concept" stuff is great for keeping management at bay ;)

host # count=0;for x in $(while read a b c;do echo -n "$b ";/usr/openv/volmgr/bin/vmquery -p $b -b|awk '{print $1}'|egrep -v '^media|^ID'|echo $(expr `echo $(wc -l)` - 1);done <<<"`/usr/openv/volmgr/bin/vmpool -list_all -bx|sed 1,2d`");do if [[ $count -eq 0 ]];then echo -n "Pool No. $x = ";count=$count+1;else echo "Count $x";count=0;fi;done
Pool No. 0 = Count 2
Pool No. 1 = Count 0
Pool No. 2 = Count 1
Pool No. 3 = Count 2


7. Show the commands you'd need to run to recreate your current setup:

host # count=0;for x in $(while read a b c;do echo -n "$b ";/usr/openv/volmgr/bin/vmquery -p $b -b|awk '{print $1}'|egrep -v '^media|^ID'|echo $(expr `echo $(wc -l)` - 1);done <<<"`/usr/openv/volmgr/bin/vmpool -list_all -bx|sed 1,2d`");do if [[ $count -eq 0 ]];then poolnum=$x;count=$count+1;else numtapes=$x;count=0;if [ $numtapes -gt 0 ];then tape_array=($(/usr/openv/volmgr/bin/vmquery -p $poolnum -b|sed 1,3d|awk '{print $1}'|xargs echo));while [ $numtapes -gt 0 ];do let numtapes=$numtapes-1;if [[ $(expr "${tape_array[$numtapes]}" : 'CLN') -eq 3 ]];then echo "CLN /usr/openv/volmgr/bin/vmchange -p $poolnum -m ${tape_array[$numtapes]}";else echo "POOL $poolnum /usr/openv/volmgr/bin/vmchange -p $poolnum -m ${tape_array[$numtapes]}";fi;done;fi;fi;done
CLN /usr/openv/volmgr/bin/vmchange -p 0 -m CLN099
CLN /usr/openv/volmgr/bin/vmchange -p 0 -m CLN098
POOL 4 /usr/openv/volmgr/bin/vmchange -p 2 -m C04440
POOL 4 /usr/openv/volmgr/bin/vmchange -p 3 -m C04441
POOL 4 /usr/openv/volmgr/bin/vmchange -p 3 -m C04442



8. Yet another way to list your tapes, and the pools to which they belong, using your existing setup as input:

host # while read a b c;do echo "Pool no. $b = $a";/usr/openv/volmgr/bin/vmquery -p $b -b|awk '{print $1}'|egrep -v '^media|^ID'|echo $(expr `echo $(wc -l)` - 1);done <<<"`/usr/openv/volmgr/bin/vmpool -list_all -bx|sed 1,2d`"
Pool no. 0 = None
2
Pool no. 1 = NetBackup
0
Pool no. 2 = MY_backups
1
Pool no. 3 = MY_database_backups
2


9. Create an array of volume pools - each with a number of members equal to the number of members in the pool (you'll see why in a second):

host # tanum=0;while read a b c;do tnum=$(/usr/openv/volmgr/bin/vmquery -p $b -b|awk '{print $1}'|egrep -v '^media|^ID'|echo $(expr `echo $(wc -l)` - 1));if [[ $tnum -gt 0 ]];then while [[ $tnum -gt 0 ]];do let tnum=$tnum-1;tarray[$tanum]=$b;let tanum=$tanum+1;done;fi;done <<<"`/usr/openv/volmgr/bin/vmpool -list_all -bx|sed 1,2d`";echo ${tarray[@]}
0 0 2 3 3


10. Use the array you just created to create new media pools on a separate host (note that this will only assign the CLN tapes to the 0 pool - specifically - and will randomly (in order ;) assign the number of tapes necessary to each of your pools. Don't forget to set those up first (as above :))

PROOF OF CONCEPT RUN

host # tarray=(0 0 2 3 3);count=0;for x in $(echo ${tarray[@]});do tape_array=($(/usr/openv/volmgr/bin/vmquery -a -b|sed 1,3d|awk '{print $1}'|sort -rn|xargs echo));if [[ $(expr "${tape_array[$count]}" : 'CLN') -eq 3 ]];then echo "CLN $x /usr/openv/volmgr/bin/vmchange -p $x -m ${tape_array[$count]}";let count=$count+1;else echo "POOL $x /usr/openv/volmgr/bin/vmchange -p $x -m ${tape_array[$count]}";let count=$count+1;fi;done
CLN 0 /usr/openv/volmgr/bin/vmchange -p 0 -m CLN009
CLN 0 /usr/openv/volmgr/bin/vmchange -p 0 -m CLN010
POOL 2 /usr/openv/volmgr/bin/vmchange -p 4 -m C08880
POOL 3 /usr/openv/volmgr/bin/vmchange -p 4 -m C08881
POOL 3 /usr/openv/volmgr/bin/vmchange -p 4 -m C08882



AND THE REAL DEAL:

host # tarray=(0 0 4 4 4 4 4 4 4 4 4 5 5 7 7 7 7 7 7 7 7 7);count=0;for x in $(echo ${tarray[@]});do tape_array=($(/usr/openv/volmgr/bin/vmquery -a -b|sed 1,3d|awk '{print $1}'|sort -rn|xargs echo));if [[ $(expr "${tape_array[$count]}" : 'CLN') -eq 3 ]];then echo "Running /usr/openv/volmgr/bin/vmchange -p $x -m ${tape_array[$tcount]}";/usr/openv/volmgr/bin/vmchange -p $x -m ${tape_array[$count]};let count=$count+1;else echo "Running /usr/openv/volmgr/bin/vmchange -p $x -m ${tape_array[$count]}";/usr/openv/volmgr/bin/vmchange -p $x -m ${tape_array[$count]};let count=$count+1;fi;done
Running /usr/openv/volmgr/bin/vmchange -p 0 -m CLN009
Running /usr/openv/volmgr/bin/vmchange -p 0 -m CLN010
Running /usr/openv/volmgr/bin/vmchange -p 2 -m C08880
Running /usr/openv/volmgr/bin/vmchange -p 3 -m C08881
Running /usr/openv/volmgr/bin/vmchange -p 3 -m C08882


11. Verify that your tape assignments worked:

host # /usr/openv/volmgr/bin/vmpool -list_all -bx
pool index max partially full description
---------------------------------------------------------------------------------------------
None 0 0 the None pool
NetBackup 1 0 the NetBackup pool
MY_backups 2 0 Not Yours
MY_Database_backups 3 0 I said MINE

host # while read a b c;do echo "Pool no. $b = $a";/usr/openv/volmgr/bin/vmquery -p $b -b|awk '{print $1}'|egrep -v '^media|^ID';done <<<"`/usr/openv/volmgr/bin/vmpool -list_all -bx|sed 1,2d`"
Pool no. 0 = None
-------------------------------------------------------------------------------
CLN009
CLN010
Pool no. 1 = NetBackup
-------------------------------------------------------------------------------
Pool no. 2 = MY_backups
CO8880
-------------------------------------------------------------------------------
Pool no. 3 = MY_Database_backups
C08881
CO8882


And so much more... but not for today ;)

Cheers,

, Mike




Discover the Free Ebook that shows you how to make 100% commissions on ClickBank!



Please note that this blog accepts comments via email only. See our Mission And Policy Statement for further details.