86 lines
2.1 KiB
Bash
86 lines
2.1 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 MAPPING -----------------------------
|
|
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
|
|
ui_status error "Missing SOURCE (arg 1)"
|
|
exit 1
|
|
fi
|
|
|
|
if [[ -z "$DEST" ]]; then
|
|
ui_status error "Missing DEST (arg 2)"
|
|
exit 1
|
|
fi
|
|
|
|
ui_status ok "Validation passed"
|
|
|
|
# ----------------------------- PRECHECK -----------------------------
|
|
if ! check_remote_online; then
|
|
ui_status error "Remote offline"
|
|
exit 1
|
|
fi
|
|
|
|
# ----------------------------- EXECUTION -----------------------------
|
|
stop_containers
|
|
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"
|
|
ui_status ok "Running rsync"
|
|
|
|
log "CMD: ${RSYNC_CMD[*]}"
|
|
|
|
"${RSYNC_CMD[@]}"
|
|
|
|
# ----------------------------- RECOVERY -----------------------------
|
|
start_containers
|
|
|
|
# ----------------------------- END -----------------------------
|
|
ui_footer "RSYNC COMPLETE" |