#!/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 ckp_running 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 ${OFFLINE_DB}/db.* > $LOGFILE # With -K we filter out the various Edge-specific tables which will be replaced with # current live versions. if [[ "${P4D_VERSION:-1970.1}" > "2019.0" ]]; then EXCLUDED_TABLES=db.have,db.working,db.locks,db.resolve,db.revsh,db.workingx,db.resolvex,db.stash,db.haveg,db.workingg,db.locksg,db.resolveg else EXCLUDED_TABLES=db.have,db.working,db.resolve,db.locks,db.revsh,db.workingx,db.resolvex fi log "Recover checkpoint from master into offline_db skipping tables not used on the edge." ${P4DBIN} -r ${OFFLINE_DB} -K $EXCLUDED_TABLES -jr -z $MASTERCKP >> $LOGFILE 2>&1 log "Stopping the edge server." ${RC} 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" ${P4DBIN} -r ${P4ROOT} -k $CKP_TABLES -jd ${CHECKPOINTS}/edgedump >> $LOGFILE 2>&1 log "Recover the edge dump into offline_db" ${P4DBIN} -r ${OFFLINE_DB} -jr ${CHECKPOINTS}/edgedump >> $LOGFILE 2>&1 log "Reset the replication state and clear the P4ROOT folder db files." rm -f ${P4ROOT}/db.* >> $LOGFILE 2>&1 rm -f ${P4ROOT}/state >> $LOGFILE 2>&1 rm -f ${P4ROOT}/rdb.lbr >> $LOGFILE 2>&1 rm -f ${P4JOURNAL} >> $LOGFILE 2>&1 log "Move the rebuilt database to P4ROOT" mv ${OFFLINE_DB}/db.* ${P4ROOT} >> $LOGFILE 2>&1 log "Start the edge server back up." ${RC} start >> $LOGFILE 2>&1 log "Recreate the offline_db" ${P4DBIN} -r ${OFFLINE_DB} -K $EXCLUDED_TABLES -jr -z $MASTERCKP >> $LOGFILE 2>&1 ${P4DBIN} -r ${OFFLINE_DB} -jr ${CHECKPOINTS}/edgedump >> $LOGFILE 2>&1 log "Create a new edge checkpoint from offline_db" get_offline_journal_num rm -f ${CHECKPOINTS}/${P4SERVER}.ckp.${OFFLINECHECKPOINTNUM}.gz >> $LOGFILE 2>&1 rm -f ${CHECKPOINTS}/${P4SERVER}.ckp.${OFFLINECHECKPOINTNUM}.gz.md5 >> $LOGFILE 2>&1 ${P4DBIN} -r ${OFFLINE_DB} -jd -z ${CHECKPOINTS}/${P4SERVER}.ckp.${OFFLINECHECKPOINTNUM}.gz >> $LOGFILE 2>&1 ckp_complete log "End $P4SERVER Recover Edge" mail_log_file "$HOSTNAME $P4SERVER Recover Edge log."
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#11 | 29720 | Russell C. Jackson (Rusty) | Corrected case on ExcludedTables | ||
#10 | 29643 | Russell C. Jackson (Rusty) | Added db.storage to checkpoint tables so we don't lose edge server storage information. | ||
#9 | 29337 | Russell C. Jackson (Rusty) | Dumping an edge set of tables still requires using -k | ||
#8 | 29261 | Russell C. Jackson (Rusty) | Added new -R edge-server parameters for dump and recovery. | ||
#7 | 27810 | Russell C. Jackson (Rusty) | Updated excluded tables for 2020.2 | ||
#6 | 27168 | Russell C. Jackson (Rusty) | Changed RC stop/start to stop_p4d and start_p4d | ||
#5 | 25830 | Russell C. Jackson (Rusty) | Added handling of new 2019.1 edge files. | ||
#4 | 23247 | Russell C. Jackson (Rusty) |
Modified the checkpoints folder to include an extension of the master or edge server.id to support sharing the data volume between a master and a workspace edge server in the same data center. Updated recover_edge to use variables appropriately and fixed a bug in the naming of the checkpoint file. |
||
#3 | 22981 | Russell C. Jackson (Rusty) | Made files writeable so they are easier to update once on the server. | ||
#2 | 22884 | Russell C. Jackson (Rusty) | Enhanced recover edge to mark when it is running so a checkpoint doesn't stomp on it, and also made it just create the correct checkpoint name. | ||
#1 | 22693 | Russell C. Jackson (Rusty) |
Branched a Unix only version of the SDP. Removed extra items to create a cleaner tree. Moved a few items around to make more sense without Windows in the mix. |
||
//guest/perforce_software/sdp/dev/Server/Unix/p4/common/bin/recover_edge.sh | |||||
#7 | 21280 | Russell C. Jackson (Rusty) | Added standard logging and use of SDP_INSTANCE. | ||
#6 | 19113 | Russell C. Jackson (Rusty) |
Changed name of daily_backup.sh to daily_checkpoint.sh Changed name of weekly_backup.sh to recreate_db_checkpoint.sh Updated crontabs with new names, and changed to run recreate_db_checkpoint on the 1st Sat. of Jan. and July. For most companies, this is a better practice than recreating weekly per discussion with Anton. Remove solaris crontab since Solaris is pretty much dead, and we don't test on it. Updated docs to reflect name changes, and did a little clean other other sections while I was in there. |
||
#5 | 17293 | Robert Cowham | Clarifications in comments - no functional change. | ||
#4 | 17219 | C. Thomas Tyler | Routine Merge Down to dev from main. | ||
#3 | 16029 | C. Thomas Tyler |
Routine merge to dev from main using: p4 merge -b perforce_software-sdp-dev |
||
#2 | 15778 | C. Thomas Tyler | Routine Merge Down to dev from main. | ||
#1 | 15753 | C. Thomas Tyler | Routine Merge Down to dev from main. | ||
//guest/perforce_software/sdp/main/Server/Unix/p4/common/bin/recover_edge.sh | |||||
#1 | 15716 | Russell C. Jackson (Rusty) | Script for rebuilding an Edge server. |