#!/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. source /p4/common/bin/p4_vars "$SDP_INSTANCE" ||\ { echo -e "\nError: Failed to load SDP environment.\n"; exit 1; } 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; } common_dir=`pwd -P` if [[ -d $common_dir ]]; then cd $common_dir || { echo -e "\nError: Failed to cd to $common_dir.\n"; exit 1; } else echo $common_dir does not exist. exit 1 fi ######### Start of Script ########## check_vars set_vars export LOGFILE=$LOGS/upgrade.$P4SERVER.log.$(date +'%Y%m%d-%H%M') 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 $common_dir/p4 ]] || { echo "No p4 in $common_dir" ; exit 1 ;} [[ -f $common_dir/p4d ]] || { echo "No p4d in $common_dir" ; exit 1 ;} chmod 755 $common_dir/p4 chmod 700 $common_dir/p4d [[ -f $common_dir/p4broker ]] && chmod 700 $common_dir/p4broker [[ -f $common_dir/p4p ]] && chmod 700 $common_dir/p4p P4RELNUM=`./p4 -V | grep -i Rev. | $AWK -F / '{print $3}'` P4DRELNUM=`./p4d -V | grep -i Rev. | $AWK -F / '{print $3}'` P4BLDNUM=`./p4 -V | grep -i Rev. | $AWK -F / '{print $4}' | awk '{print $1}'` P4DBLDNUM=`./p4d -V | grep -i Rev. | $AWK -F / '{print $4}' | awk '{print $1}'` CURRENT_RELNUM=`./p4d_${SDP_INSTANCE}_bin -V | grep -i Rev. | $AWK -F / '{print $3}'` log "Start $P4SERVER Upgrade on $(hostname)." 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 if [[ -x /p4/${SDP_INSTANCE}/bin/p4broker_${SDP_INSTANCE}_init && \ -f /p4/common/config/p4_${SDP_INSTANCE}.broker.cfg ]]; then /p4/${SDP_INSTANCE}/bin/p4broker_${SDP_INSTANCE}_init stop >> $LOGFILE 2>&1 fi P4BRELNUM=`./p4broker -V | grep -i Rev. | $AWK -F / '{print $3}'` 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 /p4/${SDP_INSTANCE}/bin/p4broker_${SDP_INSTANCE}_init && \ -f /p4/common/config/p4_${SDP_INSTANCE}.broker.cfg ]]; then /p4/${SDP_INSTANCE}/bin/p4broker_${SDP_INSTANCE}_init start >> $LOGFILE 2>&1 fi fi if [[ -L p4p_${SDP_INSTANCE}_bin ]]; then if [[ -x /p4/${SDP_INSTANCE}/bin/p4p_${SDP_INSTANCE}_init ]]; then /p4/${SDP_INSTANCE}/bin/p4p_${SDP_INSTANCE}_init stop >> $LOGFILE 2>&1 fi P4PRELNUM=`./p4p -V | grep -i Rev. | $AWK -F / '{print $3}'` 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 /p4/${SDP_INSTANCE}/bin/p4p_${SDP_INSTANCE}_init ]]; then /p4/${SDP_INSTANCE}/bin/p4p_${SDP_INSTANCE}_init start >> $LOGFILE 2>&1 fi fi $P4CBIN/p4login -v >> $LOGFILE 2>&1 if [[ -x /p4/${SDP_INSTANCE}/bin/p4d_${SDP_INSTANCE}_init ]]; then if [[ "$P4REPLICA" == "FALSE" ]] || [[ $EDGESERVER -eq 1 ]]; then get_journalnum fi /p4/${SDP_INSTANCE}/bin/p4d_${SDP_INSTANCE}_init stop >> $LOGFILE 2>&1 fi # Don't upgrade the database for minor upgrades 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" 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 if [[ -x /p4/${SDP_INSTANCE}/bin/p4d_${SDP_INSTANCE}_init ]]; then /p4/${SDP_INSTANCE}/bin/p4d_${SDP_INSTANCE}_init start >> $LOGFILE 2>&1 sleep 1 fi if [[ "$P4REPLICA" == "FALSE" && $EDGESERVER -eq 0 ]]; then log "Upgrading protections table comment format." $P4BIN protect --convert-p4admin-comments -o | $P4BIN protect -i fi log "Finished $P4SERVER Upgrade" cat $LOGFILE
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#30 | 30915 | C. Thomas Tyler |
Released SDP 2024.1.30913 (2024/11/20). Copy Up using 'p4 copy -r -b perforce_software-sdp-dev'. |
||
#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. |