#!/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:-Unset} export SDP_INSTANCE=${1:-$SDP_INSTANCE} if [[ $SDP_INSTANCE == Unset ]]; then echo -e "\nError: Instance parameter not supplied.\n" echo "You must supply the Perforce instance as a parameter to this script." exit 1 fi # Load SDP controlled shell environment. # shellcheck disable=SC1091 source /p4/common/bin/p4_vars "$SDP_INSTANCE" ||\ { echo -e "\nError: Failed to load SDP environment.\n"; exit 1; } # shellcheck disable=SC1090 source "$P4CBIN/backup_functions.sh" ||\ { echo -e "\nError: Failed to load SDP backup_functions.sh lib.\n"; exit 1; } cd "$P4CBIN" || { echo -e "\nError: Failed to cd to $P4CBIN.\n"; exit 1; } ######### Start of Script ########## check_vars set_vars # shellcheck disable=SC2155 export LOGFILE="${LOGS:-/tmp}/upgrade.$P4SERVER.$(date +'%Y%m%d-%H%M').log" echo "Processing. This may take a few minutes depending on time to rotate the active journal and replay to the offline_db." echo "Log file is: $LOGFILE" check_dirs check_uid [[ -f "$P4CBIN/p4" ]] || { echo "No p4 in $P4CBIN" ; exit 1 ;} [[ -f "$P4CBIN/p4d" ]] || { echo "No p4d in $P4CBIN" ; exit 1 ;} chmod 755 "$P4CBIN/p4" chmod 700 "$P4CBIN/p4d" [[ -f "$P4CBIN/p4broker" ]] && chmod 700 "$P4CBIN/p4broker" [[ -f "$P4CBIN/p4p" ]] && chmod 700 "$P4CBIN/p4p" #shellcheck disable=SC2016 P4RELNUM=$(./p4 -V | grep -i Rev. | $AWK -F / '{print $3}') #shellcheck disable=SC2016 P4DRELNUM=$(./p4d -V | grep -i Rev. | $AWK -F / '{print $3}') #shellcheck disable=SC2016 P4BLDNUM=$(./p4 -V | grep -i Rev. | $AWK -F / '{print $4}' | awk '{print $1}') #shellcheck disable=SC2016 P4DBLDNUM=$(./p4d -V | grep -i Rev. | $AWK -F / '{print $4}' | awk '{print $1}') #shellcheck disable=SC2016 CURRENT_RELNUM=$("./p4d_${SDP_INSTANCE}_bin" -V | grep -i Rev. | $AWK -F / '{print $3}') log "Start $P4SERVER Upgrade on ${HOSTNAME%%.*} at $(date)." log "Current server release: $CURRENT_RELNUM" log "New server release: $P4DRELNUM.$P4DBLDNUM" [[ -f "p4_$P4RELNUM.$P4BLDNUM" ]] || cp p4 "p4_$P4RELNUM.$P4BLDNUM" [[ -f "p4d_$P4DRELNUM.$P4DBLDNUM" ]] || cp p4d "p4d_$P4DRELNUM.$P4DBLDNUM" [[ -f "p4_${P4RELNUM}_bin" ]] && unlink "p4_${P4RELNUM}_bin" ln -s "p4_$P4RELNUM.$P4BLDNUM" "p4_${P4RELNUM}_bin" >> "$LOGFILE" 2>&1 [[ -f "p4d_${P4DRELNUM}_bin" ]] && unlink "p4d_${P4DRELNUM}_bin" ln -s "p4d_$P4DRELNUM.$P4DBLDNUM" "p4d_${P4DRELNUM}_bin" >> "$LOGFILE" 2>&1 [[ -f p4_bin ]] && unlink p4_bin ln -s "p4_${P4RELNUM}_bin" p4_bin >> "$LOGFILE" 2>&1 if [[ -L "p4broker_${SDP_INSTANCE}_bin" ]]; then # shellcheck disable=SC2154 if [[ -x "$P4BrokerInitScript" && \ -f "/p4/common/config/p4_${SDP_INSTANCE}.broker.cfg" ]]; then stop_p4broker fi # shellcheck disable=SC2016 P4BRELNUM=$(./p4broker -V | grep -i Rev. | $AWK -F / '{print $3}') # shellcheck disable=SC2016 P4BBLDNUM=$(./p4broker -V | grep -i Rev. | $AWK -F / '{print $4}' | $AWK '{print $1}') [[ -f "p4broker_$P4BRELNUM.$P4BBLDNUM" ]] || cp p4broker "p4broker_$P4BRELNUM.$P4BBLDNUM" [[ -L "p4broker_${P4BRELNUM}_bin" ]] && unlink "p4broker_${P4BRELNUM}_bin" ln -s "p4broker_$P4BRELNUM.$P4BBLDNUM" "p4broker_${P4BRELNUM}_bin" [[ -L "p4broker_${SDP_INSTANCE}_bin" ]] && unlink "p4broker_${SDP_INSTANCE}_bin" ln -s "p4broker_${P4BRELNUM}_bin" "p4broker_${SDP_INSTANCE}_bin" if [[ -x "$P4BrokerInitScript" && \ -f "/p4/common/config/p4_${SDP_INSTANCE}.broker.cfg" ]]; then start_p4broker fi fi if [[ -L "p4p_${SDP_INSTANCE}_bin" ]]; then # shellcheck disable=SC2154 if [[ -x "$P4ProxyInitScript" ]]; then stop_p4p fi # shellcheck disable=SC2016 P4PRELNUM=$(./p4p -V | grep -i Rev. | $AWK -F / '{print $3}') # shellcheck disable=SC2016 P4PBLDNUM=$(./p4p -V | grep -i Rev. | $AWK -F / '{print $4}' | $AWK '{print $1}') [[ -f "p4p_$P4PRELNUM.$P4PBLDNUM" ]] || cp p4p "p4p_$P4PRELNUM.$P4PBLDNUM" [[ -L "p4p_${P4PRELNUM}_bin" ]] && unlink "p4p_${P4PRELNUM}_bin" ln -s "p4p_$P4PRELNUM.$P4PBLDNUM" "p4p_${P4PRELNUM}_bin" [[ -L "p4p_${SDP_INSTANCE}_bin" ]] && unlink "p4p_${SDP_INSTANCE}_bin" ln -s "p4p_${P4PRELNUM}_bin" "p4p_${SDP_INSTANCE}_bin" if [[ -x "$P4ProxyInitScript" ]]; then start_p4p fi fi "$P4CBIN/p4login" -v >> "$LOGFILE" 2>&1 if [[ "$P4REPLICA" == "FALSE" ]] || [[ $EDGESERVER -eq 1 ]]; then get_journalnum fi stop_p4d if [[ "$CURRENT_RELNUM" != "$P4DRELNUM" ]]; then # Only rotate the journal on the master. if [[ "$P4REPLICA" == "FALSE" ]] && [[ $EDGESERVER -eq 0 ]]; then p4d_truncate_journal get_offline_journal_num replay_journals_to_offline_db fi unlink "p4d_${SDP_INSTANCE}_bin" >> "$LOGFILE" 2>&1 ln -s "p4d_${P4DRELNUM}_bin" "p4d_${SDP_INSTANCE}_bin" >> "$LOGFILE" 2>&1 log "Upgrading databases in $P4ROOT." # For versions >= 19.1 we should journal the upgrade and not upgrade offline # In such cases we let offline_db be upgraded by applying rotate journals in the # normal way. UPGRADE_JNL="$P4JOURNAL" # shellcheck disable=SC2072 if [[ "${P4DRELNUM}.${P4DBLDNUM}" < "18.2" ]]; then UPGRADE_JNL=off fi "$P4DBIN" -r "$P4ROOT" -J "$UPGRADE_JNL" -xu >> "$LOGFILE" 2>&1 ||\ die "Failed to upgrade root database." # Upgrade the offline database on the master and on edge servers. if [[ "$P4REPLICA" == "FALSE" ]] || [[ "$EDGESERVER" -eq 1 ]]; then if [[ "$UPGRADE_JNL" == "off" ]]; then log "Upgrading databases in $OFFLINE_DB as this is a pre 18.2 server upgrade" # The value of '-t localhost:0000' is necessary for syntax reasons; # it is ignored. This allows upgade of offline databases without needing # a license file; there isn't one in offline_db, only P4ROOT. A valid # license file is required to actually start the server process and have # it listen on a port. "$P4DBIN" -r "$OFFLINE_DB" -J "$UPGRADE_JNL" -xu -t localhost:0000 >> "$LOGFILE" 2>&1 || die "Failed to upgrade offline_db" else if [[ "$P4REPLICA" == "FALSE" ]] && [[ "$EDGESERVER" -eq 0 ]]; then log "Upgrade offline through rotating latest journal on master/commit server" get_journalnum p4d_truncate_journal get_offline_journal_num replay_journals_to_offline_db fi fi fi fi start_p4d if [[ "$P4REPLICA" == "FALSE" && "$EDGESERVER" -eq 0 ]]; then log "Upgrading protections table comment format." "$P4BIN" protect --convert-p4admin-comments -o | "$P4BIN" -s protect -i >> "$LOGFILE" 2>&1 fi log "Finished $P4SERVER Upgrade" cat "$LOGFILE"
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#29 | 30043 | C. Thomas Tyler |
Released SDP 2023.2.30041 (2023/12/22). Copy Up using 'p4 copy -r -b perforce_software-sdp-dev'. |
||
#28 | 29891 | C. Thomas Tyler |
Released SDP 2023.1.29699 (2023/07/11). Copy Up using 'p4 copy -r -b perforce_software-sdp-dev'. |
||
#27 | 29701 | C. Thomas Tyler |
Released SDP 2023.1.29699 (2023/07/11). Copy Up using 'p4 copy -r -b perforce_software-sdp-dev'. |
||
#26 | 29612 | C. Thomas Tyler |
Released SDP 2023.1.29610 (2023/05/25). Copy Up using 'p4 copy -r -b perforce_software-sdp-dev'. |
||
#25 | 28651 | C. Thomas Tyler |
Released SDP 2021.2.28649 (2022/03/03). Copy Up using 'p4 copy -r -b perforce_software-sdp-dev'. |
||
#24 | 28240 | C. Thomas Tyler |
Released SDP 2021.1.28238 (2021/11/12). Copy Up using 'p4 copy -r -b perforce_software-sdp-dev'. |
||
#23 | 27761 | C. Thomas Tyler |
Released SDP 2020.1.27759 (2021/05/07). Copy Up using 'p4 copy -r -b perforce_software-sdp-dev'. |
||
#22 | 27463 | C. Thomas Tyler |
Released SDP 2020.1.27457 (2021/02/17). Copy Up using 'p4 copy -r -b perforce_software-sdp-dev'. |
||
#21 | 27354 | C. Thomas Tyler |
Released SDP 2020.1.27351 (2021/01/31). Copy Up using 'p4 copy -r -b perforce_software-sdp-dev'. |
||
#20 | 27331 | C. Thomas Tyler |
Released SDP 2020.1.27325 (2021/01/29). Copy Up using 'p4 copy -r -b perforce_software-sdp-dev'. |
||
#19 | 26403 | C. Thomas Tyler |
Released SDP 2019.3.26400 (2020/03/28). Copy Up using 'p4 copy -r -b perforce_software-sdp-dev'. |
||
#18 | 25596 | C. Thomas Tyler |
Released SDP 2019.2.25594 (2019/05/02). Copy Up using 'p4 copy -r -b perforce_software-sdp-dev'. |
||
#17 | 25245 | C. Thomas Tyler |
Released SDP 2019.1.25238 (2019/03/02). Copy Up using 'p4 copy -r -b perforce_software-sdp-dev'. |
||
#16 | 23331 | C. Thomas Tyler |
Released SDP 2017.4.23329 (2017/12/05). Copy Up using 'p4 copy -r -b perforce_software-sdp-dev'. |
||
#15 | 23044 | C. Thomas Tyler |
Released SDP 2017.3.23041 (2017/10/24). Copy Up using 'p4 copy -r -b perforce_software-sdp-dev'. |
||
#14 | 21483 | C. Thomas Tyler |
Released SDP 2016.2.21480 (2017/01/11). Copy Up using 'p4 copy -r -b perforce_software-sdp-dev'. |
||
#13 | 20767 | C. Thomas Tyler |
Released SDP 2016.2.20755 (2016/09/29). Copy Up using 'p4 copy -r -b perforce_software-sdp-dev'. |
||
#12 | 20481 | C. Thomas Tyler |
Released SDP 2016.1.20460. Copy Up using 'p4 copy -r -b perforce_software-sdp-dev', with selective removal of changes related to work-in-progress files. |
||
#11 | 19414 | C. Thomas Tyler | Released SDP/MultiArch/2016.1/19410 (2016/05/17). | ||
#10 | 18619 | Russell C. Jackson (Rusty) | Updating main with current changes. | ||
#9 | 16534 | Russell C. Jackson (Rusty) | Corrected upgrade logic to not try to rotate the journal on an edge server. | ||
#8 | 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. |
||
#7 | 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. |
||
#6 | 15609 | C. Thomas Tyler | Pushing SDP 2015.1.15607 (2015/09/02). | ||
#5 | 13908 | C. Thomas Tyler | Pushing SDP 2015.1.13906. | ||
#4 | 12171 | Russell C. Jackson (Rusty) | Merge in changes to remove the need for p4master_run. | ||
#3 | 11524 | Russell C. Jackson (Rusty) | Released updated version of the SDP from Dev. | ||
#2 | 11459 | mark_foundry |
Fixing the location of the upgrade.log. Previously, it would try to write to /upgrade.log, which requires root permissions. So changed to use $LOGS which is what backupfunctions.sh uses, and is defined in p4vars. I've only tested upgrade.sh, as I don't have a pre-2013.3 server. |
||
#1 | 10148 | C. Thomas Tyler | Promoted the Perforce Server Deployment Package to The Workshop. |