#!/bin/ksh
# script fsgen
# by -=GLA=-
# to generate a script that creates filesystems
# command file uses mklvfs script
version=4.0
# constants {{{
Host=$(uname -n)
Mklvfs='/usr/local/bin/mklvfs'
# }}}
usage () { #{{{
cat >> USE
Script fsgen, version ${version}
Purpose: Generates command-file to create filesystems using existing vg as reference
Usage: fsgen -l VGNAME [-o OUTVGNAME] [-f CMDFILE] [-r RESTOREFILE]
where:
VGNAME is source vg on local system
OUTVGNAME is target vg on target system, default is same as VGNAME
CMDFILE is the creation command file to exec on target, default is ./fsgen.hostname.OUTVG
RESTOREFILE is the restore command file to exec on target, default is ./rsfs.hostname.OUTVG\n
This script:
Scans the specified vg for fs,
then generates a command file and a restore file to recreate these fs.
Assumes source and target vg have same PP size.
CMDFILE format is:
${Mklvfs} -l LVNAME -p PP -m MOUNTPOINT -v OUTVGNAME -u OWNER -g GROUP -c PERMS
RESTOREFILE format is:
/usr/bin/dsmc restore -su=yes -rep=all "/FSNAME"/*"
You'll probably want to edit the command file before use.
Examples:
fsgen -l optvg -o datavg -f /tmp/fsgen.out
Running this on xp0 produces /tmp/fsgen.out and ./rsfs.xp0.datavg
fsgen -l datavg
This produces ./fsgen.xp0.datavg and ./rsfs.xp0.datavg
USE
exit 1
} #}}}
checkvar () { #{{{
[[ -z ${vgn} ]]&&usage
vglist=$(lsvg -o)
for vg in ${vglist}; do
[[ ${vgn} = ${vg} ]]&&found=y
done
[[ -z ${found} ]]&&print "Could not find ${vgn} on this system, verify vg name."&&exit 0
[[ -z ${vgo} ]]&&vgo=${vgn}
[[ -z ${filen} ]]&&filen="fsgen.${Host}.${vgo}"
[[ -z ${rfile} ]]&&rfile="rsfs.${Host}.${vgo}"
} #}}}
genrs () { #{{{
print "Generating restore file ${rfile}..."
print "### EDIT AS NECESSARY">${rfile}
lsvg -l ${vgn}|awk '$NF~/^\//{print"/usr/bin/dsmc restore -su=yes -rep=all \""$7"\/\*\""}'>>${rfile}
print "\n${rfile} vvvvvvvvvvvvvvvvvvvv"
cat ${rfile}
print "${rfile} ^^^^^^^^^^^^^^^^^^^^"
print "\nGenerated restore file ${rfile} with above commands."
print "Execute after creating filesystems with ${filen}."
} #}}}
genfs () { #{{{
print "Generating command file ${filen}..."
ppsz=$(lsvg ${vgn}|awk '/PP SIZE/{print$6}')
print "### AUTOMATIC VERIFICATION SCRIPT FOR TARGET">${filen}
print "tgpp=\$(lsvg ${vgo}|awk '/PP SIZE/{print\$6}')">>${filen}
print "[[ ${ppsz} -ne \${tgpp} ]]&&print \"PP size mismatch, source PP = ${ppsz}, target PP = \${tgpp}\"&&exit 1">>${filen}
print 'vglist=$(lsvg -o)'>>${filen}
print 'for vg in ${vglist}; do'>>${filen}
print " [[ ${vgo} = \${vg} ]]&&found=y">>${filen}
print 'done'>>${filen}
print "if [[ -z \${found} ]]; then">>${filen}
print " print \"Could not find ${vgo} on this system, be sure to edit this file before execution.\"">>${filen}
print " exit 1\nfi">>${filen}
print "### COMMANDS TO BUILD LV AND FS">>${filen}
print "### VERIFY PARAMETERS BEFORE EXECUTION">>${filen}
lsvg -l ${vgn}>/tmp/lsvg.out
exec 4>/tmp/lsvg.out
while read -u4 line; do
printf "."
cmdstr=$(print ${line}|awk '$6~/open/&&$NF~/^\//{print Mklvfs" -l",$1,"-p",$3,"-m",$7,"-v",vgo}' vgo=${vgo} Mklvfs=${Mklvfs
})
printf "."
ugstr=$(print ${line}|awk '$6~/open/&&$NF~/^\//{system("ls -ld "$NF)}'|awk '{print" -u "$3" -g "$4}')
printf "."
lvn=$(print ${line}|awk '$6~/open/&&$NF~/^\//{print$NF}')
printf "."
prmstr=$(perl -e 'printf(" -c %o", (stat("'"${lvn}"'"))[2] & 07777)')
[[ -n ${cmdstr} && -n ${ugstr} && -n ${prmstr} ]]&&print "${cmdstr} ${ugstr} ${prmstr}">>${filen}
done
print "\n\n${filen} vvvvvvvvvvvvvvvvvvvv"
cat ${filen}
print "${filen} ^^^^^^^^^^^^^^^^^^^^"
print "\nGenerated file ${filen} with above commands.\nPlease edit lv names if necessary."
print "Execute ${filen} on target system to create these fs.\n"
} #}}}
# main
while getopts :l:f:o:r: option; do
case ${option} in
l)vgn=${OPTARG}
;;
f)filen=${OPTARG}
;;
o)vgo=${OPTARG}
;;
r)rfile=${OPTARG}
;;
*)usage
;;
esac
done
checkvar
genfs
genrs