This commit is contained in:
2026-03-27 21:12:56 +00:00
parent f787a8efb8
commit f70433a1d4
+33 -26
View File
@@ -10,6 +10,7 @@ ICON_ERROR="❌"
ICON_SUCCESS="✅" ICON_SUCCESS="✅"
ICON_RUN="🚀" ICON_RUN="🚀"
ICON_STOP="🛑" ICON_STOP="🛑"
ICON_STOPPED="🟢"
ICON_SYNC="🔄" ICON_SYNC="🔄"
# ----------------------------- OUTPUT ----------------------------- # ----------------------------- OUTPUT -----------------------------
@@ -55,10 +56,6 @@ parse_args() {
--log) ENABLE_LOGGING=true ;; --log) ENABLE_LOGGING=true ;;
--no-log) ENABLE_LOGGING=false ;; --no-log) ENABLE_LOGGING=false ;;
--status|--summary) SHOW_STATUS=true ;; --status|--summary) SHOW_STATUS=true ;;
--help|-h)
echo "Usage: script <dir> [--dry-run] [--log]"
exit 0
;;
*) CLEAN_ARGS+=("$ARG") ;; *) CLEAN_ARGS+=("$ARG") ;;
esac esac
fi fi
@@ -100,11 +97,8 @@ detect_hosts() {
# ----------------------------- REMOTE ----------------------------- # ----------------------------- REMOTE -----------------------------
resolve_remote_ip() { resolve_remote_ip() {
log "Resolving remote IP..."
REMOTE_SERVER=$(tailscale ip -4 "$REMOTE_SERVER_NAME" 2>/dev/null) REMOTE_SERVER=$(tailscale ip -4 "$REMOTE_SERVER_NAME" 2>/dev/null)
[[ -z "$REMOTE_SERVER" ]] && error "Failed to resolve remote IP" && exit 1 [[ -z "$REMOTE_SERVER" ]] && error "Failed to resolve remote IP" && exit 1
info "Remote IP: $REMOTE_SERVER" info "Remote IP: $REMOTE_SERVER"
} }
@@ -118,7 +112,6 @@ stop_containers() {
RUNNING_CONTAINERS=() RUNNING_CONTAINERS=()
for c in "${CRITICAL_CONTAINER_NAMES[@]}"; do for c in "${CRITICAL_CONTAINER_NAMES[@]}"; do
log "Checking container: $c"
STATUS=$(ssh -i "$SSH_KEY" root@"$REMOTE_SERVER" \ STATUS=$(ssh -i "$SSH_KEY" root@"$REMOTE_SERVER" \
"docker inspect -f '{{.State.Running}}' $c 2>/dev/null" || echo "false") "docker inspect -f '{{.State.Running}}' $c 2>/dev/null" || echo "false")
@@ -133,7 +126,7 @@ stop_containers() {
error "Failed to stop $c" error "Failed to stop $c"
fi fi
else else
log "$c already stopped" echo "$ICON_STOPPED $c already stopped"
fi fi
done done
} }
@@ -160,13 +153,8 @@ wait_for_rsync() {
: "${MAX_RSYNC_PROCS:=2}" : "${MAX_RSYNC_PROCS:=2}"
: "${SLEEP:=2}" : "${SLEEP:=2}"
for i in $(seq 1 "$RETRY_COUNT"); do for _ 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) COUNT=$(pgrep -x rsync | wc -l || true)
fi
if [[ "$COUNT" -ge "$MAX_RSYNC_PROCS" ]]; then if [[ "$COUNT" -ge "$MAX_RSYNC_PROCS" ]]; then
warn "Waiting rsync slot ($COUNT/$MAX_RSYNC_PROCS)" warn "Waiting rsync slot ($COUNT/$MAX_RSYNC_PROCS)"
@@ -180,26 +168,47 @@ wait_for_rsync() {
exit 1 exit 1
} }
# ----------------------------- PROFILE CONFIG -----------------------------
declare -A PROFILE_BW_LIMIT=(
[arrs_stack]=5000
[critical-data]=9500
[gmer4lfe]=8000
[important-data]=9500
[emby]=8000
)
DEFAULT_RSYNC_OPTS=(
--archive
--delete
--partial
--compress
)
# ----------------------------- RSYNC OPTIONS ----------------------------- # ----------------------------- RSYNC OPTIONS -----------------------------
get_rsync_opts() { get_rsync_opts() {
if [[ -n "${PROFILE_RSYNC_OPTS[$PROFILE_NAME]:-}" ]]; then RSYNC_OPTS=()
read -r -a RSYNC_OPTS <<< "${PROFILE_RSYNC_OPTS[$PROFILE_NAME]}"
log "Using profile rsync opts" # base profile options
else
RSYNC_OPTS=("${DEFAULT_RSYNC_OPTS[@]}") RSYNC_OPTS=("${DEFAULT_RSYNC_OPTS[@]}")
log "Using default rsync opts"
# bwlimit (FIXED + ALWAYS APPLIED)
BW_LIMIT="${PROFILE_BW_LIMIT[$PROFILE_NAME]:-0}"
if [[ "$BW_LIMIT" -gt 0 ]]; then
RSYNC_OPTS+=(--bwlimit="$BW_LIMIT")
log "bwlimit=${BW_LIMIT}KB/s applied"
fi fi
# ------------------ CLEAN PROGRESS OUTPUT ------------------ # clean progress mode
if [[ "${ENABLE_PROGRESS:-false}" == true ]]; then if [[ "${ENABLE_PROGRESS:-false}" == true ]]; then
RSYNC_OPTS+=( RSYNC_OPTS+=(
--info=progress2 --quiet
--info=progress2,name0,stats0
--human-readable --human-readable
--no-inc-recursive --no-inc-recursive
--info=progress2,name0,stats0
) )
log "Progress enabled (clean mode)" log "Progress mode enabled"
fi fi
} }
@@ -210,8 +219,6 @@ show_status() {
echo "Remote: $REMOTE_SERVER_NAME" echo "Remote: $REMOTE_SERVER_NAME"
echo "IP: $REMOTE_SERVER" echo "IP: $REMOTE_SERVER"
echo "Profile: $PROFILE_NAME" echo "Profile: $PROFILE_NAME"
echo "DryRun: $DRY_RUN"
echo "Logging: $ENABLE_LOGGING"
echo "Progress: ${ENABLE_PROGRESS:-false}" echo "Progress: ${ENABLE_PROGRESS:-false}"
echo "==================" echo "=================="
} }