diff --git a/common.sh b/common.sh index ef28eb5..222a333 100644 --- a/common.sh +++ b/common.sh @@ -10,6 +10,7 @@ ICON_ERROR="❌" ICON_SUCCESS="✅" ICON_RUN="🚀" ICON_STOP="🛑" +ICON_STOPPED="🟢" ICON_SYNC="🔄" # ----------------------------- OUTPUT ----------------------------- @@ -55,10 +56,6 @@ parse_args() { --log) ENABLE_LOGGING=true ;; --no-log) ENABLE_LOGGING=false ;; --status|--summary) SHOW_STATUS=true ;; - --help|-h) - echo "Usage: script [--dry-run] [--log]" - exit 0 - ;; *) CLEAN_ARGS+=("$ARG") ;; esac fi @@ -100,11 +97,8 @@ detect_hosts() { # ----------------------------- 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" } @@ -118,7 +112,6 @@ stop_containers() { RUNNING_CONTAINERS=() for c in "${CRITICAL_CONTAINER_NAMES[@]}"; do - log "Checking container: $c" STATUS=$(ssh -i "$SSH_KEY" root@"$REMOTE_SERVER" \ "docker inspect -f '{{.State.Running}}' $c 2>/dev/null" || echo "false") @@ -133,7 +126,7 @@ stop_containers() { error "Failed to stop $c" fi else - log "$c already stopped" + echo "$ICON_STOPPED $c already stopped" fi done } @@ -160,13 +153,8 @@ wait_for_rsync() { : "${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 + for _ in $(seq 1 "$RETRY_COUNT"); do + COUNT=$(pgrep -x rsync | wc -l || true) if [[ "$COUNT" -ge "$MAX_RSYNC_PROCS" ]]; then warn "Waiting rsync slot ($COUNT/$MAX_RSYNC_PROCS)" @@ -180,26 +168,47 @@ wait_for_rsync() { 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 ----------------------------- get_rsync_opts() { - if [[ -n "${PROFILE_RSYNC_OPTS[$PROFILE_NAME]:-}" ]]; then - read -r -a RSYNC_OPTS <<< "${PROFILE_RSYNC_OPTS[$PROFILE_NAME]}" - log "Using profile rsync opts" - else - RSYNC_OPTS=("${DEFAULT_RSYNC_OPTS[@]}") - log "Using default rsync opts" + RSYNC_OPTS=() + + # base profile options + RSYNC_OPTS=("${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 - # ------------------ CLEAN PROGRESS OUTPUT ------------------ + # clean progress mode if [[ "${ENABLE_PROGRESS:-false}" == true ]]; then RSYNC_OPTS+=( - --info=progress2 + --quiet + --info=progress2,name0,stats0 --human-readable --no-inc-recursive - --info=progress2,name0,stats0 - ) - log "Progress enabled (clean mode)" + ) + log "Progress mode enabled" fi } @@ -210,8 +219,6 @@ show_status() { echo "Remote: $REMOTE_SERVER_NAME" echo "IP: $REMOTE_SERVER" echo "Profile: $PROFILE_NAME" - echo "DryRun: $DRY_RUN" - echo "Logging: $ENABLE_LOGGING" echo "Progress: ${ENABLE_PROGRESS:-false}" echo "==================" } \ No newline at end of file