added user facing messages echo and power user admin info logging with a true false for logging

This commit is contained in:
2026-03-25 00:55:37 +00:00
parent 8506ef4a6a
commit b8b373784e
3 changed files with 120 additions and 27 deletions
+10 -16
View File
@@ -16,7 +16,7 @@ fi
shift
parse_args "$@"
# ----------------------------- Host & IP -----------------------------
# ----------------------------- Hosts & IP -----------------------------
detect_hosts
resolve_remote_ip
@@ -32,15 +32,16 @@ RETRY_COUNT=${PROFILE_RETRY_COUNT[$PROFILE_NAME]:-$RETRY_COUNT}
SLEEP=${PROFILE_SLEEP[$PROFILE_NAME]:-$SLEEP}
EXCLUDE_DIRS=(${PROFILE_EXCLUDE_DIRS[$PROFILE_NAME]:-${EXCLUDE_DIRS[@]}})
[[ "$ENABLE_LOGGING" == true ]] && echo "[LOG] Detected profile: $PROFILE_NAME"
[[ "$ENABLE_LOGGING" == true ]] && echo "[LOG] Settings: MAX_RSYNC_PROCS=$MAX_RSYNC_PROCS, BW_LIMIT=$BW_LIMIT, CONTAINERS=${CRITICAL_CONTAINER_NAMES[*]}, EXCLUDES=${EXCLUDE_DIRS[*]}, DRY_RUN=$DRY_RUN"
echo "Detected profile: $PROFILE_NAME"
log "Profile settings: MAX_RSYNC_PROCS=$MAX_RSYNC_PROCS, BW_LIMIT=$BW_LIMIT, CONTAINERS=${CRITICAL_CONTAINER_NAMES[*]}, EXCLUDES=${EXCLUDE_DIRS[*]}, DRY_RUN=$DRY_RUN"
# ----------------------------- Rsync Wait -----------------------------
wait_for_rsync() {
for attempt in $(seq 1 "$RETRY_COUNT"); do
RSYNC_COUNT=$(pgrep -fc "rsync.*root@${REMOTE_SERVER}" || true)
log "Current rsync processes: $RSYNC_COUNT"
if [ "$RSYNC_COUNT" -ge "$MAX_RSYNC_PROCS" ]; then
[[ "$ENABLE_LOGGING" == true ]] && echo "[LOG] Waiting... ($RSYNC_COUNT active rsync processes)"
echo "Waiting for available rsync slot ($RSYNC_COUNT active)..."
sleep "$SLEEP"
else
return 0
@@ -52,25 +53,17 @@ wait_for_rsync() {
# ----------------------------- Main -----------------------------
main() {
[[ "$ENABLE_LOGGING" == true ]] && echo "[LOG] Starting sync: $DIRECTORY$REMOTE_SERVER:$DIRECTORY"
# Ping check
for i in $(seq 1 "$RETRY_COUNT"); do
if ping -c 1 "$REMOTE_SERVER" &>/dev/null; then break; fi
echo "Remote $REMOTE_SERVER_NAME down, retrying in $SLEEP seconds..."
sleep "$SLEEP"
done
ping -c 1 "$REMOTE_SERVER" &>/dev/null || { echo "Remote $REMOTE_SERVER_NAME unreachable. Exiting."; exit 1; }
echo "Starting sync: $DIRECTORY$REMOTE_SERVER"
wait_for_rsync
stop_containers
get_rsync_opts
for ex in "${EXCLUDE_DIRS[@]}"; do RSYNC_OPTS+=(--exclude="$ex"); done
[ "$DRY_RUN" = true ] && RSYNC_OPTS+=("--dry-run")
log "Rsync options: ${RSYNC_OPTS[*]}"
for attempt in $(seq 1 "$RETRY_COUNT"); do
echo "Starting rsync attempt $attempt/$RETRY_COUNT..."
echo "Rsync attempt $attempt/$RETRY_COUNT..."
if rsync "${RSYNC_OPTS[@]}" -e "ssh -i \"$SSH_KEY\" -T -o Compression=no -o IPQoS=throughput" \
"$DIRECTORY" "root@${REMOTE_SERVER}:$DIRECTORY"; then
echo "Rsync completed successfully."
@@ -89,7 +82,8 @@ main() {
done
start_containers
[[ "$ENABLE_LOGGING" == true ]] && echo "[LOG] Sync complete."
echo "Sync complete."
log "[$LOCAL_SERVER_NAME] Sync finished for $DIRECTORY$REMOTE_SERVER"
}
main