#!/bin/bash #------------------------------------------------------------------------------ set -u # This script can be run before the rsync_to_hxdepots-2.sh script. This can # be run safely when the live server is up and running, as it only copies # data, but does not disturb data in the source. It's OK if it is actively # being written, as this script is not about having a perfect and complete # copy of the depot, just getting a head start on the copy, so that the # rsync called in the rsync_to_hxdepots-2.sh (which cannot be run when # data is actively written) can be faster, as rsync is an incremental # copy utility that is faster after the initial copy is done. # cd /p4/1/tmp/rsync # MyDepot=SpecifyYourDepotName # nohup ./prep_for_rsync_to_hxdepots-2.sh $MyDepot < /dev/null > prep_for_rsync_to_hxdepots-2.$MyDepot.log 2>&1 & function msg () { echo -e "$*"; } function errmsg () { msg "\\nError: ${1:-Unknown Error}\\n"; ErrorCount+=1; } function bail () { errmsg "${1:-Unknown Error}"; exit "${2:-1}"; } declare Version="1.0.0" declare SrcDirBase="/hxdepots/p4/1/depots" declare TgtDirBase="/hxdepots-2/p4/1/depots" declare MyDepot="${1:-Unset}" declare SrcDir="$SrcDirBase/$MyDepot" declare TgtDir="$TgtDirBase/$MyDepot" declare -i ErrorCount=0 msg "Started ${0##*/} v$Version on host ${HOSTNAME%%.*} at $(date)." msg "Preflight checks." [[ "$MyDepot" == "Unset" ]] && \ bail "Bad usage: Missing required depot parameter. Usage:\\n\\n\\tcd /p4/1/tmp/rsync\\n\\tMyDepot=SpecifyYourDepotName\\n\\tnohup ./prep_for_rsync_to_hxdepots-2.sh \$MyDepot < /dev/null > prep_for_rsync_to_hxdepots-2.\$MyDepot.log 2>&1 &" [[ -d "$SrcDirBase" ]] || errmsg "Missing SrcDirBase: $SrcDirBase" [[ -d "$TgtDirBase" ]] || errmsg "Missing TgtDirBase: $TgtDirBase" [[ -d "$SrcDir" ]] || errmsg "Missing SrcDir: $SrcDir" if [[ ! -d "$TgtDir" ]]; then msg "Running: mkdir -p $TgtDir" if mkdir -p "$TgtDir"; then msg "Mkdir OK." else errmsg "Mkdir failed." fi fi if [[ "$ErrorCount" -eq 0 ]]; then msg "\\nPreflight checks passed. Moving on." else bail "Aborting early due to failed preflight checks." fi msg "Running: rsync -a $SrcDir/ $TgtDir" if rsync -a "$SrcDir/" "$TgtDir"; then msg "\\nRsync was OK. Prep complete. This can be run again to keep target current until rsync_to_hxdepots-2.sh is run to finish the job." else errmsg "Rsync did not go OK. Aborting." fi msg "\\nThat took $((SECONDS/3600)) hours $((SECONDS%3600/60)) minutes $((SECONDS%60)) seconds.\\n" if [[ "$ErrorCount" -eq 0 ]]; then msg "\\nAll processing completed successfully." else errmsg "Done, but with with errors. See above." fi exit "$ErrorCount"
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#2 | 30243 | C. Thomas Tyler |
cdrs.sh v3.0: Consolidated prep and execution into a single script. WORK IN PROGRESS CHANGE. |
||
#1 | 27587 | C. Thomas Tyler | Added sample rsync scripts. |