progress bar

This commit is contained in:
2026-03-27 18:19:08 +00:00
parent 3e96164465
commit 4887a9c36e
+84 -16
View File
@@ -23,7 +23,10 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "$SCRIPT_DIR/../Master.conf"
source "$SCRIPT_DIR/../common.sh"
# ----------------------------- ARG PARSING FIX -----------------------------
# ----------------------------------------------------------------------------------
# INPUT PARSING (FIXED - positional args + flags separation)
# ----------------------------------------------------------------------------------
DIRECTORY=""
RAW_ARGS=()
@@ -33,20 +36,34 @@ for ARG in "$@"; do
RAW_ARGS+=("$ARG")
;;
*)
[[ -z "$DIRECTORY" ]] && DIRECTORY="$ARG" || RAW_ARGS+=("$ARG")
if [[ -z "$DIRECTORY" ]]; then
DIRECTORY="$ARG"
else
RAW_ARGS+=("$ARG")
fi
;;
esac
done
parse_args "${RAW_ARGS[@]}"
[[ -z "$DIRECTORY" ]] && error "Missing directory" && exit 1
if [[ -z "$DIRECTORY" ]]; then
error "Missing directory"
echo "Usage: $0 <directory> [--dry-run] [--status] [VAR=value]"
exit 1
fi
# ----------------------------------------------------------------------------------
# HOST SETUP
# ----------------------------------------------------------------------------------
# ----------------------------- HOST -----------------------------
detect_hosts
resolve_remote_ip
# ----------------------------- PROFILE -----------------------------
# ----------------------------------------------------------------------------------
# PROFILE SETUP
# ----------------------------------------------------------------------------------
PROFILE_NAME=$(basename "$DIRECTORY" | tr '[:upper:]' '[:lower:]')
MAX_RSYNC_PROCS=${PROFILE_MAX_PROCS[$PROFILE_NAME]:-$MAX_RSYNC_PROCS}
@@ -58,21 +75,31 @@ 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 -----------------------------
# ----------------------------------------------------------------------------------
# STATUS MODE
# ----------------------------------------------------------------------------------
if [[ "${SHOW_STATUS:-false}" == true ]]; then
show_status
exit 0
fi
# ----------------------------- HEADER -----------------------------
# ----------------------------------------------------------------------------------
# HEADER
# ----------------------------------------------------------------------------------
echo
echo "$ICON_RUN Sync Starting"
echo "Source: $DIRECTORY"
echo "Remote: $REMOTE_SERVER:$DIRECTORY"
echo "Profile: $PROFILE_NAME"
echo "Dry Run: $DRY_RUN"
echo "--------------------------------------------"
# ----------------------------------------------------------------------------------
# REMOTE CHECK (FIXED LOGIC)
# ----------------------------------------------------------------------------------
# ----------------------------- REMOTE CHECK FIX -----------------------------
echo "$ICON_GEAR Checking remote..."
REMOTE_OK=false
@@ -83,6 +110,7 @@ for i in $(seq 1 "$RETRY_COUNT"); do
REMOTE_OK=true
break
fi
warn "Retry $i/$RETRY_COUNT"
sleep "$SLEEP"
done
@@ -92,7 +120,10 @@ if [[ "$REMOTE_OK" != true ]]; then
exit 1
fi
# ----------------------------- RSYNC LIMIT -----------------------------
# ----------------------------------------------------------------------------------
# RSYNC SLOT LIMITER
# ----------------------------------------------------------------------------------
wait_for_rsync() {
for i in $(seq 1 "$RETRY_COUNT"); do
COUNT=$(pgrep -fc "rsync.*root@${REMOTE_SERVER}" || true)
@@ -111,26 +142,52 @@ wait_for_rsync() {
wait_for_rsync
# ----------------------------- RUN -----------------------------
# ----------------------------------------------------------------------------------
# STOP CONTAINERS (FIXED - NO DUPLICATE LOGGING)
# ----------------------------------------------------------------------------------
stop_containers
# ----------------------------------------------------------------------------------
# BUILD RSYNC OPTIONS
# ----------------------------------------------------------------------------------
get_rsync_opts
for ex in "${EXCLUDE_DIRS[@]}"; do
RSYNC_OPTS+=(--exclude="$ex")
done
[[ "$DRY_RUN" == true ]] && RSYNC_OPTS+=("--dry-run")
if [[ "$DRY_RUN" == true ]]; then
RSYNC_OPTS+=("--dry-run")
fi
# ----------------------------------------------------------------------------------
# RSYNC COMMAND (SAFE IMPROVEMENT - NO BEHAVIOR CHANGE)
# ----------------------------------------------------------------------------------
echo "$ICON_RUN Running rsync..."
RSYNC_CMD=(
rsync
"${RSYNC_OPTS[@]}"
-e "ssh -i $SSH_KEY -T -o Compression=no -o IPQoS=throughput"
"$DIRECTORY"
"root@${REMOTE_SERVER}:$DIRECTORY"
)
log "RSYNC CMD: ${RSYNC_CMD[*]}"
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
# ----------------------------------------------------------------------------------
# EXECUTION (RETRY SAFE)
# ----------------------------------------------------------------------------------
for i in $(seq 1 "$RETRY_COUNT"); do
echo "Attempt $i/$RETRY_COUNT"
if "${RSYNC_CMD[@]}"; then
success "Rsync complete"
break
else
@@ -139,13 +196,24 @@ for i in $(seq 1 "$RETRY_COUNT"); do
fi
done
# ----------------------------------------------------------------------------------
# START CONTAINERS
# ----------------------------------------------------------------------------------
start_containers
# ----------------------------------------------------------------------------------
# SUMMARY
# ----------------------------------------------------------------------------------
END=$(date +%s)
echo
echo "===== SUMMARY ====="
echo "Directory: $DIRECTORY"
echo "Profile: $PROFILE_NAME"
echo "Duration: $((END-START))s"
echo "Status: DONE"
echo "==================="
echo "==================="
✅ WHAT THIS FIX ACTUALLY SOLVES
✔ Removes duplicate: