1844161 Members
2338 Online
110229 Solutions
New Discussion

vgexport script

 
Aggy
Frequent Advisor

vgexport script

I wanted to create a map files of all the vol groups on my production servers from existing Test Server and then copy that created MAP files to my Test server

I have written a generic script which runs OK and is pasted below
VGEXP=/usr/sbin
MAPFILE=/home/root/mapfiles
MAPFILE1=/home/root/vgmaps/

# PRODSERV1
echo "Creating PRODSERV1 Map File"
remsh prodserv1 -l root $VGEXP/vgexport -v -p -m $MAPFILE/prodserv1.map vgFisc01
echo "Copying PRODSERV Map File to TESTSERV1"
rcp prodserv:$MAPFILE/prodserv.map $MAPFILE1/prodserv1/

# PRODSERV2
echo "Creating PRODSERV2 Map File"
remsh prodserv2 -l root $VGEXP/vgexport -v -p -m $MAPFILE/prodserv2.map vgFisc01
echo "Copying PRODSERV2 Map File to TESTSERV1"
rcp prodserv2:$MAPFILE/prodserv2.map $MAPFILE1/prodserv2/

but this script makes a map file of vol group vgFisc01, I also have other volume groups on my production servers, So I wanted to change the script in a way that it finds the vol groups on my production servers and then do a VGEXPORT of that vol groups to create a MAP file. Then the MAP files of all my prod servers gets copied to my Test Server.

I am not sure but it can use /etc/lvmtab or /dev/vg* to get the details of vol group.
8 REPLIES 8
James R. Ferguson
Acclaimed Contributor

Re: vgexport script

Hi Aggy:

One way to obtain a list of volume groups is:

# VGS=`vgdisplay|awk '/VG Name/ {print $3}'`

... THen you can do:

# for VG in ${VGS}
> do
> ...
> done

Regards!

...JRF...
Marvin Strong
Honored Contributor

Re: vgexport script

here is a simple loop to get all vg's and make map files for each one in /tmp

i'll leave as an excerise for the reader to modify it to copy them to another server.

vgdisplay | grep "VG N" | awk '{print $NF}' | while read vg
do
vgexport -p -m /tmp/${vg##*/}.map ${vg}
done
~
Marvin Strong
Honored Contributor

Re: vgexport script

Oh got to add, that will only get active volume groups if they are not active they will not get a map file created. But you will get errors on those.

Doug O'Leary
Honored Contributor

Re: vgexport script

Hey;

Dont' listen to Marvin Strong; he never knows what he's talking about!

Just kidding: How you doing, Marvin?

To expand, a bit on what Marvin suggested: Your script seemingly runs from the test server; it'd be easier to implement running from the production server(s):

#!/bin/ksh

mapdir=/var/adm/crash/maps
[[ ! -d ${mapdir} ]] && mkdir -m 750 -p ${mapdir}
rm ${mapdir}/*.map > /dev/null 2>&1
for vg in $(vgdisplay | grep -i 'vg name' | awk '{print $NF}')
do
vgexport -s -m ${mapdir}/${vg##*/}.map -p ${vg}
done

rcp -rp ${mapdir} ${test_sys}:/var/adm/crash

#EOF

Same constraints that Marvin mentioned - only works on active vgs...

Hth

------
Senior UNIX Admin
O'Leary Computers Inc
linkedin: http://www.linkedin.com/dkoleary
Resume: http://www.olearycomputers.com/resume.html
Aggy
Frequent Advisor

Re: vgexport script

Thank you very much.
My script works. Can you please explain what $[vg##*/} does/how it works
Marvin Strong
Honored Contributor

Re: vgexport script

${vg##*/}

means delete the largest pattern matching */
thus leaving you with only vg?? instead of /dev/vg??


Marvin Strong
Honored Contributor

Re: vgexport script

BTW that is fully documented in the man page for ksh.
Aggy
Frequent Advisor

Re: vgexport script

Thankyou Evryone