Files
Varaverk/unRAID Essentials/rsync_stop.sh
T

109 lines
2.5 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 MAP -----------------------------
SOURCE="${POSITIONAL_ARGS[0]:-}"
DEST="${POSITIONAL_ARGS[1]:-}"
# ----------------------------- STATUS MODE -----------------------------
if [[ "$SHOW_STATUS" == true ]]; then
show_status
exit 0
fi
# ----------------------------- HEADER -----------------------------
ui_header "RSYNC OPERATION"
ui_section "Context"
ui_kv "Source" "$SOURCE"
ui_kv "Destination" "$DEST"
ui_kv "Remote" "$REMOTE_SERVER_NAME"
ui_kv "IP" "$REMOTE_SERVER"
ui_kv "Dry Run" "$DRY_RUN"
# ----------------------------- VALIDATION -----------------------------
if [[ -z "$SOURCE" ]]; then
echo_error "Missing SOURCE argument"
exit 1
fi
if [[ -z "$DEST" ]]; then
echo_error "Missing DEST argument"
exit 1
fi
ui_status ok "Validation passed"
# ----------------------------- MIRROR MODE -----------------------------
if [[ "$SOURCE" == "$DEST" ]]; then
echo
echo "[INFO] Mirror mode detected (identical paths)"
echo "[INFO] Treating as cross-host sync of same structure"
log "Mirror mode active"
fi
# ----------------------------- PRECHECK -----------------------------
if ! check_remote_online; then
echo_error "Remote host offline"
exit 1
fi
echo "[OK] Remote reachable"
# ----------------------------- CONTAINERS -----------------------------
stop_containers
# ----------------------------- RSYNC EXECUTION -----------------------------
get_rsync_opts
RSYNC_CMD=(
rsync
"${RSYNC_OPTS[@]}"
"$SOURCE"
root@"$REMOTE_SERVER":"$DEST"
)
if [[ "$DRY_RUN" == true ]]; then
RSYNC_CMD+=("--dry-run")
fi
ui_section "Execution"
echo "[RUN] Starting rsync..."
log "CMD: ${RSYNC_CMD[*]}"
"${RSYNC_CMD[@]}"
# ----------------------------- RECOVERY -----------------------------
start_containers
# ----------------------------- END -----------------------------
ui_footer "RSYNC COMPLETE"