#!/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 # # IBM_PROLOG_BEGIN_TAG # This is an automatically generated prolog. # # 61haes_r720 src/43haes/lib/ksh93/hacmp/KLIB_HACMP_add_snapshot.sh 1.9 # # Licensed Materials - Property of IBM # # COPYRIGHT International Business Machines Corp. 1990,2010 # 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 # @(#) 7d4c34b 43haes/lib/ksh93/hacmp/KLIB_HACMP_add_snapshot.sh, 726, 2147A_aha726, Feb 05 2021 09:50 PM #============================================================================ # # Name: KLIB_HACMP_add_snapshot # # Description: This is the main, FPATH function that is invoked by clmgr # to create a snapshot of the cluster configuration. The # backup includes all the SystemMirror ODMs, along with an # information file that provides a "picture" of the state # of the system at the time the snapshot was taken. # # Inputs: Refer to the "devDoc()" function, below. # # Outputs: No explicit outputs, other than the normal clsnapshot # output, along with any error messages that might be needed. # # Returns: Zero if no errors are detected. Otherwise, an appropriate # non-zero value is returned. Refer to the "RETURN" section # of the "devDoc()" function, below, for the standard return # code values/meanings for clmgr. # #============================================================================ function KLIB_HACMP_add_snapshot { . $HALIBROOT/log_entry "$0()" "$CL" : version=@(#) 7d4c34b 43haes/lib/ksh93/hacmp/KLIB_HACMP_add_snapshot.sh, 726, 2147A_aha726, Feb 05 2021 09:50 PM : INPUTS: $* typeset -n properties=$1 typeset snapshot=${2//\"/} typeset description=${3#\"} description=${description%\"} typeset methods=${4//\"/} methods=${methods//,/ } typeset -l misc_info=${5//\"/} [[ $CLMGR_LOGGING == 'med' ]] && set +x # Only trace param values #================================================================ : Check for a defined cluster. No need to continue without one. #================================================================ CL=$LINENO isClusterDefined if (( $? != RC_SUCCESS )); then log_return_msg "$RC_MISSING_DEPENDENCY" "$0()" "$LINENO" return $? # Bail out now. Nothing to take a snapshot of. fi #=================================== : Declare and initialize variables #=================================== typeset mOpt= typeset -i rc=$RC_UNKNOWN [[ -n $methods ]] && mOpt=" -m '$methods'" # clsnapshot honors an optional user specified path - it can be set with # an environment variable (but not via command line) - set a default # here if none exists if [[ -z $SNAPSHOTPATH || ! -d $SNAPSHOTPATH ]]; then SNAPSHOTPATH=/usr/es/sbin/cluster/snapshots fi #================= : Validate inputs #================= if [[ -z $snapshot ]]; then dspmsg -s $CLMGR_SET $CLMGR_MSGS 100 "\nERROR: a name/label must be provided.\n\n" 1>&2 rc=$RC_MISSING_INPUT fi #============================================================ : Create the snapshot if no input errors have been detected #============================================================ if (( $rc == RC_UNKNOWN )); then [[ $description == *([[:space:]]) ]] && description="$(cllsclstr -N), $(LC_ALL=C date)" # clsnapshot can create a .info file with the output of various # system commands (lsvg, netstat, etc) - there is nothing in PowerHA # that utilizes this information, but for compatibility we force it # if called from the gui or the user requests it typeset iOpt="" [[ $CLMGR_GUI == "SMUI" ]] && iOpt="-i " [[ -n $misc_info && $misc_info == @(y|e|t|1)* ]] && iOpt="-i " # Output from any user specified method(s) goes in the .info # file, so if they have specified custom method(s) then we automatically # assume they want a .info file [[ -n "$mOpt" ]] && iOpt="-i " print "$0()[$LINENO]($SECONDS): clsnapshot -c $iOpt -n \"$snapshot\"$mOpt -d \"$description\"" >>$CLMGR_TMPLOG # Always log commands : Provide escaping for some characters that are not safe in an eval description=${description//\$\(/\\\$\(} description=${description//\`/\\\`} description=${description//\"/\\\"} : Provide character entity replacement, a la HTML description=${description//\&apos\;/\'} description=${description//\"\;/\\\"} description=${description//\<\;/\<} description=${description//\>\;/\>} description=${description//\&\;/\&} description=${description//\&excl\;/\!} eval "clsnapshot -c $iOpt -n \"$snapshot\"$mOpt -d \"$description\"" rc=$? print "$0()[$LINENO]($SECONDS): clsnapshot RC: $rc" >>$CLMGR_TMPLOG # Always log command result if (( $rc == RC_SUCCESS )); then # command succeeded, but check the file was created anyway [[ ! -s $SNAPSHOTPATH/$snapshot.odm ]] && rc=$RC_ERROR fi if (( $rc != RC_SUCCESS )); then dspmsg -s $CLMGR_SET $CLMGR_MSGS 201 '\nERROR: failed to create "%1$s".\n\n' "$snapshot" 1>&2 rc=$RC_ERROR fi #=========================================================== : If output from this operation was requested, retrieve it #=========================================================== if (( $rc == RC_SUCCESS )); then if (( CLMGR_VERBOSE )) || [[ -n $CLMGR_ATTRS ]]; then CL=$LINENO KLIB_HACMP_get_snapshot_attributes "$snapshot" properties fi 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 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" \ "add snapshot -h" "SNAPSHOT:" "$CLMGR_PROGNAME" 1>&2 fi log_return_msg "$rc" "$0()" "$LINENO" return $? } # End of "KLIB_HACMP_add_snapshot()" #============================================================================ # # 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_add_snapshot =head1 SYNOPSIS clmgr add snapshot "" \ [ DESCRIPTION="" ] \ [ METHODS="method1 method2 ..." ] \ [ MISC_INFO={false|true} ] NOTE: the alias for "snapshot" is "sn". =head1 DESCRIPTION Attempts to create a snapshot of the cluster configuration. =head1 ARGUMENTS 1. properties [REQUIRED] [hash ref] An associative array within which data about the created object can be returned to the caller. 2. snapshot [REQUIRED] [string] The name of the snapshot. 3. description [OPTIONAL] [string] A description of the snapshot. If no description is provided, then one will be automatically generated. The string can be up to 255 characters. 4. methods [OPTIONAL] [string] One or more custom snapshot methods that should be executed when capturing this snapshot. 5. misc_info [OPTIONAL] [boolean] Collect miscellaneous information from various system commands like lsvg and netstat in a separate file with a .info extension. =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 #==============================================================================