#@(#)87 1.6.1.3 src/bos/usr/lib/nim/methods/c_restvg.sh, cmdnim, bos720, 1508A_720 1/27/15 21:23:19 # IBM_PROLOG_BEGIN_TAG # This is an automatically generated prolog. # # bos720 src/bos/usr/lib/nim/methods/c_restvg.sh 1.6.1.3 # # Licensed Materials - Property of IBM # # Restricted Materials of IBM # # COPYRIGHT International Business Machines Corp. 2002,2015 # All Rights Reserved # # US Government Users Restricted Rights - Use, duplication or # disclosure restricted by GSA ADP Schedule Contract with IBM Corp. # # IBM_PROLOG_END_TAG # COMPONENT_NAME: CMDNIM # # FUNCTIONS: ./usr/lib/nim/methods/c_restvg.sh # # # ORIGINS: 27 # # # (C) COPYRIGHT International Business Machines Corp. 2002 # All Rights Reserved # Licensed Materials - Property of IBM # US Government Users Restricted Rights - Use, duplication or # disclosure restricted by GSA ADP Schedule Contract with IBM Corp. # include common NIM shell defines/functions NIMPATH=${0%/*} NIMPATH=${NIMPATH%/*} [[ ${NIMPATH} = ${0} ]] && NIMPATH=/usr/lpp/bos.sysmgt/nim NIM_METHODS="${NIMPATH}/methods" . ${NIM_METHODS}/c_sh_lib #---------------------------- local defines -------------------------------- EXCLUDE_ROOTVG=/etc/exclude.rootvg RESTVG=/usr/bin/restvg savevg_mnt_dir="" #---------------------------- module globals -------------------------------- REQUIRED_ATTRS="savevg" OPTIONAL_ATTRS="disk group verbose vg_data shrink map block partition vg_data_only" savevg="" disk="" vg_data="" vg_data_access="" savevg_access="" shrink="" map="" block="" partition="" vg_data_only="" #---------------------------- alloc_resource -------------------------------- # # NAME: alloc_resource # # FUNCTION: # allocates the specified resource # # EXECUTION ENVIRONMENT: # # NOTES: # calls error on failure # # RECOVERY OPERATION: # # DATA STRUCTURES: # parameters: # res = resource to alloc in form of = # global: # # RETURNS: (int) # 0 = success # 1 = failure # # OUTPUT: #------------------------------------------------------------------------------- function alloc_resource { typeset res_type=${1%%=*} typeset res_name=${1##*=} # make sure the /NIM_BOS_IMAGE directory exists if [[ ! -d /NIM_BOS_IMAGE ]] then ${MKDIR} /NIM_BOS_IMAGE 2>${ERR} || err_from_cmd ${MKDIR} fi # use nimclient to allocate the resource ${NIMCLIENT} -o allocate -a ${res_type}=${res_name} -a force=yes \ -a ignore_state=yes 2>${ERR} || \ err_from_cmd ${NIMCLIENT} } # end of alloc_resource #---------------------------- dealloc_resource -------------------------------- # # NAME: dealloc_resource # # FUNCTION: # deallocates the specified resource # # EXECUTION ENVIRONMENT: # # NOTES: # calls error on failure # # RECOVERY OPERATION: # # DATA STRUCTURES: # parameters: # res = resource to dealloc in form of = # global: # # RETURNS: (int) # 0 = success # 1 = failure # # OUTPUT: #------------------------------------------------------------------------------- function dealloc_resource { typeset res_type=${1%%=*} typeset res_name=${1##*=} # use nimclient to deallocate the resource ${NIMCLIENT} -o deallocate -a ${res_type}=${res_name} -a force=yes \ -a ignore_state=yes 2>${ERR} || \ err_from_cmd ${NIMCLIENT} } # end of dealloc_resource #----------------------------- c_restvg ------------------------------------- # # NAME: c_restvg # # FUNCTION: # # # EXECUTION ENVIRONMENT: # # NOTES: # # RECOVERY OPERATION: # # DATA STRUCTURES: # parameters: # global: # # RETURNS: (int) # 0 = no errors # >0 = failure # # OUTPUT: #-----------------------------------------------------------------------------*/ function c_restvg { # check that bos.sysmgt.sysbr (System Backup and BOS Install Utilities) is installed STATE=`${LSLPP} -qcIL bos.sysmgt.sysbr 2>/dev/null | ${CUT} -d":" -f6` if [[ "${STATE}" != "C" ]]; then nim_name=`${GREP} $NIM_NAME ${NIMINFO} | ${CUT} -d"=" -f2` error ${ERR_NO_SYSBR} ${nim_name} fi # Allocate the savevg resource if it is client initiated # if client initiated, savevg will be in the form savevg= # if master initiated, savevg will be in the form savevg=: ${ECHO} ${savevg} | ${GREP} -q ":" client_initiated=$? if [[ ${client_initiated} -ne 0 ]]; then savevg_resource=${savevg} alloc_resource savevg=${savevg} location=`${NIMCLIENT} -l -l ${savevg} | ${GREP} "location" | ${SED} 's/ //g' | ${CUT} -d"=" -f2` server=`${NIMCLIENT} -l -l ${savevg} | ${GREP} "server" | ${SED} 's/ //g' | ${CUT} -d"=" -f2` if [[ ${server} = "master" ]]; then savevg=${NIM_MASTER_HOSTNAME}:${location} else savevg=${server}:${location} fi fi # mount the savevg resource so that we can restvg nim_mount ${savevg} savevg_access=${access_pnt} if [[ -n $vg_data ]]; then if [[ ${client_initiated} -ne 0 ]]; then vg_data_resource=${vg_data} alloc_resource vg_data=${vg_data} location=`${NIMCLIENT} -l -l ${vg_data} | ${GREP} "location" | ${SED} 's/ //g' | ${CUT} -d"=" -f2` server=`${NIMCLIENT} -l -l ${vg_data} | ${GREP} "server" | ${SED} 's/ //g' | ${CUT} -d"=" -f2` if [[ ${server} = "master" ]]; then vg_data=${NIM_MASTER_HOSTNAME}:${location} else vg_data=${server}:${location} fi fi # mount the vg_data resource # going to create a tmp directory at "/tmp/$$.mnt" # look for lowest, unused seqno typeset -i idx=0 while (( ${idx} < ${MAX_MNT} )) do vg_data_mnt_dir="/tmp/$$.mnt${idx}" [[ ! -d ${vg_data_mnt_dir} ]] && break let idx=idx+1 done (( ${idx} >= ${MAX_MNT} )) && error ${ERR_GEN_SEQNO} /tmp/$$.mnt ${MKDIR} ${vg_data_mnt_dir} 2>${ERR} || err_from_cmd ${MKDIR} nim_mount ${vg_data} ${vg_data_mnt_dir} vg_data_access=${vg_data_mnt_dir} # Now that we can access vg_data, we need to get some info from it. if [[ -z $disk ]]; then disk=`${CAT} ${vg_data_access} | ${GREP} VG_SOURCE_DISK_LIST | ${CUT} -f2 -d'='` fi fi disk=`${ECHO} $disk | ${AWK} '{hdisk=$0; gsub(/,/, " ", hdisk); print hdisk;}'` if [[ $shrink = "yes" ]]; then shrink="-s"; fi if [[ $map = "no" ]]; then map="-n"; else map=""; fi # check vg resource for vg_data_only flag if [[ -z $vg_data_only ]]; then vg_data_only=`${LSMKSYSB} -l -f ${savevg_access} | ${AWK} '/VG DATA ONLY:/ {print $4}'` fi # VG data only ? then add '-r' flag if [[ $vg_data_only = "yes" ]]; then vg_data_only="-r"; else vg_data_only=""; fi # call restvg to restore the image # ${parameter:-word} if parameter is undefine, subsitutes word # ${parameter:+word} if parameter is not empty, substitutes word ${RESTVG} -q \ ${vg_data:+-d $vg_data_access} \ ${shrink} \ ${map} \ ${vg_data_only} \ ${block:+-b $block} \ ${partition:+-P $partition} \ ${savevg_access:+-f $savevg_access} \ ${disk} # return code from restvg RC=$? # unmount the savevg resouce nim_unmount ${savevg_access} if [[ ${client_initiated} -ne 0 ]]; then dealloc_resource savevg=${savevg_resource} fi # unmount the vg_data resource if [[ -n $vg_data_access ]]; then nim_unmount ${vg_data_access} # Check to see if the unmount failed. If it failed then # leave the temporary directory there. We don't want to # inadvertently erase extra files. ${MOUNT} | ${EGREP} -q ${vg_data_mnt_dir} if [[ $? -ne 0 ]]; then ${RM} -r ${vg_data_mnt_dir} fi if [[ ${client_initiated} -ne 0 ]]; then dealloc_resource vg_data=${vg_data_resource} fi fi return $RC } # end c_restvg #------------------------------- MAIN --------------------------------------- # signal processing trap cleanup 0 trap err_signal 1 2 11 15 # NIM initialization nim_init # set parameters from command line while getopts :a:qv c do case ${c} in a) # validate the attr ass parse_attr_ass "${OPTARG}" # include the assignment for use in this environment eval ${variable}=\"${value}\" ;; q) # show attr info cmd_what exit 0 ;; v) # verbose mode (for debugging) set -x for i in $(typeset +f) do typeset -ft $i done ;; \?) # unknown option error ${ERR_BAD_OPT} ${OPTARG} ;; esac done # check for missing attrs ck_attrs # run restvg c_restvg #exit with return code from c_restvg exit $?