Saving volume group information
#!/usr/bin/ksh
#
# Script: save_vg_info.ksh
#
# Author: Steve Diwell - Jedi Technology Ltd.
#
# Date: June 1999
#
# Aim: Save the volume group information required to recreate a
# volume group after a disk crash.
#
# NOTE:
# To run this script in debug mode type:
# export DEBUG=yes
# on the command line before running this script.
#
# To turn off debug mode type:
# unset DEBUG
# on the command line before running this script.
#
#
# Function to display the scripts usage
#
usage()
{
[[ -n ${DEBUG} ]] && set -x
clear
cat <<EOF
This script saves information required to recreate a volume group
after a disaster or disk crash. The volume group information is
stored in the "${SAVEDIR}" directory.
You may specify 'ALL' as the volume group name, in which case the
script saves information on all volume groups that are currently
on-line.
This script will not create the information on the rootvg
filesystem.
NOTE: You must be the root user to run this script.
Usage: ${SCRIPT} VolumeGroup|ALL
EOF
exit 1
}
#
# Some commands take a while to run and may produce no output, so
# this function puts a . on the screen every five seconds.
#
progress()
{
while :
do
echo ".\c"
sleep 5
done
}
#
# Are we in debug mode?
#
[[ -n ${DEBUG} ]] && set -x
clear
#
# Set environment for the script
#
PATH=/usr/bin:/etc:/usr/sbin:/usr/ucb:/usr/bin/X11:/sbin:
SCRIPT=`basename ${0}`
SAVEDIR="/var/adm/vgdata"
VG_INPUT=$*
#
# Only root can run the script.
#
[[ `whoami` != "root" ]] && usage
#
# If user input is null or rootvg, display usage.
# If user input is ALL, do all volume groups except rootvg.
#
[[ -z ${VG_INPUT} ]] && usage
[[ ${VG} = "rootvg" ]] && usage
[[ ${VG_INPUT} = "ALL" ]] && VG_INPUT=`lsvg -o | grep -v rootvg`
#
# For every volume group listed, save information
#
for VG in `echo ${VG_INPUT}`
do
echo "\nWorking on volume group ${VG}..."
#
# Let's check the ${VG} is on-line
#
lsvg -o | grep -q ${VG} || {
echo "\nThe Volume Group ${VG} is not on-line on this system."
break
}
#
# Get all the disks the ${VG} volume group is on.
#
DISKS=`lsvg -p ${VG} | awk '/active/ { ORS=" "
print $1}'`
#
# Create the Exclude file to stop the savevg backing up any files
#
[[ -f /etc/exclude.${VG} ]] && mv /etc/exclude.${VG} /etc/exclude.${VG}.saved
echo "/" > /etc/exclude.${VG}
#
# Now, mount all the filesystems in ${VG}, otherwise, savevg will
# miss them!!
#
echo "\nEnsuring all filesystems in the ${VG} are mounted, please wait."
progress &
PID=$!
lsvg -l ${VG} | awk '/closed/ {
if ( $2 == "jfs" )
{ if ( system ("mount " $7 ) != 0 )
print "Mount command failed for " $7
}
}'
echo ""
kill ${PID} 1>/dev/null 2>&1
#
# Create volume group information
#
echo "\nCreating the volume group data, please wait..\c"
progress &
PID=$!
mkvgdata -m ${VG} || {
echo "\nMkvgdata Command Failed for ${VG}"
kill ${PID}
exit 1
}
echo ""
kill ${PID} 1>/dev/null 2>&1
#
# Backup the ${VG} data file and put copy in ${SAVEDIR}
#
[[ ! -d ${SAVEDIR}/${VG} ]] && mkdir -p ${SAVEDIR}/${VG}
cp /tmp/vgdata/${VG}/${VG}.data ${SAVEDIR}/${VG}/${VG}.data
echo "" > ${SAVEDIR}/${VG}/${VG}.disks
for PV in `echo ${DISKS}`
do
lspv -l ${PV} >> ${SAVEDIR}/${VG}/${VG}.disks
echo "" >> ${SAVEDIR}/${VG}/${VG}.disks
lspv ${PV} >> ${SAVEDIR}/${VG}/${VG}.disks
echo "" >> ${SAVEDIR}/${VG}/${VG}.disks
done
#
# Save the volume group structure, which is used by restvg
#
echo "\nSaving the volume group structure, please wait..."
savevg -ef ${SAVEDIR}/${VG}.backup ${VG} || {
echo "Savevg command failed for ${VG}"
exit 1
}
echo "\nInformation required to recreate the ${VG} volume group"
echo "has been saved in plain text files in \"${SAVEDIR}/${VG}\"."
echo "\nThe command \"restvg -f ${SAVEDIR}/${VG}.backup\""
echo "can be used to recreate the volume group.\n"
#
# Put back the original exclude file, if it existed.
#
if [[ -f /etc/exclude.${VG}.saved ]]
then
mv /etc/exclude.${VG}.saved /etc/exclude.${VG}
else
rm -f /etc/exclude.${VG}
fi
#
# Clean up temporary files and directories
#
[[ -f /tmp/${VG}.backup ]] && rm -f /tmp/${VG}.backup
[[ -f /tmp/vgdata/vgdata.files ]] && rm -f /tmp/vgdata/vgdata.files
[[ -d /tmp/vgdata/${VG} ]] && rm -fr /tmp/vgdata/${VG}
done # For the for VG in `echo ${VG_INPUT}`
exit 0