This commit is contained in:
2026-03-27 18:56:10 +00:00
parent 0766efdcf9
commit 872821eaf5
+63 -39
View File
@@ -1,47 +1,70 @@
#!/bin/bash #!/bin/bash
set -e set -e
# ---------------------------------------------------------------------------------------------- # ----------------------------------------------------------------------------------------------
# --------------------------------- Rsync Core Script ------------------------------------------ # --------------------------------- Rsync Core Script ------------------------------------------
# ---------------------------------------------------------------------------------------------- # ----------------------------------------------------------------------------------------------
# ---------------- User Variables, Please adjust in Master.conf as needed ---------------------- # User Variables handled in Master.conf
# ----------------------------------------------------------------------------------------------
#
# User variables can be adjusted in Master.conf
#
# Scripts now just contain runtime logic
#
# This new setup allows for profiles and arguments to use the core script
#
# Use arguments in unRAID User Plugin for directory
# Example = /mnt/user/appdata/unraid_scripts/Rsync/rsync.sh --dry-run
# ----------------------------------------------------------------------------------------------
# -------------- End Of User Variables, Please adjust in Master.conf as needed -----------------
# ---------------------------------------------------------------------------------------------- # ----------------------------------------------------------------------------------------------
# Resolve script directory (Unraid-safe /tmp compatible)
BASE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" BASE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
SCRIPT_DIR="$BASE_DIR"
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # ----------------------------------------------------------------------------------------------
# Load configs (Master.conf)
# Load configs & helpers # ----------------------------------------------------------------------------------------------
if [[ -f "$SCRIPT_DIR/../Master.conf" ]]; then
source "$SCRIPT_DIR/../Master.conf" source "$SCRIPT_DIR/../Master.conf"
source "$SCRIPT_DIR/../common.sh" else
echo "❌ [ERROR] Master.conf not found"
exit 1
fi
# ----------------------------------------------------------------------------- # ----------------------------------------------------------------------------------------------
# Load shared helpers (if your common.sh provides these) # Load common.sh safely (MULTI-PATH FIX)
# ----------------------------------------------------------------------------- # ----------------------------------------------------------------------------------------------
COMMON_LOADED=false
COMMON_CANDIDATES=(
"$SCRIPT_DIR/../common.sh"
"$SCRIPT_DIR/common.sh"
"/mnt/user/appdata/unraid_scripts/common.sh"
"/mnt/user/appdata/unraid_scripts/Rsync/common.sh"
)
for c in "${COMMON_CANDIDATES[@]}"; do
if [[ -f "$c" ]]; then
source "$c"
COMMON_LOADED=true
break
fi
done
# ----------------------------------------------------------------------------------------------
# Fallback logging (ONLY if common.sh not loaded)
# ----------------------------------------------------------------------------------------------
if [[ "$COMMON_LOADED" != true ]]; then
log_info() { echo "️ [INFO] $*"; }
log_ok() { echo "✅ [OK] $*"; }
log_warn() { echo "⚠️ [WARN] $*"; }
log_error() { echo "❌ [ERROR] $*"; }
log_warn "common.sh not found — using fallback logger"
fi
# ----------------------------------------------------------------------------------------------
# Init
# ----------------------------------------------------------------------------------------------
log_info "Sync script initialized" log_info "Sync script initialized"
# -----------------------------------------------------------------------------
# Host resolution (safe fallback)
# -----------------------------------------------------------------------------
LOCAL_HOST="$(hostname)" LOCAL_HOST="$(hostname)"
REMOTE_HOST="${REMOTE_HOST:-jayred365}" REMOTE_HOST="${REMOTE_HOST:-jayred365}"
log_info "Host: ${LOCAL_HOST}${REMOTE_HOST}" log_info "Host: ${LOCAL_HOST}${REMOTE_HOST}"
# ----------------------------------------------------------------------------- # ----------------------------------------------------------------------------------------------
# Resolve remote IP # Resolve remote IP
# ----------------------------------------------------------------------------- # ----------------------------------------------------------------------------------------------
log_info "Resolving remote IP..." log_info "Resolving remote IP..."
REMOTE_IP="$(getent hosts "$REMOTE_HOST" | awk '{print $1}' || true)" REMOTE_IP="$(getent hosts "$REMOTE_HOST" | awk '{print $1}' || true)"
@@ -53,9 +76,9 @@ fi
log_info "Remote IP: $REMOTE_IP" log_info "Remote IP: $REMOTE_IP"
# ----------------------------------------------------------------------------- # ----------------------------------------------------------------------------------------------
# Config validation # Profile + paths
# ----------------------------------------------------------------------------- # ----------------------------------------------------------------------------------------------
PROFILE="${1:-arrs_stack}" PROFILE="${1:-arrs_stack}"
SOURCE_PATH="${SOURCE_PATH:-/mnt/user/appdata-Failover/Arrs_Stack}" SOURCE_PATH="${SOURCE_PATH:-/mnt/user/appdata-Failover/Arrs_Stack}"
@@ -68,29 +91,30 @@ log_info "Remote: $REMOTE_IP:$REMOTE_PATH"
log_info "Profile: $PROFILE" log_info "Profile: $PROFILE"
log_info "Dry Run: ${DRY_RUN:-false}" log_info "Dry Run: ${DRY_RUN:-false}"
# ----------------------------------------------------------------------------- # ----------------------------------------------------------------------------------------------
# Remote check # Remote check
# ----------------------------------------------------------------------------- # ----------------------------------------------------------------------------------------------
log_info "Checking remote..." log_info "Checking remote..."
if ! ssh -o BatchMode=yes -o ConnectTimeout=5 "${REMOTE_USER}@${REMOTE_IP}" "echo ok" >/dev/null 2>&1; then if ! ssh -o BatchMode=yes -o ConnectTimeout=5 \
"${REMOTE_USER}@${REMOTE_IP}" "echo ok" >/dev/null 2>&1; then
log_error "Remote unreachable" log_error "Remote unreachable"
exit 1 exit 1
fi fi
log_ok "Remote reachable" log_ok "Remote reachable"
# ----------------------------------------------------------------------------- # ----------------------------------------------------------------------------------------------
# Stop containers (if defined in common.sh) # Stop containers (optional)
# ----------------------------------------------------------------------------- # ----------------------------------------------------------------------------------------------
if declare -f stop_containers >/dev/null 2>&1; then if declare -f stop_containers >/dev/null 2>&1; then
log_info "Stopping containers..." log_info "Stopping containers..."
stop_containers "$PROFILE" || true stop_containers "$PROFILE" || true
fi fi
# ----------------------------------------------------------------------------- # ----------------------------------------------------------------------------------------------
# RSYNC EXECUTION # RSYNC EXECUTION
# ----------------------------------------------------------------------------- # ----------------------------------------------------------------------------------------------
log_info "Running rsync..." log_info "Running rsync..."
RSYNC_OPTS="-aHAX --delete --numeric-ids" RSYNC_OPTS="-aHAX --delete --numeric-ids"
@@ -106,9 +130,9 @@ rsync $RSYNC_OPTS \
log_ok "Rsync complete" log_ok "Rsync complete"
# ----------------------------------------------------------------------------- # ----------------------------------------------------------------------------------------------
# Restart containers (if defined) # Start containers (optional)
# ----------------------------------------------------------------------------- # ----------------------------------------------------------------------------------------------
if declare -f start_containers >/dev/null 2>&1; then if declare -f start_containers >/dev/null 2>&1; then
log_info "Starting containers..." log_info "Starting containers..."
start_containers "$PROFILE" || true start_containers "$PROFILE" || true