#!/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 is designed to rebuild an Edge server from a checkpoint of the master WHILE # KEEPING THE EXISTING EDGE SPECIFIC DATA. # You have to first copy the checkpoint from the master to the edge server before running this script. # Then you run this script on the Edge server with the instance number and full path and filename # of the master checkpoint as parameters. # # Run example: # ./recover_edge.sh 1 /depotdata/p4_1.ckp.9188.gz 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 LOGFILE=$LOGS/recover_edge.log ######### Start of Script ########## check_vars set_vars if [[ "$2" == "" ]]; then echo You must pass in the full path and filename of the checkpoint you copied over from the master server. exit 2 fi MASTERCKP=$2 log "Remove offline db" rm -f /p4/${SDP_INSTANCE}/offline_db/db.* > $LOGFILE # With -K we filter out the various Edge-specific tables which will be replaced with # current live versions. EXCLUDED_TABLES=db.have,db.working,db.resolve,db.locks,db.revsh,db.workingx,db.resolvex log "Recover checkpoint from master into offline_db skipping tables not used on the edge." /p4/${SDP_INSTANCE}/bin/p4d_${SDP_INSTANCE} -r /p4/${SDP_INSTANCE}/offline_db/ -K $EXCLUDED_TABLES -jr -z $MASTERCKP >> $LOGFILE 2>&1 log "Stopping the edge server." /p4/${SDP_INSTANCE}/bin/p4d_${SDP_INSTANCE}_init stop >> $LOGFILE 2>&1 # With -k we filter and only checkpoint the specified tables from the current live Edge DB. CKP_TABLES=$EXCLUDED_TABLES,db.view,db.label,db.revsx,db.revux log "Creating a dump of the edge specific data from P4ROOT" /p4/${SDP_INSTANCE}/bin/p4d_${SDP_INSTANCE} -r /p4/${SDP_INSTANCE}/root/ -k $CKP_TABLES -jd /p4/${SDP_INSTANCE}/checkpoints/edgedump >> $LOGFILE 2>&1 log "Recover the edge dump into offline_db" /p4/${SDP_INSTANCE}/bin/p4d_${SDP_INSTANCE} -r /p4/${SDP_INSTANCE}/offline_db -jr /p4/${SDP_INSTANCE}/checkpoints/edgedump >> $LOGFILE 2>&1 log "Reset the replication state and clear the P4ROOT folder db files." rm -f /p4/${SDP_INSTANCE}/root/db.* >> $LOGFILE 2>&1 rm -f /p4/${SDP_INSTANCE}/root/state >> $LOGFILE 2>&1 rm -f /p4/${SDP_INSTANCE}/root/rdb.lbr >> $LOGFILE 2>&1 rm -f /p4/${SDP_INSTANCE}/logs/journal >> $LOGFILE 2>&1 log "Move the rebuilt database to P4ROOT" mv /p4/${SDP_INSTANCE}/offline_db/db.* /p4/${SDP_INSTANCE}/root/ >> $LOGFILE 2>&1 log "Start the edge server back up." /p4/${SDP_INSTANCE}/bin/p4d_${SDP_INSTANCE}_init start >> $LOGFILE 2>&1 log "Recreate the offline_db" /p4/${SDP_INSTANCE}/bin/p4d_${SDP_INSTANCE} -r /p4/${SDP_INSTANCE}/offline_db/ -K $EXCLUDED_TABLES -jr -z $MASTERCKP >> $LOGFILE 2>&1 /p4/${SDP_INSTANCE}/bin/p4d_${SDP_INSTANCE} -r /p4/${SDP_INSTANCE}/offline_db -jr /p4/${SDP_INSTANCE}/checkpoints/edgedump >> $LOGFILE 2>&1 log "Create a new edge checkpoint from offline_db" /p4/${SDP_INSTANCE}/bin/p4d_${SDP_INSTANCE} -r /p4/${SDP_INSTANCE}/offline_db -jd -z /p4/${SDP_INSTANCE}/checkpoints/rebuilt_edge_dump.gz >> $LOGFILE 2>&1 # Inform the user about follow up tasks log "Rebuilt checkpoint is: /p4/${SDP_INSTANCE}/checkpoints/rebuilt_edge_dump.gz" log "If you run this script the night before a recreate_db_checkpoint.sh is going to run," log "you need to delete the highest numbered checkpoint in /p4/${SDP_INSTANCE}/checkpoints" log "and rename /p4/${SDP_INSTANCE}/checkpoints/rebuilt_edge_dump.gz to replace that file." cat $LOGFILE
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#15 | 28240 | C. Thomas Tyler |
Released SDP 2021.1.28238 (2021/11/12). Copy Up using 'p4 copy -r -b perforce_software-sdp-dev'. |
||
#14 | 27331 | C. Thomas Tyler |
Released SDP 2020.1.27325 (2021/01/29). Copy Up using 'p4 copy -r -b perforce_software-sdp-dev'. |
||
#13 | 26496 | C. Thomas Tyler |
Released SDP 2019.3.26494 (2020/04/23). Copy Up using 'p4 copy -r -b perforce_software-sdp-dev'. |
||
#12 | 25951 | C. Thomas Tyler |
Released SDP 2019.2.25949 (2019/08/12). Copy Up using 'p4 copy -r -b perforce_software-sdp-dev'. |
||
#11 | 25940 | C. Thomas Tyler |
Released SDP 2019.2.25938 (2019/08/05). Copy Up using 'p4 copy -r -b perforce_software-sdp-dev'. |
||
#10 | 25933 | C. Thomas Tyler |
Released SDP 2019.2.25923 (2019/08/05). Copy Up using 'p4 copy -r -b perforce_software-sdp-dev'. |
||
#9 | 23331 | C. Thomas Tyler |
Released SDP 2017.4.23329 (2017/12/05). Copy Up using 'p4 copy -r -b perforce_software-sdp-dev'. |
||
#8 | 23006 | C. Thomas Tyler |
Released SDP 2017.3.23003 (2017/10/19). Copy Up using 'p4 copy -r -b perforce_software-sdp-dev'. |
||
#7 | 21338 | C. Thomas Tyler |
Released SDP 2016.2.21328 (2016/12/16). Copy Up using 'p4 copy -r -b perforce_software-sdp-dev'. |
||
#6 | 19414 | C. Thomas Tyler | Released SDP/MultiArch/2016.1/19410 (2016/05/17). | ||
#5 | 17315 | C. Thomas Tyler |
Released SDP/MultiArch/2016.1/17297 (2016/02/03). Copy Up using 'p4 copy -r -b perforce_software-sdp-dev'. |
||
#4 | 16845 | C. Thomas Tyler | Fixed typo in script name in a comment; no functional change. | ||
#3 | 15856 | C. Thomas Tyler |
Replaced the big license comment block with a shortened form referencing the LICENSE file included with the SDP package, and also by the URL for the license file in The Workshop. |
||
#2 | 15777 | C. Thomas Tyler |
No functional changes. Style Policing only on bash scripts only. Normalized indentation and line breaks, removed offending tabs, and general whitespace usage. |
||
#1 | 15716 | Russell C. Jackson (Rusty) | Script for rebuilding an Edge server. |