Structure change and vissually fixing code to make it easier to read
This commit is contained in:
+24
-7
@@ -1,5 +1,22 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
# ----------------------------------------------------------------------------------------------
|
||||
# --------------------------------- Rsync Core Script ------------------------------------------
|
||||
# ----------------------------------------------------------------------------------------------
|
||||
# ---------------- User Variables, Please adjust in Master.conf as needed ----------------------
|
||||
# ----------------------------------------------------------------------------------------------
|
||||
#
|
||||
# User variables can be adjusted in Master.conf
|
||||
#
|
||||
# Scripts now just contain runtime logic
|
||||
#
|
||||
# This new setup allows for profiles and arguments to use the core script
|
||||
#
|
||||
# Use arguments in unRAID User Plugin for directory
|
||||
# Example = /mnt/user/appdata/unraid_scripts/Rsync/rsync.sh --dry-run
|
||||
# ----------------------------------------------------------------------------------------------
|
||||
# -------------- End Of User Variables, Please adjust in Master.conf as needed -----------------
|
||||
# ----------------------------------------------------------------------------------------------
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
|
||||
@@ -7,7 +24,7 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
source "$SCRIPT_DIR/../Master.conf"
|
||||
source "$SCRIPT_DIR/../common.sh"
|
||||
|
||||
# ----------------------------- Input -----------------------------
|
||||
# Input
|
||||
DIRECTORY="$1"
|
||||
if [[ -z "$DIRECTORY" ]]; then
|
||||
echo "Usage: $0 <directory-to-sync> [--dry-run] [VAR=value ...]"
|
||||
@@ -16,11 +33,11 @@ fi
|
||||
shift
|
||||
parse_args "$@"
|
||||
|
||||
# ----------------------------- Host & IP -----------------------------
|
||||
# Host & IP
|
||||
detect_hosts
|
||||
resolve_remote_ip
|
||||
|
||||
# ----------------------------- Profile -----------------------------
|
||||
# Profile
|
||||
PROFILE_NAME=$(basename "$DIRECTORY" | tr '[:upper:]' '[:lower:]')
|
||||
|
||||
MAX_RSYNC_PROCS=${PROFILE_MAX_PROCS[$PROFILE_NAME]:-$MAX_RSYNC_PROCS}
|
||||
@@ -32,14 +49,14 @@ 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 Mode -----------------------------
|
||||
# Status Mode
|
||||
if [[ "$SHOW_STATUS" == true ]]; then
|
||||
show_status
|
||||
exit 0
|
||||
fi
|
||||
|
||||
|
||||
# ----------------------------- User Info -----------------------------
|
||||
# User Info
|
||||
echo "============================================================"
|
||||
echo " Sync Job Starting"
|
||||
echo "------------------------------------------------------------"
|
||||
@@ -53,7 +70,7 @@ log "Settings: MAX_RSYNC_PROCS=$MAX_RSYNC_PROCS, BW_LIMIT=$BW_LIMIT"
|
||||
log "Containers: ${CRITICAL_CONTAINER_NAMES[*]}"
|
||||
log "Excludes: ${EXCLUDE_DIRS[*]}"
|
||||
|
||||
# ----------------------------- Rsync Wait -----------------------------
|
||||
# Rsync Wait
|
||||
wait_for_rsync() {
|
||||
for attempt in $(seq 1 "$RETRY_COUNT"); do
|
||||
RSYNC_COUNT=$(pgrep -fc "rsync.*root@${REMOTE_SERVER}" || true)
|
||||
@@ -69,7 +86,7 @@ wait_for_rsync() {
|
||||
exit 1
|
||||
}
|
||||
|
||||
# ----------------------------- Main -----------------------------
|
||||
# Main
|
||||
main() {
|
||||
echo ""
|
||||
echo "🔍 Checking remote connectivity..."
|
||||
|
||||
Reference in New Issue
Block a user