#!/bin/bash #------------------------------------------------------------------------------ set -u # One-time usage: # cd /p4/1/tmp/rsync # MyDepot=SpecifyYourDepotName # nohup ./rsync_to_hxdepots-2.sh $MyDepot < /dev/null > 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="2.1.1" 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 ./rsync_to_hxdepots-2.sh \$MyDepot < /dev/null > 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 "Disk space checks BEFORE:\\ndf -h /hxdepots /hxdepots-2\\n$(df -h /hxdepots /hxdepots-2)\\n" msg "Running: rsync -a $SrcDir/ $TgtDir" if rsync -a "$SrcDir/" "$TgtDir"; then msg "\\nRsync was OK. Moving original source." msg "Running: mv ${SrcDir} ${SrcDir}.JUNK" if mv "${SrcDir}" "${SrcDir}.JUNK"; then msg "\\nMove OK, doing symlink." msg "Running: ln -s $TgtDir $SrcDir" if ln -s "$TgtDir" "$SrcDir"; then msg "Symlink OK. Doing remove." msg "Running: rm -rf ${SrcDir}.JUNK" if rm -rf "${SrcDir}.JUNK"; then msg "Removal OK." else errmsg "Removal did not go OK. Aborting." fi else errmsg "Symlink did not go OK. Aborting." fi else errmsg "Move did nto go OK. Aborting." fi 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 msg "Disk space checks AFTER:\\ndf -h /hxdepots /hxdepots-2\\n$(df -h /hxdepots /hxdepots-2)\\n" 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. |