#!/bin/ksh93 # ALTRAN_PROLOG_BEGIN_TAG # This is an automatically generated prolog. # # Copyright (C) Altran ACT S.A.S. 2019,2021. All rights reserved. # # ALTRAN_PROLOG_END_TAG # @(#) 7d4c34b 43haes/lib/ksh93/hacmp/KLIB_HACMP_compare_snapshot.sh, 726, 2147A_aha726, Feb 05 2021 09:50 PM #============================================================================ # # Name: KLIB_HACMP_compare_snapshot # # Description: This is the main, FPATH function that is invoked by clmgr # to compare snapshot. It uses the "clsnapshot" utility # with the "preview" option to generate a report. # # Inputs: See the "devDoc()" function at the bottom of this file. # # Outputs: Output from the clsnapshot preview. # # Returns: Zero if no errors are detected. Otherwise, an appropriate # non-zero value is returned. Refer to the "RETURN" section # of the "devDoc()" function at the bottom of this file for # the standard return code values/meanings for clmgr. # #============================================================================ function KLIB_HACMP_compare_snapshot { . $HALIBROOT/log_entry "$0()" "$CL" : version="@(#) 7d4c34b 43haes/lib/ksh93/hacmp/KLIB_HACMP_compare_snapshot.sh, 726, 2147A_aha726, Feb 05 2021 09:50 PM" : INPUTS: $* typeset snapshots=${1//\"/} typeset SNAPSHOTPATH=${2//\"/} typeset SECTION=${3//\"/} typeset PAGER=${4//\"/} typeset SDIFF_OUTPUT_WIDTH=${5//\"/} typeset SDIFF_FLAGS=${6//\"/} [[ $CLMGR_LOGGING == 'med' ]] && set +x # Only trace param values #=================================== : Declare and initialize variables #=================================== typeset -i rc=$RC_UNKNOWN typeset MSG="" typeset Sopt="" #=================================== : Validate inputs #=================================== # "clsnapshot compare" takes 2 names which can be keywords, full path # names, snapshot names or a combination - see the devDoc for details - # no matter what they must be comma separated, so we begin by checking # for that if [[ $snapshots == *([[:space:]]) || $snapshots != *,* ]] then cl_dspmsg -s $CLMGR_SET $CLMGR_MSGS 200 "\nERROR: missing required argument: %1\$s\n" "," 1>&2 rc=$RC_MISSING_INPUT # additional help message will be printed below fi # Oddly, clsnapshot takes a few things from the env where there is no # command line equivalent to do the same thing - so we shall take the # clmgr inputs, verify them as best we can, and export them to the shell # before invoking clsnapshot # SNAPSHOTPATH must be an absolute path if [[ -n $SNAPSHOTPATH ]] then if [[ $SNAPSHOTPATH != /* ]]; then MSG=$(dspmsg -s $CLMGR_SET $CLMGR_MSGS 106 "\nERROR: the specified path/file does not appear to be in absolute format:\n%1\$s\n\n" "$SNAPSHOTPATH") MSG="$MSG (SNAPSHOTPATH @ $LOCAL_NODE)" cl_dspmsg -s $CLMGR_SET $CLMGR_MSGS -1 "${MSG//+([[:space:]])/ }" 1>&2 rc=$RC_INCORRECT_INPUT else export CLSNAPSHOT_SNAPSHOTPATH=$SNAPSHOTPATH fi fi # clsnapshot itself will check if any specified section is valid # and exists in both snapshots, so we do no explicit check of the optional # SECTION input here [[ $SECTION != *([[:space:]]) ]] && Sopt="-S $SECTION" # According to the man page for sdiff the output width must be in the # range of 20 - 2048, but in reality it will throw an error if 20 is # used, so we go with 21 here if [[ -n $SDIFF_OUTPUT_WIDTH ]] then CL=$LINENO verify_numeric_range "$SDIFF_OUTPUT_WIDTH" 21 2048 SDIFF_OUTPUT_WIDTH if (( $? != RC_SUCCESS )) then rc=$RC_INCORRECT_INPUT else export CLSNAPSHOT_SDIFF_OUTPUT_WIDTH=$SDIFF_OUTPUT_WIDTH fi fi # Check "pager" and "flags" for shell execution characters, otherwise # we just export them as is if [[ -n $PAGER ]] then if [[ $PAGER == *@(\`|\$\(|\|)* ]] then dspmsg -s $CLVT_SET $CLVT_MSGS 133 "\nERROR: the \"%1\$s\" option contains a shell execution character: %2\$s\n\n" PAGER "$PAGER" 1>&2 rc=$RC_INCORRECT_INPUT else # make sure it exists if [[ ! -x $PAGER ]] then MSG=$(dspmsg -s $CLMGR_SET $CLMGR_MSGS 107 '\nERROR: the specified path/file does not appear to exist on "%2$s": %1$s\n\n' "$PAGER" $(hostname)) MSG="$MSG (PAGER)" cl_dspmsg -s $CLMGR_SET $CLMGR_MSGS -1 "${MSG//+([[:space:]])/ }" 1>&2 rc=$RC_NOT_FOUND else export CLSNAPSHOT_PAGER=$PAGER fi fi fi if [[ -n $SDIFF_FLAGS ]] then if [[ $SDIFF_FLAGS == *@(\`|\$\(|\|)* ]] then dspmsg -s $CLVT_SET $CLVT_MSGS 133 "\nERROR: the \"%1\$s\" option contains a shell execution character: %2\$s\n\n" SDIFF_FLAGS "$SDIFF_FLAGS" 1>&2 rc=$RC_INCORRECT_INPUT else export CLSNAPSHOT_SDIFF_FLAGS=$SDIFF_FLAGS fi fi #=================================================== : Invoke clsnapshot for the comparison - clsnapshot takes care of : all additional input validation #=================================================== if (( $rc == RC_UNKNOWN )) then print "$0()[$LINENO]($SECONDS): clsnapshot $Sopt -p $snapshots " >>$CLMGR_TMPLOG # Always log commands clsnapshot $Sopt -p $snapshots 2>>$CLMGR_TMPLOG rc=$? print "$0()[$LINENO]($SECONDS): clsnapshot RC=$rc" >>$CLMGR_TMPLOG # Always log command result if (( $rc != RC_SUCCESS )); then # clsnapshot will have shown detailed error information dspmsg -s $CLMGR_SET $CLMGR_MSGS 109 "\nERROR: the operation appears to have failed.\n\n" 1>&2 rc=$RC_ERROR fi fi #======================================================================= : If a user input error was detected, provide some helpful suggestions #======================================================================= if (( $rc == RC_MISSING_INPUT || $rc == RC_INCORRECT_INPUT )) && \ [[ $CLMGR_GUI == *([[:space:]]) ]] then print -u2 "" cl_dspmsg -s $CLMGR_SET $CLMGR_MSGS 104 "For more information about available options and syntax, try\n\"$HAUTILS/clmgr %1\$s\". As an\nalternative, if the PowerHA SystemMirror man pages have been installed, invoke\n\"$HAUTILS/clmgr -hv\" (or \"/usr/bin/man clmgr\"),\nsearching for \"%2\$s\" in the displayed text.\n\n" \ "compare snapshot -h" "SNAPSHOT:" "$CLMGR_PROGNAME" 1>&2 fi log_return_msg "$rc" "$0()" "$LINENO" return $? } #============================================================================ # # Name: devDoc # # Description: This is a never-to-be-called, wrapper function that all the # clmgr FPATH functions implement in order to hide embedded # syntax from trace logging. This information is implemented # in POD format, and can be viewed in a number of ways using # POD tools. Some viewing suggestions for this function's POD- # formatted information are: # # perldoc # pod2text -c # pod2text -c --code # pod2html # # However, the more important use for this information is that # it is parsed by clmgr to display the syntax for this file's # operation. The information in the "SYNOPSIS" section is used # for this purpose even if the man pages are installed. # As a result of this, it is imperative that the information in # this SYNOPSIS be kept in sync with the man page information. # # Inputs: None. # # Outputs: None. # # Returns: n/a (not intended to be invoked) # #============================================================================ function devDoc { : <<'=cut' >/dev/null 2>&1 =head1 NAME KLIB_HACMP_compare_snapshot =head1 SYNOPSIS clmgr compare snapshot , \ [ SNAPSHOTPATH="/absolute/path/to/search/for/snapshots" ] \ [ SECTION="list,of,sections,to,compare" ] \ [ PAGER="pager_command" ] \ [ SDIFF_OUTPUT_WIDTH="21 .. 2048" ] \ [ SDIFF_FLAGS="flags_for_sdiff" ] NOTE: the alias for "snapshot" is "sn". =head1 DESCRIPTION Compares the specified snapshots. =head1 ARGUMENTS 1. snapshots [REQUIRED] string Comma separated list of two entities to compare. Either entity can be: o a snapshot name. o full path (begins with "/") to a snapshot file including the ".odm" suffix. o the keyword "DCD" to compare the configuration in the Default Configuration Directory. o the keyword "ACD" to compare the configuration in the Active Configuration Directory. If the first entity is not specified, it defaults to the DCD. If the second entity is not specified, it defaults to the ACD. 2. SNAPSHOTPATH [OPTIONAL] string Path to use when searching for snapshots. Must begin with "/". Default is "/usr/es/sbin/cluster/snapshots". If a full path to a snapshot is given, this input is ignored. 3. SECTION [OPTIONAL] string Comma separated list of sections to compare between the 2 snapshots provided. Note this is only valid with the "compare" action of clmgr. 4. PAGER [OPTIONAL] string Compare snapshot uses "sdiff" to generate differences and the sdiff output is then displayed using "pg" by default. This argument can be used to specify a different command other than "pg". 5. SDIFF_OUTPUT_WIDTH [OPTIONAL] integer The sdiff command can produce results with a specific width which defaults to 200 columns. This input can be used to sepcify a different width, between 21 and 2048 columns. 6. SDIFF_FLAGS [OPTIONAL] string Any additional flags to be passed to the sdiff command. =head1 RETURN 0: no errors were detected; the operation appears to have been successful 1: a general error has occurred 2: a specified resource does not exist, or could not be found 3: some required input was missing 4: some detected input was incorrect in some way 5: a required dependency does not exist 6: a specified search failed to match any data =cut } # End of "devDoc()" #============================================================================== # The following, comment block attempts to enforce coding standards when this # file is edited via emacs or vim. This block _must_ appear at the very end # of the file, or the editor will not find it, and it will be ignored. #============================================================================== # Local Variables: # indent-tabs-mode: nil # tab-width: 4 # End: #============================================================================== # vim: tabstop=4 shiftwidth=4 expandtab #==============================================================================