#!/bin/ksh # CMD lvDefs.sh # Author: Raymond M. A. Erdey # http://members.telocity.com/rerdey # # Date: 01/09/1998 # # Description: # Generates commands needed to recreate the Physical Volumes, Volume Groups # Logical Volumes, and File Systems, defined on the current host. # # Parameters: # -s ScriptFile - The name of the script file to generate. # -l LVDataFile - The name of the LV data file to generate. # -d - Do not generate commands to recreate Physical # Volumes and Volume Groups. # # Modifications: # Initial revision # # # # # ScriptFile="" LVDataFile="" BT="\'" CMD=$(basename $0) MyPID=$$ HOSTNAME=$(hostname) DATE=$(date) PTH="/tmp" TempFile="${PTH}/${CMD}.$$" TempErrorFile="${PTH}/${CMD}.TempErrorFile.$$" ErrorFile="${PTH}/${CMD}.ErrorFile.$$" LockFile="${PTH}/${CMD}.lock" FileList="${TempFile} ${TempErrorFile} ${ErrorFile} ${LockFile}" trap "rm -f ${FileList};exit" 3 4 5 6 8 10 11 15 TTY=$(tty) if [ $? -ne 0 ] then TTY="null" fi RetCode=0 NoDisk="FALSE" ############################################################################### # Function: Usage # # Purpose: Print usage text. # ############################################################################### Usage() { print -u2 "\n\nUsage: "$CMD" -s ScriptFile -l LVDataFile [-d]" print -u2 "Where:" print -u2 "\t-s ScriptFile\t- Name of shell script file to create." print -u2 "\t\t\t This file will contain the commands needed to" print -u2 "\t\t\t recreate the Logical Volumes, File Systems" print -u2 "\t\t\t Physical Volumes and Volume Groups that are" print -u2 "\t\t\t defined on the current system." print -u2 "\t-l LVDataFile\t- Name of the Logical Volume Data file" print -u2 "\t\t\t to create." print -u2 "\t -d\t\t- If specified, then the commands needed to" print -u2 "\t\t\t recreate the Physical Volumes and Volume groups" print -u2 "\t\t\t will not be generated." print -u2 "\t\t\t The Logical Volumes will be recreated in the" print -u2 "\t\t\t current Volume Groups, but not on the current" print -u2 "\t\t\t Physical Volumes." print -u2 "\t\t\t If Logical Volumes are mirrored, then the" print -u2 "\t\t\t mirrors will not be recreated." print -u2 "\n" } ############################################################################### # Function: lock # # Purpose: Creates a file lock for the current process. On failure a # # non-zero return code is returned. # ############################################################################### lock() { print ${MyPID} >${LockFile}.${MyPID} RC=$? ln -s ${LockFile}.${MyPID} ${LockFile} SaveRC=$? ########################################################## # If lock file exists, then make sure that the process # # that created it is still running. # # If it is not running then try again to create the # # lock file. # ########################################################## if [ ${SaveRC} -ne 0 ] then ################################################ # Get Process ID of the process that created # # the current lock file. # ################################################ PID=$( cat ${LockFile} |awk '{print $1}' ) ####################################################### # If "ps" returns a non-zero value then the process # # is not running. # ####################################################### ps -fp${PID} SaveRC=$? if [ ${SaveRC} -ne 0 ] then ########################### # Delete old lock file. # ########################### rm -f ${LockFile} ${LockFile}.${PID} 1>/dev/null 2>/dev/null ########################### # Create new lock file. # ########################### ln -s ${LockFile}.${MyPID} ${LockFile} SaveRC=$? else RC=1 fi fi RC=$( expr ${RC} + ${SaveRC} ) if [ "${TTY}" != "null" ] then print "\n\nLockFiles:\n----------" ls -ltr ${LockFile}* print "\n" fi ############################################ # If unable to get a lock then clean up. # ############################################ if [ ${RC} -ne 0 ] then rm -f ${LockFile}.${MyPID} fi return $RC } ############################################################################### # Function: unlock # # Purpose: Removes lock file for the current process. # ############################################################################### unlock() { if [ $(cat ${LockFile} |awk '{print $1}') -eq ${MyPID} ] then rm ${LockFile} RC=$? else RC=0 fi rm ${LockFile}.${MyPID} RC=$( expr ${RC} + $? ) return RC } while getopts :hds:l: KEY $* do case $KEY in s) ScriptFile=$OPTARG ;; l) LVDataFile=$OPTARG ;; d) NoDisk="TRUE" ;; h) Usage ; exit ;; *) print -u2 "Invalid option."; Usage ; exit ;; esac done if [ "${ScriptFile}" = "" ] then Usage exit fi if [ "${LVDataFile}" = "" ] then Usage exit fi typeset -ri iUID=$(id -u) if [ ${iUID} -ne 0 ] then print "\nWARNING: This script should be run via the root user ID.\n" if [ "${TTY}" != "null" ] then print -n "Do you wish to continue (y/n): " read ans if [ "${ans}" != "y" ] && [ "${ans}" != "Y" ] then print "Exiting.\n" exit 1 fi fi fi ##################################################### # Create lock file; Prevents multiple instances. # ##################################################### lock if [ $? -ne 0 ] then DB=$(cat ${LockFile} |awk '{print $2}') print "\n\n"${CMD}" is currently running." >${TempFile} if [ "${TTY}" != "null" ] then cat ${TempFile} fi rm ${TempFile} exit fi rm -f ${LVDataFile} ${ScriptFile} ${TempErrorFile} ${ErrorFile} 2>/dev/null 1>/dev/null touch ${LVDataFile} ${ScriptFile} ${TempErrorFile} ${ErrorFile} print "\n\nHost Name:\t${HOSTNAME}" print "Date:\t\t${DATE}" print "#!/bin/ksh" >${ScriptFile} print "#\n#\tHost Name:\t${HOSTNAME}" >>${ScriptFile} print "#\tDate:\t\t${DATE}\n\n" >>${ScriptFile} print "" >>${ScriptFile} print 'typeset -rs CMD=$(basename $0)' >>${ScriptFile} print 'typeset -rs PID=$$' >>${ScriptFile} print "typeset -rs PTH=\"/tmp\"" >>${ScriptFile} print 'typeset -rs TempErrorFile="${PTH}/${CMD}.TempErrors.${PID}"' >>${ScriptFile} print "\nif [ \"\$1\" = \"\" ]\nthen\n" >>${ScriptFile} print "\t"'typeset -rs ErrorFile="${PTH}/${CMD}.Errors.${PID}"' >>${ScriptFile} print "\t"'typeset -rs FILELIST="${TempErrorFile} ${ErrorFile}"' >>${ScriptFile} print "else\n\ttypeset -rs ErrorFile=\"\$1\"" >>${ScriptFile} print "\t"'typeset -rs FILELIST="${TempErrorFile}"' >>${ScriptFile} print "fi\n" >>${ScriptFile} print "" >>${ScriptFile} print 'touch ${ErrorFile}' >>${ScriptFile} print "" >>${ScriptFile} print "typeset -i RC=0" >>${ScriptFile} print "typeset -i RC2=0" >>${ScriptFile} print "typeset -i RetCode=0" >>${ScriptFile} print "FSFAILED=\"\"" >>${ScriptFile} print "LVFAILED=\"\"" >>${ScriptFile} print "LVCFAILED=\"\"" >>${ScriptFile} print "" >>${ScriptFile} ################################################### # This would be nice if it worked... Bummer... # ################################################### #if [ "${TTY}" != "null" ] #then # WriteToScript="| tee -a ${ScriptFile}" #else # WriteToScript=">> ${ScriptFile}" #fi ###################################################### # Create commands needed to recreate disks that do # # not belong to rootvg. # ###################################################### if [ "${NoDisk}" = "FALSE" ] then print -u2 "\n\nGathering information for physical volumes.\nThis may take a few minutes...\n" lsvg -o |grep -v rootvg | lsvg -i -p | grep -v -E ":|PV_NAME" | sort -u | awk -v TempFile=$TempFile -v TempErrorFile=${TempErrorFile} -v ErrorFile=${ErrorFile} -v BT=${BT} ' ###################################################################### # Function: CheckErrors # # Purpose: If text is found in the TempErrorFile then the text # # as well as the command "str" will be copied to # # the ErrorFile. # ###################################################################### function CheckErrors(str,TempErrorFile,ErrorFile) { LineCount=0 close(TempErrorFile) while (getline < TempErrorFile > 0) { if ( $0 != "" ) { LineCount++ if ( LineCount == 1 ) { RetCode=1 cmd=sprintf("/bin/ksh -c %s print \"COMMAND:\n\t%s\nERROR:\n\t%s\" >>%s %s", BT, str, $0, ErrorFile, BT) } else { cmd=sprintf("/bin/ksh -c %s print \"\t%s\" >>%s %s", BT, $0, ErrorFile, BT) } system(cmd) } } close(TempFile) } BEGIN { RetCode=0 print "\n###########################################" print "# Commands needed to redefine the disks #" print "###########################################\n" print "MissinDisks=\"\"" VGCount=0 } { PVName=$1 cmd=sprintf("/usr/sbin/lsdev -Cl %s -F\"name type class subclass parent connwhere\" 1>%s 2>%s", PVName, TempFile, TempErrorFile) system(cmd) close(TempFile) if (getline < TempFile > 0) { split($0, ARGS) printf("set -x\nmkdev -l %s -t %s -c %s -s %s -p %s -w %s 2>${TempErrorFile}\nmkdev -l %s 2>>${TempErrorFile}\nRC=$?\nset +x\n", PVName, ARGS[2], ARGS[3], ARGS[4], ARGS[5], ARGS[6], PVName) printf("if [ ${RC} -ne 0 ]\nthen\n") printf("\tRetCode=$( expr ${RetCode} + ${RC} )\n") printf("\tMissinDisks=\"${MissinDisks} %s\"\n", PVName) printf("\tprint \"ERROR: Unable to create the Physical Volume named %s\" |tee -a ${ErrorFile}\n", PVName) printf("\tcat ${TempErrorFile} |tee -a ${ErrorFile}\n") printf("fi\n") } else { print "ERROR: Unable to get device definition for "PVName } close(TempFile) ################################ # Check for possible errors. # ################################ RetCode=CheckErrors(cmd,TempErrorFile,ErrorFile) #################################### # Get Volume group for the disk. # #################################### cmd=sprintf("lspv %s |grep \"VOLUME GROUP:\" 1>%s 2>%s", PVName, TempFile, TempErrorFile) system(cmd) close(TempFile) if (getline < TempFile > 0) { VGName=$6 if ( VGTable[VGName] == "" ) { VGCount=VGCount+1 VGList[VGCount]=VGName } VGTable[VGName]=VGTable[VGName]" "PVName } close(TempFile) ################################ # Check for possible errors. # ################################ RetCode=CheckErrors(cmd,TempErrorFile,ErrorFile) } END { printf("\n##############################################\n") printf("# Commands needed to create volume groups. #\n") printf("##############################################\n\n") i=1 while (i<=VGCount) { VGName=VGList[i] PVList=VGTable[VGName] cmd=sprintf("lsvg %s >%s", VGName, TempFile) system(cmd) close(TempFile) while (getline < TempFile > 0) { if ( $4 == "PP" ) { PPSize=$6 } else if ( $4 == "AUTO" ) { if ( $6 == "no" ) { AutoMount="-n" } else { AutoMount="" } } else if ( $4 == "QUORUM:" ) { if ($5 == "1" ) { QUORUM="no" } } } close(TempFile) printf("if [ \"${MissinDisks}\" != \"\" ]\nthen\n\tprint \"The following Disks are not defined, please correct this before continuing:\\n${MissinDisks}\" |tee -a ${ErrorFile}\n\texit 1\nfi\n") printf("set -x\nmkvg -f %s -y %s -s %s %s 2>${TempErrorFile}\nRC=$?\nset +x\n", AutoMount, VGName, PPSize, PVList) printf("if [ ${RC} -ne 0 ]\nthen\n") printf("\tRetCode=$( expr ${RetCode} + ${RC} )\n") printf("\tprint \"ERROR: Unable to create the %s Volume Group.\" |tee -a ${ErrorFile}\n", VGName) printf("\tcat ${TempErrorFile} |tee -a ${ErrorFile}\n") printf("\texit 1\nfi\n") if ( QUORUM == "no" ) { printf("chvg -Qn %s\n", VGName) } i++ } exit RetCode }' | tee -a ${ScriptFile} RetCode=$( expr ${RetCode} + $? ) fi print -u2 "\n\nGathering information for logical volumes.\nThis may take a few minutes...\n" >${TempErrorFile} ############################################### # Get logical volumes for each volume group # # except rootvg. # # The Logical volumes are sorted by type. # # first and then by name. # # This way JFSLOGs will be created first. # ############################################### lsvg -o 2>>${TempErrorFile} |grep -v rootvg |lsvg -i -l 2>>${TempErrorFile} |grep -v -E ":|LV NAME" |sort +2 -r >${TempFile} RetCode=$( expr ${RetCode} + $? ) if [ -s ${TempErrorFile} ] then print "COMMAND:\n\tlsvg\nERROR:\n" >>${ErrorFile} cat ${TempErrorFile} |awk '{ printf("\t%s\n", $0) }' fi ############################################# # Process the logical volume information. # ############################################# cat ${TempFile} |awk -v TempFile=$TempFile -v NoDisk=${NoDisk} -v TempErrorFile=${TempErrorFile} -v ErrorFile=${ErrorFile} -v BT=${BT} -v LVDataFile=${LVDataFile} ' ###################################################################### # Function: CheckErrors # # Purpose: If text is found in the TempErrorFile then the text # # as well as the command "str" will be copied to # # the ErrorFile. # ###################################################################### function CheckErrors(str,TempErrorFile,ErrorFile) { LineCount=0 close(TempErrorFile) while (getline < TempErrorFile > 0) { if ( $0 != "" ) { LineCount++ if ( LineCount == 1 ) { RetCode=1 cmd=sprintf("/bin/ksh -c %s print \"COMMAND:\n\t%s\nERROR:\n\t%s\" >>%s %s", BT, str, $0, ErrorFile, BT) } else { cmd=sprintf("/bin/ksh -c %s print \"\t%s\" >>%s %s", BT, $0, ErrorFile, BT) } system(cmd) } } close(TempFile) } ###################################################################### # Function: ValidLVControlBlock # # Purpose: Checks a raw logical volume and returns "true" if # # it contains a valid Logical Volume Control Block. # # Notes: A Logical Control Block is 512 bytes in length. # # Verified via IBM ticket FH2417. # ###################################################################### function ValidLVControlBlock(LVName) { ############################################################ # Does the Logical Volume Contain a Valid Control Block? # ############################################################ cmd=sprintf("dd count=1 if=/dev/r%s 2>&1 |grep \"^AIX LVCB\" |grep -v -E \"records in|records out\" 1>%s 2>%s", LVName, TempFile, TempErrorFile) system(cmd) ################################ # Check for possible errors. # ################################ RetCode=CheckErrors(cmd,TempErrorFile,ErrorFile) close(TempFile) RC="false" while (getline < TempFile > 0) { if ( index($0, "AIX LVCB") != 0 ) { RC="true" } } close(TempFile) return RC } ###################################################################### # Function: GetPerm # # Purpose: Returns the command needed to recreate the access # # permissions set for a given device, file or file # # system. # ###################################################################### function GetPerm(ObjectName) { cmd=sprintf("ls -ld \"%s\" 1>%s 2>%s", ObjectName, TempFile, TempErrorFile) system(cmd) ################################ # Check for possible errors. # ################################ RetCode=CheckErrors(cmd,TempErrorFile,ErrorFile) close(TempFile) O0=0 O1=0 O2=0 O3=0 if (getline < TempFile > 0) { OWNER=$3 GROUP=$4 PERM=$1 if (substr(PERM,2,1) == "r") { O1=O1+4 } if (substr(PERM,3,1) == "w") { O1=O1+2 } if (substr(PERM,4,1) == "x") { O1=O1+1 } if (substr(PERM,4,1) == "s") { O1=O1+1 O0=O0+4 } if (substr(PERM,4,1) == "S") { O0=O0+4 } if (substr(PERM,5,1) == "r") { O2=O2+4 } if (substr(PERM,6,1) == "w") { O2=O2+2 } if (substr(PERM,7,1) == "x") { O2=O2+1 } if (substr(PERM,7,1) == "s") { O2=O2+1 O0=O0+2 } if (substr(PERM,7,1) == "S") { O0=O0+2 } if (substr(PERM,8,1) == "r") { O3=O3+4 } if (substr(PERM,9,1) == "w") { O3=O3+2 } if (substr(PERM,10,1) == "x") { O3=O3+1 } if (substr(PERM,10,1) == "t") { O3=O3+1 O0=O0+1 } if (substr(PERM,10,1) == "T") { O0=O0+1 } } cmd=sprintf("chown %s%s.%s%s %s%s%s\nchmod %s%d%d%d%d%s %s%s%s\n", BT, OWNER, GROUP, BT, BT, ObjectName, BT, BT, O0, O1, O2, O3, BT, BT, ObjectName, BT) return cmd } ###################################################################### # Function: PrintMakeLVCmd # # Purpose: Outputs commands needed to recreate a Logical # # Volume. # ###################################################################### function PrintMakeLVCmd(LVName,VGName,LVLoc,LPs,StripeSize,LABEL,VRFY,TYPE,MWC,DISKS,MIRROR1,MIRROR2) { print "############################" print "# Create Logical Volume. #" print "############################" printf("#Logical Volume Name: %s\n#\n", LVName) ############################################# # Command to recreate the Logical volume. # ############################################# if ( StripeSize != "" ) { ##################################### # We have a stripped file system. # ##################################### printf("set -x\nmklv -y%s%s%s -a%s%s%s -v%s%s%s -t%s%s%s -S%s%s%s", BT, LVName, BT, BT, LVLoc, BT, BT, VRFY, BT, BT, TYPE, BT, BT, StripeSize, BT) } else { ############################################################## # Check to see if we have a simulated striped file system. # ############################################################## cmd=sprintf("/bin/ksh -c %s print \"%s\" |wc -w >%s %s", BT, DISKS, TempFile, BT) system(cmd) close(TempFile) if (getline < TempFile > 0) { NumDisks=$1 } close(TempFile) if ( NumDisks == UpperBound ) { printf("set -x\nmklv -y%s%s%s -a%s%s%s -v%s%s%s -t%s%s%s -w%s%s%s -ex -u%s%s%s", BT, LVName, BT, BT, LVLoc, BT, BT, VRFY, BT, BT, TYPE, BT, BT, MWC, BT, BT, UpperBound, BT) } else { printf("set -x\nmklv -y%s%s%s -a%s%s%s -v%s%s%s -t%s%s%s -w%s%s%s", BT, LVName, BT, BT, LVLoc, BT, BT, VRFY, BT, BT, TYPE, BT, BT, MWC, BT) } } if ( LABEL != "" ) { printf(" -L %s%s%s", BT, LABEL, BT) } if ( NoDisk == "FALSE" ) { printf(" %s%s%s %s%s%s %s", BT, VGName, BT, BT, LPs, BT, DISKS) } else { printf(" %s%s%s %s%s%s", BT, VGName, BT, BT, LPs, BT) } printf(" 2>${TempErrorFile}\nRC=$?\nset +x\nif [ ${RC} -ne 0 ]\nthen\n") printf("\tRetCode=$( expr ${RetCode} + ${RC} )\n") printf("\tprint ${LVFAILED}\n\tLVFAILED=\"${LVFAILED} %s\"\n", LVName) printf("\tprint \"ERROR: Unable to create the %s Logical Volume.\" |tee -a ${ErrorFile}\n", LVName) printf("\tcat ${TempErrorFile} |tee -a ${ErrorFile}\n") printf("fi\n") if ( NoDisk == "FALSE" ) { if ( MIRROR1 != "" ) { print "###################################" print "# Create Logical Volume Mirror. #" print "###################################" printf("set -x\nmklvcopy %s%s%s 2 %s 2>${TempErrorFile}\nRC=$?\nset +x\n", BT, LVName, BT, MIRROR1) if ( MIRROR2 != "" ) { printf("set -x\nmklvcopy %s%s%s 3 %s 2>>${TempErrorFile}\nRC2=$?\nset +x\n", BT, LVName, BT, MIRROR2) } else { print "RC2=0" } printf("if [ ${RC} -ne 0 ] || [ ${RC2} -ne 0 ]\nthen\n") printf("\tRetCode=$( expr ${RetCode} + ${RC} )\n") printf("\tLVCFAILED=\"${LVCFAILED} %s\"\n", LVName) printf("\tprint \"ERROR: Unable to mirror the %s Logical Volume.\" |tee -a ${ErrorFile}\n", LVName) printf("\tcat ${TempErrorFile} |tee -a ${ErrorFile}\n") printf("fi\n") } } if ( TYPE == "jfslog" ) { print "####################" print "# Format JFS Log #" print "####################" printf("set -x\nprint \"y\" | /usr/sbin/logform /dev/%s\nset +x\n", LVName) } } ###################################################################### # Function: BuildFSLogTable # # Purpose: Build table with File System Name as index and log # # device as the value. # ###################################################################### function BuildFSLogTable( Table ) { cmd=sprintf("grep -E \":|log\" /etc/filesystems 1>%s 2>%s", TempFile, TempErrorFile) system(cmd) ################################ # Check for possible errors. # ################################ RetCode=CheckErrors(cmd,TempErrorFile,ErrorFile) close(TempFile) FSName="" LogDevice="" while (getline < TempFile > 0) { ################################ # File System Name was read. # ################################ if ( (i=index($1,":")) == length($1) ) { ############################################# # Write information for last file system. # ############################################# if ( FSName != "" ) { Table[FSName] = LogDevice #printf("FS=%s\tLOG=%s\n", FSName, Table[FSName]) } ########################################## # Initialize for new file system to be # # processed. # ########################################## LogDevice="" FSName=substr($1,1,i-1) } else if ( $1 == "log" ) { ############################################### # Not all file systems specify a log device # # for some reason. # ############################################### LogDevice=$3 } } ############################################ # Save information for last file system. # ############################################ if ( FSName != "" ) { Table[FSName] = LogDevice #printf("FS=%s\tLOG=%s\n", FSName, Table[FSName]) } close(TempFile) } BEGIN { RetCode=0 BuildFSLogTable( FSLogTable ) print "\n##############################################" print "# Commands needed to recreate LVs and FSs. #" print "##############################################\n" } { ######################################## # Get attributes for logical volume. # ######################################## LVName=$1 FSName=$7 VGName="" LVLoc="" LPs="" StripeSize="" LABEL="" VRFY="" TYPE="" MWC="" cmd=sprintf("lslv %s 1>%s 2>%s", LVName, TempFile, TempErrorFile) system(cmd) ################################ # Check for possible errors. # ################################ RetCode=CheckErrors(cmd,TempErrorFile,ErrorFile) close(TempFile) while (getline < TempFile > 0) { if ( $1 == "LPs:" ) { LPs=$2 }else if ( $1 == "INTRA-POLICY:" ) { if ( $2 == "middle" ) { LVLoc="m" } else if ( $2 == "center" ) { LVLoc="c" } else if ( $2 == "edge" ) { LVLoc="e" } else if ( $2 == "inner" ) { if ( $3 == "middle" ) { LVLoc="im" } else if ( $3 == "edge" ) { LVLoc="ie" } } } else if ( $1 == "TYPE:" ) { TYPE=$2 } else if ( $1 == "MIRROR" ) { if ( tolower($4) == "on" ) { MWC="y" } else { MWC="n" } } else if ( $1 == "STRIPE" ) { StripeSize=$3 } if ( $3 == "UPPER" ) { UpperBound=$5 } if ( $4 == "VOLUME" ) { VGName=$6 } else if ( $4 == "LABEL:" ) { if ( tolower($5) != "none" ) { LABEL=$5 } } else if ( $4 == "VERIFY:" ) { if ( tolower($5) == "off" ) { VRFY="n" } else { VRFY="y" } } } close(TempFile) ################################################ # Get Disks that contain the logical volume. # ################################################ cmd=sprintf(">%s;lslv -m %s 2>>%s |grep -v -E \":|PV3\" |sort -u +2 -3 +4 -1 +6 >%s 2>>%s ", TempErrorFile, LVName, TempErrorFile, TempFile, TempErrorFile) system(cmd) ################################ # Check for possible errors. # ################################ RetCode=CheckErrors(cmd,TempErrorFile,ErrorFile) close(TempFile) DISKS="" MIRROR1="" MIRROR2="" while (getline < TempFile > 0) { if ( index(DISKS, $3) == 0 ) { DISKS=sprintf("%s %s", DISKS, $3) } if ( $5 != "" ) { if ( index(MIRROR1, $5) == 0 ) { MIRROR1=sprintf("%s %s", MIRROR1, $5) } } if ( $7 != "" ) { if ( index(MIRROR2, $7) == 0 ) { MIRROR2=sprintf("%s %s", MIRROR2, $7) } } } close(TempFile) #################################################### # If a file system is defined for Logical Volume # # then get options for the file system. # #################################################### if ( FSName != "N/A" ) { cmd=sprintf("lsfs -q -c %s 2>%s |grep -E \"%s|lv size\" >%s", FSName, TempErrorFile, LVName, TempFile) system(cmd) ################################ # Check for possible errors. # ################################ RetCode=CheckErrors(cmd,TempErrorFile,ErrorFile) close(TempFile) OPTIONS="" VFS="" Auto="" Accounting="" FRAG="" COMPRESS="" while (getline < TempFile > 0) { iArgCnt=split($0,ARGS,":") if ( index($0, LVName) != 0 ) { VFS=ARGS[3] OPTIONS=ARGS[7] Auto=ARGS[8] Accounting=ARGS[9] } else if ( index($0, "frag size") != 0 ) { i=1 while (i <= iArgCnt) { str=ARGS[i] if ( (j=index(str, "frag size")) != 0 ) { str=substr(str,j+10) if ( (j=index(str,")")) != 0 ) { str=substr(str,1,j-1) } FRAG=str } else if ( (j=index(str, "compress")) != 0 ) { str=substr(str,j+9) if ( (j=index(str,")")) != 0 ) { str=substr(str,1,j-1) } COMPRESS=str } i++ } } } printf("############################################\n") printf("# Check to see if Logical Volume exists. #\n") printf("############################################\n") printf("lslv %s 1>/dev/null 2>/dev/null\nLVRC=$?\n", LVName) printf("#####################################################\n") printf("# If Logical Volume does not exist then make sure #\n") printf("# that the file system definition does not exist. #\n") printf("#####################################################\n") printf("if [ ${LVRC} -ne 0 ]\nthen\n") printf("\tgrep %s%s:%s /etc/filesystems 1>/dev/null 2>/dev/null\n\tGREPRC=$?\n", BT, FSName, BT) printf("\tif [ ${GREPRC} -eq 0 ]\n\tthen\n") printf("\t\t###################################################\n") printf("\t\t# Logical Volume does not exist but file system #\n") printf("\t\t# definition was found in /etc/filesystems. #\n") printf("\t\t# Remove file system definition. #\n") printf("\t\t###################################################\n") printf("\t\tset -x\n") printf("\t\trmfs %s%s%s\n", BT, FSName, BT) printf("\t\tset +x\n") printf("\tfi\n") printf("fi\n") PrintMakeLVCmd(LVName,VGName,LVLoc,LPs,StripeSize,LABEL,VRFY,TYPE,MWC,DISKS,MIRROR1,MIRROR2) printf("#########################\n") printf("# Create file system. #\n") printf("#########################\n") printf("set -x\n") cmd=sprintf("crfs -v %s%s%s -d %s%s%s -m %s%s%s -A %s%s%s -p %s%s%s -t %s%s%s", BT, VFS, BT, BT, LVName, BT, BT, FSName, BT, BT, Auto, BT, BT, OPTIONS, BT, BT, Accounting, BT) if ( FRAG != "" ) { cmd=sprintf("%s -a %sfrag=%s%s", cmd, BT, FRAG, BT) } if ( COMPRESS != "" ) { cmd=sprintf("%s -a %scompress=%s%s", cmd, BT, COMPRESS, BT) } printf("%s 2>${TempErrorFile}\nRC=$?\nset +x\n", cmd) printf("if [ ${RC} -ne 0 ]\nthen\n") printf("\tRetCode=$( expr ${RetCode} + ${RC} )\n") printf("\tFSFAILED=\"${FSFAILED} %s\"\n", FSName) printf("\tprint \"ERROR: Unable to create the %s File System.\" |tee -a ${ErrorFile}\n", FSName) printf("\tcat ${TempErrorFile} |tee -a ${ErrorFile}\n") printf("fi\n") if ( FSLogTable[FSName] != "" ) { print "#####################################################" print "# Make sure the file system uses correct JFS log. #" print "#####################################################" printf("set -x\nchfs -a log=\"%s\" \"%s\"\nset +x\n", FSLogTable[FSName], FSName) } printf("set -x\nmount %s%s%s\n", BT, FSName, BT) ObjectName=FSName cmd=GetPerm(ObjectName) printf("%s", cmd) printf("set +x\n") ##################################################################### # The Current Logical Volume is not asociated with a File System. # ##################################################################### } else { PrintMakeLVCmd(LVName,VGName,LVLoc,LPs,StripeSize,LABEL,VRFY,TYPE,MWC,DISKS,MIRROR1,MIRROR2) printf("#########################################\n") printf("# Set permissions for Logical Volume. #\n") printf("#########################################\n") print "set -x" ObjectName=sprintf("/dev/%s", LVName) #Block Device cmd=GetPerm(ObjectName) printf("%s", cmd) ObjectName=sprintf("/dev/r%s", LVName) #Character Device cmd=GetPerm(ObjectName) printf("%s", cmd) print "set +x" ########################################################### # If the current logical volume is not asociated with a # # file system and the current logical volume is not a # # JFS log then check to see if it has a valid logical # # volume control block. # ########################################################### if ( TYPE != "jfslog" ) { ############################################# # Does the Logical Volume contain a valid # # Control Block. # ############################################# if ( ValidLVControlBlock(LVName) == "true" ) { print "#########################################" print "# Valid Logical Volume Control Block. #" print "#########################################" printf("#Logical Volume Name: %s\n#\n", LVName) cmd=sprintf("/bin/ksh -c %s print \"%s:8\" >>%s %s", BT, LVName, LVDataFile, BT) system(cmd) } else { print "###########################################" print "# Invalid Logical Volume Control Block. #" print "###########################################" printf("#Logical Volume Name: %s\n#\n", LVName) cmd=sprintf("/bin/ksh -c %s print \"%s:0\" >>%s %s", BT, LVName, LVDataFile, BT) system(cmd) } } } print "" } END { printf("print \"\\n\\n\\n\"\n") printf("if [ \"${LVFAILED}\" != \"\" ]\nthen\n\tprint \"\\nThe following logical volumes where not created successfully:\" >> ${ErrorFile}\n") printf("\tfor s in ${LVFAILED}\n\tdo\n\t\tprint \"\\t${s}\" >> ${ErrorFile}\n\tdone\nfi\n") printf("if [ \"${LVCFAILED}\" != \"\" ]\nthen\n\tprint \"\\nThe following logical volumes where not mirrored successfully:\" >> ${ErrorFile}\n") printf("\tfor s in ${LVCFAILED}\n\tdo\n\t\tprint \"\\t${s}\" >> ${ErrorFile}\n\tdone\nfi\n") printf("if [ \"${FSFAILED}\" != \"\" ]\nthen\n\tprint \"\\nThe following file systems where not created successfully:\" >> ${ErrorFile}\n") printf("\tfor s in ${FSFAILED}\n\tdo\n\t\tprint \"\\t${s}\" >> ${ErrorFile}\n\tdone\nfi\n") printf("if [ -s ${ErrorFile} ]\nthen\n\tprint \"Errors encountered during execution:\"\n\tcat ${ErrorFile}\nfi\n") exit RetCode }' | tee -a ${ScriptFile} RetCode=$( expr ${RetCode} + $? ) ################################################### # Generate "syncvg" commands for all non-rootvg # # volume groups. # ################################################### lsvg -o |grep -v rootvg |awk ' BEGIN { print "\n######################################################" print "# Commands needed to syncronize the volume groups. #" print "######################################################\n" print "at now <>${ErrorFile} RetCode=$( expr ${RetCode} + 1 ) fi ########################################### # Display any errors that have occured. # ########################################### if [ -s ${ErrorFile} ] then RetCode=$( expr ${RetCode} + 1 ) print "The following errors were detected during execution.\n" cat ${ErrorFile} fi rm -f ${FileList} exit ${RetCode}