Files
Varaverk/unRAID Essentials/rsync_stop.sh
T
2026-03-27 17:14:57 +00:00

105 lines
2.4 KiB
Bash

#!/bin/bash
set -e
# ----------------------------------------------------------------------------------------------
# ------------------------ Stop all running Rsync processes for Unraid -------------------------
# ----------------------------------------------------------------------------------------------
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "$SCRIPT_DIR/../Master.conf"
source "$SCRIPT_DIR/../common.sh"
# ----------------------------- INIT -----------------------------
parse_args "$@"
require_var "HOST1"
require_var "HOST2"
detect_hosts
resolve_remote_ip
# ----------------------------- POSITIONAL -----------------------------
SOURCE="${POSITIONAL_ARGS[0]:-}"
DEST="${POSITIONAL_ARGS[1]:-}"
# ----------------------------- STATUS MODE -----------------------------
if [[ "$SHOW_STATUS" == true ]]; then
show_status
exit 0
fi
# ----------------------------- HEADER -----------------------------
echo
echo "=================================================="
echo " 🚀 RSYNC START"
echo "=================================================="
echo "[INFO] Source: $SOURCE"
echo "[INFO] Destination: $DEST"
echo "[INFO] Remote: $REMOTE_SERVER_NAME ($REMOTE_SERVER)"
echo "[INFO] DryRun: $DRY_RUN"
echo
# ----------------------------- VALIDATION -----------------------------
if [[ -z "$SOURCE" ]]; then
echo_error "Missing SOURCE"
exit 1
fi
if [[ -z "$DEST" ]]; then
echo_error "Missing DEST"
exit 1
fi
echo "[OK] Validation passed"
log "Validation completed successfully"
# ----------------------------- PRECHECK -----------------------------
if ! check_remote_online; then
echo_error "Remote host offline"
exit 1
fi
echo "[OK] Remote reachable"
# ----------------------------- CONTAINERS -----------------------------
stop_containers
# ----------------------------- RSYNC -----------------------------
get_rsync_opts
RSYNC_CMD=(
rsync
"${RSYNC_OPTS[@]}"
"$SOURCE"
root@"$REMOTE_SERVER":"$DEST"
)
if [[ "$DRY_RUN" == true ]]; then
RSYNC_CMD+=("--dry-run")
fi
echo
echo "[RUN] Executing rsync..."
log "CMD: ${RSYNC_CMD[*]}"
"${RSYNC_CMD[@]}"
# ----------------------------- RECOVERY -----------------------------
start_containers
# ----------------------------- END -----------------------------
echo
echo "=================================================="
echo " ✅ RSYNC COMPLETE"
echo "=================================================="