refresh_P4ROOT_from_offline_db.sh #1

  • //
  • guest/
  • perforce_software/
  • sdp/
  • main/
  • Server/
  • Unix/
  • p4/
  • common/
  • bin/
  • refresh_P4ROOT_from_offline_db.sh
  • View
  • Commits
  • Open Download .zip Download (2 KB)
#!/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
#------------------------------------------------------------------------------

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 

# shellcheck disable=SC1091
source /p4/common/bin/p4_vars "$SDP_INSTANCE"
# shellcheck disable=SC1091
source /p4/common/bin/backup_functions.sh
LOGFILE="$LOGS/refresh_P4ROOT_from_offline_db.log"

######### Start of Script ##########
check_vars
set_vars
rotate_last_run_logs
log "Start $P4SERVER Refresh P4ROOT from offline_db."
check_uid
check_dirs
check_offline_db_usable
if ! "$P4BIN" info -s > /dev/null 2>&1; then
   die "Error: p4d is not running as expected. Aborting."
fi
ckp_running
"$P4CBIN"/p4login
get_journalnum
get_offline_journal_num
stop_p4d
p4d_truncate_journal
replay_journals_to_offline_db

# On an edge server, we have to replay the active journal as well because the edge
# server has been running since the journal was rotated.
if [[ "$EDGESERVER" -eq 1 ]]; then
   replay_active_journal_to_offline_db
fi

switch_db_files
start_p4d
log "Removing db files from save directory since we know the journal successfully replayed at this point."
# The offline_db directory was the root, so this is where the save directory is now.
rm -f "${OFFLINE_DB}"/save/db.* >> "$LOGFILE" 2>&1
recreate_offline_db_files
get_offline_journal_num
replay_journals_to_offline_db
# shellcheck disable=SC2034
ROOTDIR=$OFFLINE_DB
dump_checkpoint
remove_old_checkpoints_and_journals
check_disk_space
remove_old_logs
log "End $P4SERVER Refresh P4ROOT from offline_db."
mail_log_file "$HOSTNAME $P4SERVER Refresh P4ROOT from offline_db log."
set_counter
ckp_complete
# Change User Description Committed
#5 31204 Will Kreitzmann Released SDP 2024.2.31193 (2025/01/17).
Copy Up using 'p4 copy -r -b perforce_software-sdp-dev'.
#4 30915 C. Thomas Tyler Released SDP 2024.1.30913 (2024/11/20).
Copy Up using 'p4 copy -r -b perforce_software-sdp-dev'.
#3 30297 C. Thomas Tyler Released SDP 2023.2.30295 (2024/05/08).
Copy Up using 'p4 copy -r -b perforce_software-sdp-dev'.
#2 26470 C. Thomas Tyler Released SDP 2019.3.26468 (2020/04/10).
Copy Up using 'p4 copy -r -b perforce_software-sdp-dev'.
#1 26403 C. Thomas Tyler Released SDP 2019.3.26400 (2020/03/28).
Copy Up using 'p4 copy -r -b perforce_software-sdp-dev'.
//guest/perforce_software/sdp/dev/Server/Unix/p4/common/bin/refresh_P4ROOT_from_offline_db.sh
#1 26400 C. Thomas Tyler Added refresh_P4ROOT_from_offline_db.sh.

Updated backup_functions.sh to support functionality for db refresh.

Upgrade start_p4d() and stop_p4d() to use systemd if available, else
use the underlying SysV init scripts.

Updated verify_sdp.sh to be called from other scripts (sans
its own logging).  Added many checks to verify_sdp.sh to
support P4ROOT/offline_db swap.

Logic in P4ROOT/offline_db swap is more careful about what gets
swapped.

Added start_p4broker() and stop_p4broker() that behave similarly.

More shellcheck compliance.

#review-26401