Operating System - HP-UX
1820754 Members
3530 Online
109627 Solutions
New Discussion юеВ

Script for Exporting and Importing VG's

 
SOLVED
Go to solution
Richard Pugh_2
Advisor

Script for Exporting and Importing VG's

Hello,
I was wondering if anyone out there has a script for creating a VGImport and Export script. I have some preliminary work done already but I cannot get some of it to work. So, if you have any information for me it would greatly be appreciated.

Thanks in advance,
CoMteC17
10 REPLIES 10
Patrick Wallek
Honored Contributor

Re: Script for Exporting and Importing VG's

If you could show us the script you have now and tell us what isn't working we may be able to help you fix it.
Donny Jekels
Respected Contributor

Re: Script for Exporting and Importing VG's

you find what you are looking for in this list.


http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0xf0fc5dc05a7ad711abdc0090277a778c,00.html

http://www.shellderado.com
"Vision, is the art of seeing the invisible"
Geoff Wild
Honored Contributor
Solution

Re: Script for Exporting and Importing VG's

How about:

for i in `ls -d /dev/vg*`
do
vgexport -s -p -v -m /tmp/$i.map $i
done

Then to import, mkdir all the /dev/vg's
and
mknod /dev/vgXX/group c 64 0xXX000

for i in `ls /tmp/*.map | awk -F. '{print $1}' | awk -F/ '{print $3}'`
do
vgimport -s -v -m /tmp/$i.map /dev/$i
done


Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
John Meissner
Esteemed Contributor

Re: Script for Exporting and Importing VG's

I wrote two scripts for this the other day...

here is the export script:



#! /usr/bin/ksh
# this script written by John Meissner 4.14.2003
# This script will automatically do a vgexport for a server and generate map files
BOLD="`tput smso`"
NORMAL="`tput rmso`"
if [ `id|cut -c5-11` != "0(root)" ]
then
echo "Quitting - You must run this script as Root"
exit 1
fi

SGP=$(cmviewcl | grep `hostname` | grep enabled | awk '{print $1}') #checks for SG package name
# the following section will check for the service gard package status and halt the package
mcsg=1
while [ "$mcsg" = "1" ]
do
SGPS=$(cmviewcl | grep `hostname | grep enabled | awk '{print $2}') #checks the SG package status
if [ "$SGPS" = up ]
then
echo "Service Gard package $SGP is $SGPS - stopping package now"
cmhaltpkg $SGP
elif [ "$SGPS" = "down" ] || [ $? != 0 ]
then
echo "Service Gard package $SGP is $SGPS - continuing "
mcsg=0
elif [ "$SGPS" = "starting" ] || [ "$SGPS" = "halting" ]
then
echo " Service Gard package $SGP is $SGPS - sleeping 10 "
sleep 10
fi
done

#this section will find the VG names for the server and export the VG's to map files
dev_vg=$(ll /dev/vg*/group | grep -v vg00 | awk '{print $10}' | sed 's/\/group//g' | sed 's/\/dev\///g')
for i in $dev_vg
do
vgexport -p -s -m $dev_vg.map /dev/$dev_vg
done

#find the failover server and ftp the map files
SGF=$(cmviewcl -v -p $SGP | grep Alternate | awk '{print $4}')
ftp -n -i <open $SGF
user username password
cd /tmp
ascii
mput /tmp/*.map
quit
HERE
All paths lead to destiny
John Meissner
Esteemed Contributor

Re: Script for Exporting and Importing VG's

and here is the vgimport script:


#! /usr/bin/ksh
# written by John Meissner on 4.14.03
# this script will automatically import vg map files created from other servers

# this entire process will deal only with the VG's that have new map files for them
# the map files will have already been ftp'd from the primary SG server to the /tmp directory

# get a list of the minor numbers and get them ready
vgmap_files=$(ls /tmp/*.map | sed 's/\/tmp\///g'| sed 's/\.map//g')
for i in $vgmap_files
do
ll /dev/vg*/group | grep $i | awk '{print $6,$10}' >> /tmp/minornum.list
newvg=$(ll /dev/vg*/group | grep $i)
if [ "$newvg" = "" ]
then
function get_next_volume_group_minor_number {
typeset -Z2 NEXTMINORNUM=0
let MINORNUM=0
ls -l /dev/*/group | awk '{print $6}' | cut -c 3-4 | {
while read MINORNUM
do
if ((NEXTMINORNUM < MINORNUM));
then
let NEXTMINORNUM=MINORNUM
fi
done
}
let NEXTMINORNUM=NEXTMINORNUM+1
print "0x0"$NEXTMINORNUM"0000 $i" >> /tmp/minornum.list
}

fi
done

# export the old VG's
oldvg-$(cat /tmp/minornum.list | awk '{print $2}' | awk -F/ '{print $3}')
for i in $oldvg
do
vgexport $i
done
fi
#now vgimport the new vg maps
vgdir=$(cat /tmp/minornum.list | awk '{print $2}' | awk -F/ '{print $3}')
for i in $vgdir
do
mkdir /dev/$i
done

#mknod
cat /tmp/minornum.list | awk '{print "mknod " $2 " c 64 " $1}' > /tmp/makenod.sh
chmod +x /tmp/makenod.sh
/tmp/makenod.sh

#vgimport
cat minornum.list | awk '{print "vgimport -s -m " $2 ".map /dev/" $2}' > /tmp/vgimpt.sh
chmod +x /tmp/vgimpt.sh
/tmp/vgimpt.sh

echo " you may now try to start the SG package "

All paths lead to destiny
Richard Pugh_2
Advisor

Re: Script for Exporting and Importing VG's

Thanks John,
There was one command that did the trick for me. I will post the script when I have completely tested it.

I do have one question, how do force the export of the VG? What I mean is, after I run the vgexport -v -m /mapfile -s /dev/vg , I strings the /etc/lvmtab and the vg is still there.

Is there anything special I must do?
Richard Pugh_2
Advisor

Re: Script for Exporting and Importing VG's

Nevermind....I answered my own question. I must umount the filesystems and do a vgchange -a n /dev/vg.

Thanks again for all the responses.
John Meissner
Esteemed Contributor

Re: Script for Exporting and Importing VG's

Richard... i went back through my script and fount two lines you will need to comment out before it works.

comment out the following two lines:

function get_next_volume_group_minor_number {
}

(the last } bracket in the function for get_next_volume_group_minor_number will also need to be commented out.)

after you do that it should work perfectly. sorry for not catching this sooner
All paths lead to destiny
John Meissner
Esteemed Contributor

Re: Script for Exporting and Importing VG's

to completely remove the vg you just do
vgexport
without any options this should remove the vg from you system and the lvmtab - but it sounds like you got that already
All paths lead to destiny
Richard Pugh_2
Advisor

Re: Script for Exporting and Importing VG's