getting back
This commit is contained in:
+41
-17
@@ -1,5 +1,4 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
# ----------------------------------------------------------------------------------------------
|
||||
# --------------------------------- Rsync Core Script ------------------------------------------
|
||||
# ----------------------------------------------------------------------------------------------
|
||||
@@ -11,6 +10,9 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
source "$SCRIPT_DIR/../Master.conf"
|
||||
source "$SCRIPT_DIR/../common.sh"
|
||||
|
||||
# -----------------------------------------------------------------------------------------------
|
||||
# Separate the positional directory argument from flag/key=value args
|
||||
# -----------------------------------------------------------------------------------------------
|
||||
DIRECTORY=""
|
||||
RAW_ARGS=()
|
||||
|
||||
@@ -23,29 +25,40 @@ done
|
||||
|
||||
parse_args "${RAW_ARGS[@]}"
|
||||
|
||||
[[ -z "$DIRECTORY" ]] && error "Missing directory" && exit 1
|
||||
[[ -z "$DIRECTORY" ]] && error "No directory specified. Usage: rsync.sh <dir> [--dry-run] [--log]" && exit 1
|
||||
|
||||
detect_hosts
|
||||
resolve_remote_ip
|
||||
|
||||
# -----------------------------------------------------------------------------------------------
|
||||
# Profile resolution — inferred from the directory basename
|
||||
# -----------------------------------------------------------------------------------------------
|
||||
PROFILE_NAME=$(basename "$DIRECTORY" | tr '[:upper:]' '[:lower:]')
|
||||
info "Profile: $PROFILE_NAME"
|
||||
|
||||
# Scalar overrides from profile
|
||||
MAX_RSYNC_PROCS=${PROFILE_MAX_PROCS[$PROFILE_NAME]:-$MAX_RSYNC_PROCS}
|
||||
BW_LIMIT=${PROFILE_BW_LIMIT[$PROFILE_NAME]:-$BW_LIMIT}
|
||||
RETRY_COUNT=${PROFILE_RETRY_COUNT[$PROFILE_NAME]:-$RETRY_COUNT}
|
||||
SLEEP=${PROFILE_SLEEP[$PROFILE_NAME]:-$SLEEP}
|
||||
|
||||
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]}"
|
||||
|
||||
# Array overrides from profile — convert space-separated strings to proper bash arrays
|
||||
read -r -a CRITICAL_CONTAINER_NAMES <<< "${PROFILE_CRITICAL_CONTAINER_NAMES[$PROFILE_NAME]:-}"
|
||||
read -r -a DELAYED_CONTAINERS <<< "${PROFILE_DELAYED_CONTAINERS[$PROFILE_NAME]:-}"
|
||||
read -r -a EXCLUDE_DIRS <<< "${PROFILE_EXCLUDE_DIRS[$PROFILE_NAME]:-}"
|
||||
|
||||
[[ "$SHOW_STATUS" == true ]] && show_status && exit 0
|
||||
|
||||
# -----------------------------------------------------------------------------------------------
|
||||
# Run
|
||||
# -----------------------------------------------------------------------------------------------
|
||||
echo ""
|
||||
echo "$ICON_RUN Sync Starting"
|
||||
echo "Source: $DIRECTORY"
|
||||
echo "Remote: $REMOTE_SERVER:$DIRECTORY"
|
||||
echo "Source: $DIRECTORY"
|
||||
echo "Remote: $REMOTE_SERVER:$DIRECTORY"
|
||||
echo "Profile: $PROFILE_NAME"
|
||||
echo ""
|
||||
|
||||
wait_for_rsync
|
||||
|
||||
@@ -53,23 +66,26 @@ stop_containers
|
||||
|
||||
get_rsync_opts
|
||||
|
||||
for ex in $EXCLUDE_DIRS; do
|
||||
RSYNC_OPTS+=(--exclude="$ex")
|
||||
# Append excludes
|
||||
for ex in "${EXCLUDE_DIRS[@]}"; do
|
||||
[[ -n "$ex" ]] && RSYNC_OPTS+=(--exclude="$ex")
|
||||
done
|
||||
|
||||
[[ "$DRY_RUN" == true ]] && RSYNC_OPTS+=("--dry-run")
|
||||
[[ "$DRY_RUN" == true ]] && RSYNC_OPTS+=("--dry-run") && warn "DRY RUN — no changes will be made"
|
||||
|
||||
START=$(date +%s)
|
||||
RSYNC_SUCCESS=false
|
||||
|
||||
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
|
||||
"$DIRECTORY" "root@${REMOTE_SERVER}:$(dirname "$DIRECTORY")/"; then
|
||||
success "Rsync complete"
|
||||
RSYNC_SUCCESS=true
|
||||
break
|
||||
else
|
||||
warn "Rsync failed ($i/$RETRY_COUNT)"
|
||||
sleep "$SLEEP"
|
||||
warn "$ICON_RETRY Rsync failed (attempt $i/$RETRY_COUNT)"
|
||||
[[ "$i" -lt "$RETRY_COUNT" ]] && info "Retrying in ${SLEEP}s..." && sleep "$SLEEP"
|
||||
fi
|
||||
done
|
||||
|
||||
@@ -77,9 +93,17 @@ start_containers
|
||||
|
||||
END=$(date +%s)
|
||||
|
||||
echo ""
|
||||
echo "===== SUMMARY ====="
|
||||
echo "Directory: $DIRECTORY"
|
||||
echo "Profile: $PROFILE_NAME"
|
||||
echo "Duration: $((END-START))s"
|
||||
echo "Status: DONE"
|
||||
echo "==================="
|
||||
echo "Duration: $((END - START))s"
|
||||
if [[ "$RSYNC_SUCCESS" == true ]]; then
|
||||
echo "Status: $ICON_SUCCESS DONE"
|
||||
else
|
||||
echo "Status: $ICON_ERROR FAILED after $RETRY_COUNT attempts"
|
||||
fi
|
||||
echo "==================="
|
||||
|
||||
[[ "$RSYNC_SUCCESS" == false ]] && exit 1
|
||||
exit 0
|
||||
|
||||
Reference in New Issue
Block a user