bug fixes

This commit is contained in:
2026-03-27 22:35:52 +00:00
parent 02e20cdf42
commit 4bd864343b
3 changed files with 43 additions and 151 deletions
+12 -21
View File
@@ -2,18 +2,6 @@
# ----------------------------------------------------------------------------------------------
# ---------------------------- Master Variables for unRAID scripts -----------------------------
# ----------------------------------------------------------------------------------------------
# This is the master.conf file, it contains all the variables used by
# all scripts.
#
# It is sourced by each script at runtime, so any changes here will
# affect all scripts immediately.
#
# This is where you should adjust any settings or variables
# that you want to apply globally across all your scripts
#
# ----------------------------------------------------------------------------------------------
# ---------------- User Variables, Please adjust here in Master.conf as needed -----------------
# ----------------------------------------------------------------------------------------------
# ----------------------- Host Configuration --------------------
# List the Hostnames of both servers
@@ -71,14 +59,16 @@ SSH_PORT=221
# Profiles are inferred from the directory basename (lowercased)
# Profile-specific rsync options (override global) must list all options as they do not inherit from global
# For example, look up at global rsync options above
# SPACE-SEPARATED STRINGS
declare -A PROFILE_RSYNC_OPTS=(
[arrs_stack]="-av --info=progress2 --human-readable --bwlimit=$BW_LIMIT --delete --inplace --no-whole-file"
[arrs_stack]="-av --info=progress2 --human-readable --bwlimit=$BW_LIMIT --delete --inplace"
[critical-data]="-av --human-readable --bwlimit=$BW_LIMIT --delete"
[gmer4lfe]="-av --info=progress2 --bwlimit=$BW_LIMIT"
[important-data]="-av --human-readable --bwlimit=$BW_LIMIT"
[emby]="-av --human-readable --bwlimit=$BW_LIMIT"
)
# Max rsync processes per profile
declare -A PROFILE_MAX_PROCS=(
[arrs_stack]=2
[critical-data]=2
@@ -86,7 +76,7 @@ declare -A PROFILE_MAX_PROCS=(
[important-data]=2
[emby]=1
)
# Bandwidth limits per profile (KB/s, 0 = unlimited)
declare -A PROFILE_BW_LIMIT=(
[arrs_stack]=5000
[critical-data]=9500
@@ -94,7 +84,7 @@ declare -A PROFILE_BW_LIMIT=(
[important-data]=9500
[emby]=8000
)
# Retry logic per profile
declare -A PROFILE_RETRY_COUNT=(
[arrs_stack]=3
[critical-data]=3
@@ -102,7 +92,7 @@ declare -A PROFILE_RETRY_COUNT=(
[important-data]=3
[emby]=3
)
# Sleep between retries per profile (seconds)
declare -A PROFILE_SLEEP=(
[arrs_stack]=300
[critical-data]=300
@@ -110,7 +100,8 @@ declare -A PROFILE_SLEEP=(
[important-data]=300
[emby]=300
)
# Containers to stop/start per profile (space-separated strings)
# SPACE-SEPARATED STRINGS
declare -A PROFILE_CRITICAL_CONTAINER_NAMES=(
[arrs_stack]="Sonarr Lidarr Readarr Radarr Prowlarr Bazarr Pinchflat"
[critical-data]="Mariadb-Authelia Redis-Authelia Lldap-Gmer4Lfe NginxProxyManager Authelia"
@@ -118,7 +109,7 @@ declare -A PROFILE_CRITICAL_CONTAINER_NAMES=(
[important-data]="Postgres-NextCloud NextCloud"
[emby]=""
)
# Delayed containers per profile (space-separated strings)
declare -A PROFILE_DELAYED_CONTAINERS=(
[arrs_stack]=""
[critical-data]="Authelia"
@@ -126,7 +117,7 @@ declare -A PROFILE_DELAYED_CONTAINERS=(
[important-data]="NextCloud"
[emby]=""
)
# Delay in seconds before starting delayed containers per profile (seconds)
declare -A PROFILE_CONTAINER_DELAY=(
[arrs_stack]=5
[critical-data]=10
@@ -134,7 +125,7 @@ declare -A PROFILE_CONTAINER_DELAY=(
[important-data]=10
[emby]=5
)
# Not include logs or other file types during transfer per profile
# SPACE-SEPARATED STRINGS
declare -A PROFILE_EXCLUDE_DIRS=(
[arrs_stack]="logs *.tmp"
[critical-data]="logs *.tmp"
+10 -64
View File
@@ -11,18 +11,13 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "$SCRIPT_DIR/../Master.conf"
source "$SCRIPT_DIR/../common.sh"
# ARG PARSING FIX
DIRECTORY=""
RAW_ARGS=()
for ARG in "$@"; do
case "$ARG" in
--*|*=*)
RAW_ARGS+=("$ARG")
;;
*)
[[ -z "$DIRECTORY" ]] && DIRECTORY="$ARG" || RAW_ARGS+=("$ARG")
;;
--*|*=*) RAW_ARGS+=("$ARG") ;;
*) [[ -z "$DIRECTORY" ]] && DIRECTORY="$ARG" || RAW_ARGS+=("$ARG") ;;
esac
done
@@ -30,95 +25,46 @@ parse_args "${RAW_ARGS[@]}"
[[ -z "$DIRECTORY" ]] && error "Missing directory" && exit 1
# HOST
detect_hosts
resolve_remote_ip
# PROFILE
PROFILE_NAME=$(basename "$DIRECTORY" | tr '[:upper:]' '[:lower:]')
MAX_RSYNC_PROCS=${PROFILE_MAX_PROCS[$PROFILE_NAME]:-$MAX_RSYNC_PROCS}
BW_LIMIT=${PROFILE_BW_LIMIT[$PROFILE_NAME]:-$BW_LIMIT}
CRITICAL_CONTAINER_NAMES=(${PROFILE_CRITICAL_CONTAINER_NAMES[$PROFILE_NAME]})
DELAYED_CONTAINERS=(${PROFILE_DELAYED_CONTAINERS[$PROFILE_NAME]})
CONTAINER_DELAY=${PROFILE_CONTAINER_DELAY[$PROFILE_NAME]:-$CONTAINER_DELAY}
RETRY_COUNT=${PROFILE_RETRY_COUNT[$PROFILE_NAME]:-$RETRY_COUNT}
SLEEP=${PROFILE_SLEEP[$PROFILE_NAME]:-$SLEEP}
EXCLUDE_DIRS=(${PROFILE_EXCLUDE_DIRS[$PROFILE_NAME]:-${EXCLUDE_DIRS[@]}})
# STATUS
if [[ "${SHOW_STATUS:-false}" == true ]]; then
show_status
exit 0
fi
CRITICAL_CONTAINER_NAMES="${PROFILE_CRITICAL_CONTAINER_NAMES[$PROFILE_NAME]}"
DELAYED_CONTAINERS="${PROFILE_DELAYED_CONTAINERS[$PROFILE_NAME]}"
CONTAINER_DELAY=${PROFILE_CONTAINER_DELAY[$PROFILE_NAME]:-$CONTAINER_DELAY}
EXCLUDE_DIRS="${PROFILE_EXCLUDE_DIRS[$PROFILE_NAME]}"
[[ "$SHOW_STATUS" == true ]] && show_status && exit 0
# HEADER
echo
echo "$ICON_RUN Sync Starting"
echo "Source: $DIRECTORY"
echo "Remote: $REMOTE_SERVER:$DIRECTORY"
echo "Profile: $PROFILE_NAME"
echo "Dry Run: $DRY_RUN"
# REMOTE CHECK FIX
echo "$ICON_GEAR Checking remote..."
REMOTE_OK=false
for i in $(seq 1 "$RETRY_COUNT"); do
if ping -c 1 "$REMOTE_SERVER" &>/dev/null; then
success "Remote reachable"
REMOTE_OK=true
break
fi
warn "Retry $i/$RETRY_COUNT"
sleep "$SLEEP"
done
if [[ "$REMOTE_OK" != true ]]; then
error "Remote unreachable"
exit 1
fi
# RSYNC LIMIT
wait_for_rsync() {
for i in $(seq 1 "$RETRY_COUNT"); do
COUNT=$(pgrep -fc "rsync.*root@${REMOTE_SERVER}" || true)
if [[ "$COUNT" -ge "$MAX_RSYNC_PROCS" ]]; then
warn "Waiting rsync slot ($COUNT)"
sleep "$SLEEP"
else
return 0
fi
done
error "Too many rsync processes"
exit 1
}
wait_for_rsync
# RUN
stop_containers
get_rsync_opts
for ex in "${EXCLUDE_DIRS[@]}"; do
for ex in $EXCLUDE_DIRS; do
RSYNC_OPTS+=(--exclude="$ex")
done
[[ "$DRY_RUN" == true ]] && RSYNC_OPTS+=("--dry-run")
echo "$ICON_RUN Running rsync..."
START=$(date +%s)
for i in $(seq 1 "$RETRY_COUNT"); do
if rsync "${RSYNC_OPTS[@]}" \
-e "ssh -i $SSH_KEY -T -o Compression=no -o IPQoS=throughput" \
"$DIRECTORY" "root@${REMOTE_SERVER}:$DIRECTORY"; then
success "Rsync complete"
break
else
@@ -130,7 +76,7 @@ done
start_containers
END=$(date +%s)
echo
echo "===== SUMMARY ====="
echo "Directory: $DIRECTORY"
echo "Profile: $PROFILE_NAME"
+21 -66
View File
@@ -1,9 +1,6 @@
#!/bin/bash
# -----------------------------------------------------------------------------------------------
# ----------------- UNRAID OPS COMMON LIBRARY (STABLE FRAMEWORK v1) -----------------------
# -----------------------------------------------------------------------------------------------
# ICONS Profiles
# ---------------- ICONS ----------------
ICON_INFO="️"
ICON_WARN="⚠️"
ICON_ERROR="❌"
@@ -14,17 +11,13 @@ ICON_RETRY="🔁"
ICON_SYNC="🔄"
ICON_GEAR="⚙️"
# OUTPUT
info() { echo "$ICON_INFO [INFO] $*"; }
warn() { echo "$ICON_WARN [WARN] $*"; }
error() { echo "$ICON_ERROR [ERROR] $*"; }
success() { echo "$ICON_SUCCESS [OK] $*"; }
log() { [[ "${ENABLE_LOGGING:-false}" == true ]] && echo "[LOG] $*"; }
log() {
[[ "${ENABLE_LOGGING:-false}" == true ]] && echo "[LOG] $*"
}
# ARG PARSER
# ---------------- ARG PARSER ----------------
parse_args() {
ENABLE_LOGGING=${ENABLE_LOGGING:-false}
DRY_RUN=${DRY_RUN:-false}
@@ -33,48 +26,23 @@ parse_args() {
CLEAN_ARGS=()
for ARG in "$@"; do
if [[ "$ARG" == *=* ]]; then
VAR="${ARG%%=*}"
VAL="${ARG#*=}"
case "$VAR" in
LOG)
[[ "$VAL" == "true" ]] && ENABLE_LOGGING=true
[[ "$VAL" == "false" ]] && ENABLE_LOGGING=false
;;
*)
if declare -p "$VAR" &>/dev/null; then
printf -v "$VAR" '%s' "$VAL"
log "Set $VAR=$VAL"
else
warn "Unknown variable: $VAR"
fi
;;
esac
else
case "$ARG" in
--dry-run|-n) DRY_RUN=true ;;
--log) ENABLE_LOGGING=true ;;
--no-log) ENABLE_LOGGING=false ;;
--status|--summary) SHOW_STATUS=true ;;
--help|-h)
echo "Usage: script <dir> [--dry-run] [--log]"
exit 0
;;
*) CLEAN_ARGS+=("$ARG") ;;
esac
fi
case "$ARG" in
--dry-run|-n) DRY_RUN=true ;;
--log) ENABLE_LOGGING=true ;;
--no-log) ENABLE_LOGGING=false ;;
--status|--summary) SHOW_STATUS=true ;;
*) CLEAN_ARGS+=("$ARG") ;;
esac
done
PARSED_ARGS=("${CLEAN_ARGS[@]}")
}
# VALIDATION
require_var() {
[[ -z "${!1:-}" ]] && error "Missing required: $1" && exit 1
}
# HOST DETECTION
# ---------------- HOST DETECTION ----------------
detect_hosts() {
LOCAL_HOSTNAME="$(hostname)"
@@ -100,27 +68,24 @@ detect_hosts() {
info "Host: $LOCAL_SERVER_NAME$REMOTE_SERVER_NAME"
}
# REMOTE
resolve_remote_ip() {
log "Resolving remote IP..."
REMOTE_SERVER=$(tailscale ip -4 "$REMOTE_SERVER_NAME" 2>/dev/null)
[[ -z "$REMOTE_SERVER" ]] && error "Failed to resolve remote IP" && exit 1
info "Remote IP: $REMOTE_SERVER"
}
# CONTAINERS
# ---------------- CONTAINERS (FIXED) ----------------
RUNNING_CONTAINERS=()
stop_containers() {
[[ ${#CRITICAL_CONTAINER_NAMES[@]} -eq 0 ]] && return
[[ -z "${CRITICAL_CONTAINER_NAMES:-}" ]] && return
read -r -a containers <<< "${CRITICAL_CONTAINER_NAMES}"
info "Stopping containers..."
RUNNING_CONTAINERS=()
for c in "${CRITICAL_CONTAINER_NAMES[@]}"; do
info "Checking container: $c"
for c in "${containers[@]}"; do
[[ -z "$c" ]] && continue
STATUS=$(ssh -i "$SSH_KEY" root@"$REMOTE_SERVER" \
"docker inspect -f '{{.State.Running}}' $c 2>/dev/null" || echo "false")
@@ -135,7 +100,7 @@ stop_containers() {
error "Failed to stop $c"
fi
else
log "$c already stopped"
success "$c already stopped"
fi
done
}
@@ -146,8 +111,6 @@ start_containers() {
info "Starting containers..."
for c in "${RUNNING_CONTAINERS[@]}"; do
info "Starting $c"
if ssh -i "$SSH_KEY" root@"$REMOTE_SERVER" "docker start $c" >/dev/null; then
success "$c started"
else
@@ -156,19 +119,14 @@ start_containers() {
done
}
# RSYNC LIMITER
# ---------------- RSYNC LIMIT ----------------
wait_for_rsync() {
: "${RETRY_COUNT:=5}"
: "${MAX_RSYNC_PROCS:=2}"
: "${SLEEP:=2}"
for i in $(seq 1 "$RETRY_COUNT"); do
COUNT=$(ps -eo pid,cmd | grep "[r]sync .*${REMOTE_SERVER:-}" | wc -l || true)
if [[ -z "$REMOTE_SERVER" ]]; then
COUNT=$(pgrep -x rsync | wc -l || true)
fi
COUNT=$(pgrep -fc "rsync" || true)
if [[ "$COUNT" -ge "$MAX_RSYNC_PROCS" ]]; then
warn "Waiting rsync slot ($COUNT/$MAX_RSYNC_PROCS)"
@@ -182,7 +140,7 @@ wait_for_rsync() {
exit 1
}
# RSYNC OPTIONS
# ---------------- RSYNC OPTS ----------------
get_rsync_opts() {
if [[ -n "${PROFILE_RSYNC_OPTS[$PROFILE_NAME]:-}" ]]; then
read -r -a RSYNC_OPTS <<< "${PROFILE_RSYNC_OPTS[$PROFILE_NAME]}"
@@ -191,14 +149,11 @@ get_rsync_opts() {
fi
}
# STATUS
show_status() {
echo "===== STATUS ====="
echo "Local: $LOCAL_SERVER_NAME"
echo "Remote: $REMOTE_SERVER_NAME"
echo "IP: $REMOTE_SERVER"
echo "Profile: $PROFILE_NAME"
echo "DryRun: $DRY_RUN"
echo "Logging: $ENABLE_LOGGING"
echo "=================="
}