#!/bin/bash
#==============================================================================
# Copyright and license info is available in the LICENSE file included with
# the Server Deployment Package (SDP), and also available online:
# https://swarm.workshop.perforce.com/projects/perforce-software-sdp/view/main/LICENSE
#------------------------------------------------------------------------------
set -u
#==============================================================================
# Declarations and Environment
export SDP_ENV=/p4/common/bin/p4_vars
export SDP_INSTANCE=${SDP_INSTANCE:-Unset}
export SDP_INSTANCE=${1:-$SDP_INSTANCE}
if [[ $SDP_INSTANCE == Undefined ]]; then
echo "Instance parameter not supplied."
echo "You must supply the Perforce instance as a parameter to this script."
exit 1
fi
export CkpFile=Unset
declare StatusMessage="OK: Restore Completed."
declare -i CkpFailed=
declare -i ExitCode=0
declare RestoreCmd=
declare Log=Unset
declare Version=1.0.0
declare Threads=1
#==============================================================================
# Local Functions
# Micro-functions, one-liners used to avoid external dependencies.
function msg () { if [[ $Log != Unset ]]; then echo -e "$*" >> $Log; else echo -e "$*"; fi; }
function bail () { msg "\nError: ${1:-Unknown Error}"; exit ${2:-1}; }
#------------------------------------------------------------------------------
# Function: usage (required function)
#
# Input:
# $1 - style, either -h (for short form) or -man (for man-page like format).
# The default is -h.
#
# $2 - error message (optional). Specify this if usage() is called due to
# user error, in which case the given message displayed first, followed by the
# standard usage message (short or long depending on $1). If displaying an
# errror, usually $1 should be -h so that the longer usage message doesn't
# obsure the error message.
#
# Sample Usage:
# usage
# usage -man
# usage -h "Incorrect command line usage."
#
# This last example generates a usage error message followed by the short
# '-h' usage summary.
#------------------------------------------------------------------------------
function usage
{
declare style=${1:--h}
declare errorMessage=${2:-Unset}
if [[ $errorMessage != Unset ]]; then
echo -e "\n\nUsage Error:\n\n$errorMessage\n\n" >&2
fi
echo "USAGE for parallel_ckp_restore.sh v$Version:
parallel_ckp_restore.sh [<instance>] -f <parallel_ckp.tgz> [-P #]
or
parallel_ckp_restore.sh -h|-man
"
if [[ $style == -man ]]; then
echo -e "DESCRIPTION:
This script runs a parallel offline checkpoint.
OPTIONS:
<instance>
Specify the SDP instances. If not specified, the SDP_INSTANCE
environment variable is used instead. If the instance is not
defined by a parameter and SDP_INSTANCE is not defined, parallel_ckp_restore.sh
exists immediately with an error message.
-f parallel_ckp_file.tgz
The parallel checkpoint tgz file to restore to the offline_db
-P #
Specify the number of db_files to restore in parallel.
HELP OPTIONS:
-h Display short help message
-man Display man-style help message
EXAMPLES:
This script is typically called via cron with only the instance
paramter and the number of threads as arguments, e.g.:
parallel_ckp_restore.sh 1 6
LOGGING:
This script generates no output by default. All (stdout and stderr) is
logged to /p4/N/logs/checkpoint.log.
The exception is usage errors, which result an error being sent to
stderr followed usage info on stdout, followed by an immediate exit.
EXIT CODES:
An exit code of 0 indicates no errors were encounted attempting to
perform verifications, AND that all verifications attempted
reported no problems.
A exit status of 1 indicates that verifications could not be
attempted for some reason.
"
fi
exit 1
}
#==============================================================================
# Command Line Processing
declare -i shiftArgs=0
set +u
while [[ $# -gt 0 ]]; do
case $1 in
(-h) usage -h;;
(-man) usage -man;;
(-f) CkpFile=$2; shiftArgs=1;;
(-P) Threads=$2; shiftArgs=1;;
(-*) usage -h "Unknown command line option ($1).";;
(*) export SDP_INSTANCE=$1;;
esac
# Shift (modify $#) the appropriate number of times.
shift; while [[ $shiftArgs -gt 0 ]]; do
[[ $# -eq 0 ]] && usage -h "Incorrect number of arguments."
shiftArgs=$shiftArgs-1
shift
done
done
#==============================================================================
# Command Line Verification
[[ $SDP_INSTANCE == Unset ]] && \
bail "The \$SDP_INSTANCE setting is not defined. It must be defined by doing:\n\n\tsource /p4/common/bin/p4_vars <instance>\n\nor by passing in the instance name as a parameter to this script.\n"
[[ $CkpFile == Unset ]] && \
bail "The Checkpoint file to be restored was not passed in with the -f parameter to this script.\n\n"
#==============================================================================
# Main Program
source $SDP_ENV $SDP_INSTANCE || bail "Failed to load SDP environment for instance $SDP_INSTANCE."
source $P4CBIN/backup_functions.sh || bail "Failed to load backup_functions.sh."
[[ $Log == Unset ]] && Log=$LOGS/checkpoint_restore.log
# This is needed because everything in backup_functions.sh uses LOGFILE including the mail_log_file function.
LOGFILE=$Log
LOG=$LOGS/checkpoint
check_vars
set_vars
msg "${0##*/} v$Version Starting $P4SERVER checkpoint restore to offline_db at $(date +'%a %Y-%m-%d %H:%M:%S %Z')."
msg "If there are errors in this log, contact your local support team."
check_uid
check_dirs
ckp_running
rm -f $CKPTMPDIR/*
extract_tar_ckp $CkpFile
restore_parallel_ckp
rm -f $CKPTMPDIR/*
msg "${0##*/} v$Version End $P4SERVER checkpoint restore at $(date +'%a %Y-%m-%d %H:%M:%S %Z')."
ckp_complete
exit $ExitCode
| # | Change | User | Description | Committed | |
|---|---|---|---|---|---|
| #2 | 26453 | C. Thomas Tyler |
Temporary removal of parallel_ckp.sh and parallel_ckp_restore.sh until this can be re-added with test suite coverage. Supporting logic in backup_functions.sh will be left in place to support the eventual return of these scripts. |
||
| #1 | 25374 | Russell C. Jackson (Rusty) |
New script for performing a parallel checkpoint. Run as follows: parallel_ckp.sh <instance> -P <threads> New script to restore a parallel checkpoint file to the offline database in case a recovery is needed. Run as follows: parallel_ckp_restore.sh <instance> -f <parallel_ckp_file.tgz> -P <threads> |