opt_perforce_sdp_backup.sh #3

  • //
  • p4-sdp/
  • dev_c2s/
  • Server/
  • Unix/
  • p4/
  • common/
  • bin/
  • opt_perforce_sdp_backup.sh
  • View
  • Commits
  • Open Download .zip Download (2 KB)
#!/bin/bash
set -u

# Version ID Block. Relies on +k filetype modifier.
#------------------------------------------------------------------------------
# shellcheck disable=SC2016
declare VersionID='$Id: //p4-sdp/dev_c2s/Server/Unix/p4/common/bin/opt_perforce_sdp_backup.sh#3 $ $Change: 31580 $'
declare VersionStream=${VersionID#*//}; VersionStream=${VersionStream#*/}; VersionStream=${VersionStream%%/*};
declare VersionCL=${VersionID##*: }; VersionCL=${VersionCL%% *}
declare Version=${VersionStream}.${VersionCL}
[[ "$VersionStream" == r* ]] || Version="${Version^^}"

declare ThisScript="${0##*/}"
declare ThisUser=
declare ThisHost=${HOSTNAME%%.*}
declare PerforcePackageBase=/opt/perforce
declare SDPPackageBase="$PerforcePackageBase/helix-sdp"
declare BackupBase="/hxdepots/backup"
declare BackupDir="$BackupBase/opt_perforce_helix-sdp.$ThisHost"
declare RsyncCmd=
declare -i Debug=${SDP_DEBUG:-0}
declare -i ErrorCount=0

#==============================================================================
# Local Functions

function msg () { echo -e "$*"; }
function dbg () { [[ "$Debug" -eq 0 ]] || msg "DEBUG: $*"; }
function errmsg () { msg "\\nError: ${1:-Unknown Error}\\n"; ErrorCount+=1; }
function bail () { errmsg "${1:-Unknown Error}"; exit "${2:-1}"; }

ThisUser=$(id -n -u)
msg "Started $ThisScript version $Version as $ThisUser@$ThisHost on $(date)."

dbg "Starting Preflight Checks."

if [[ "$ThisUser" == root ]]; then
   dbg "Verified: Running as root"
else
   errmsg "Run this as root, not $ThisUser."
fi

if [[ -d "$SDPPackageBase" ]]; then
   dbg "Verified: $SDPPackageBase directory exists."
else
   errmsg "SDP OS Package Structure [$SDPPackageBase] does not exists. Use this script only if that structure exists."
fi

mkdir -p "$BackupBase" ||\
   errmsg "Could not do: mkdir -p \"$BackupBase\""

if [[ -d "$BackupBase" && -w "$BackupBase" ]]; then
   dbg "Verified: $BackupBase directory exists and is writable."
else
   errmsg "The BackupBase directory [$BackupBase] does not exist or is not writable."
fi

if [[ "$ErrorCount" -eq 0 ]]; then
   dbg "Preflight checks OK."
else
   bail "Aborting due to failed preflight checks."
fi

RsyncCmd="rsync -av $SDPPackageBase/ $BackupDir"
if eval "$RsyncCmd"; then
   msg "SDP Package Backup to $BackupDir was successful."
else
   bail "SDP Package Backup to $BackupDir failed."
fi

exit "$ErrorCount"
# Change User Description Committed
#3 31580 C. Thomas Tyler Merge dev->dev_c2s.
Several interactive merges were required, mostly due
to the change to version strings.
#2 31472 C. Thomas Tyler Updated bash scripts and bash template to new file versioning scheme.
Modernized template bash script.
#1 31399 C. Thomas Tyler Populate -r -S //p4-sdp/dev_c2s.
//p4-sdp/dev/Server/Unix/p4/common/bin/opt_perforce_sdp_backup.sh
#1 31397 C. Thomas Tyler Populate -b SDP_Classic_to_Streams -s //guest/perforce_software/sdp/...@31368.
//guest/perforce_software/sdp/dev/Server/Unix/p4/common/bin/opt_perforce_sdp_backup.sh
#2 31051 C. Thomas Tyler Tweaked to create backup dir if needed.
#1 31050 C. Thomas Tyler Added script to back SDP OS Package Structure.

Modified sdp_upgrade.sh to install a systemd oneshot service to call this
script if operating on a system using the SDP OS Package Structure (i.e.
a systemd where /opt/perforce/helix-sdp exists).