#!/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
#------------------------------------------------------------------------------
# This script recreates offline_db files from the latest checkpoint. If it fails, then
# the only option is to run live_checkpoint.sh instead.
#
# This script can be called directly specifying instance, or using the p4master_run script
# in order to properly set the environment variables for the script to reference. It
# sources /p4/common/bin/p4_vars to set the environment variables that this script
# depends on.
#
# This script is using the following external variables:
#
# SDP_INSTANCE - The instance of Perforce that is being backed up. Always an
# integer value.
#
# P4HOME - Server's home directory.
# P4BIN - Command line client name for the instance being backed up.
# P4DBIN - Server executable name for the instance being backed up.
# P4ROOT - Server's root directory. p4/root, p4_N/root
# P4PORT - TCP/IP port for the server instance being backed up.
# P4JOURNAL - Location of the Journal for the server instance being backed up.
#
#
export SDP_INSTANCE=${SDP_INSTANCE:-Undefined}
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
. /p4/common/bin/p4_vars $SDP_INSTANCE
. /p4/common/bin/backup_functions.sh
recreate_offline_db_from_latest_ckp () {
[[ -f ${CHECKPOINTS}/${P4SERVER}.ckp.*.gz ]] && \
ckp_complete && die "No checkpoints found - consider running live_checkpoint.sh"
rm -f ${OFFLINE_DB}/offline_db_usable.txt
rm -f ${OFFLINE_DB}/db.* >> "$LOGFILE"
LASTCKP=`ls -t ${CHECKPOINTS}/${P4SERVER}.ckp.*.gz | head -1`
log "Recovering from $LASTCKP"
# curly braces are necessary to capture the output of 'time'
{ time $P4DBIN -r $OFFLINE_DB -jr -z ${LASTCKP}; } \
>> "$LOGFILE" 2>&1 || { die "Restore of checkpoint to $OFFLINE_DB failed!"; }
echo "Offline db file restored successfully." > ${OFFLINE_DB}/offline_db_usable.txt
}
######### Start of Script ##########
check_vars
set_vars
check_uid
check_dirs
ckp_running
get_journalnum
rotate_last_run_logs
log "Start $P4SERVER recreate of offline db"
recreate_offline_db_from_latest_ckp
log "Offline db basic recovery completed"
/p4/common/bin/p4login
get_offline_journal_num
replay_journals_to_offline_db
log "End $P4SERVER recreate offline db"
mail_log_file "$HOSTNAME $P4SERVER recreate offline db log."
remove_old_logs
ckp_complete
| # | Change | User | Description | Committed | |
|---|---|---|---|---|---|
| #3 | 22142 | Robert Cowham | Merge in latest changes from Dev | ||
| #2 | 20726 | Robert Cowham | Catch up from dev | ||
| #1 | 18586 | Robert Cowham | Branching using cowhamr.sdp.dev | ||
| //guest/perforce_software/sdp/dev/Server/Unix/p4/common/bin/recreate_offline_db.sh | |||||
| #1 | 18534 | Robert Cowham |
New script to recreate_offline_db files from latest found checkpoint. Something to try before live_checkpoint (which blocks live database). |
||