moved some things to common.sh
This commit is contained in:
+1
-1
@@ -18,7 +18,7 @@
|
|||||||
# ------------------ Git, Pull & Execute Script -----------------
|
# ------------------ Git, Pull & Execute Script -----------------
|
||||||
REPO_SSH="git@192.168.50.2:FailedProxy/Unraid_Scripts.git"
|
REPO_SSH="git@192.168.50.2:FailedProxy/Unraid_Scripts.git"
|
||||||
TARGET_DIR="/mnt/user/appdata/unraid_scripts"
|
TARGET_DIR="/mnt/user/appdata/unraid_scripts"
|
||||||
SSH_KEY="/root/.ssh/id_gitea_rsync"
|
GITEA_SSH_KEY="/root/.ssh/id_gitea_rsync"
|
||||||
SSH_PORT=221
|
SSH_PORT=221
|
||||||
|
|
||||||
# -------------------Rsync Script Defaults-----------------------
|
# -------------------Rsync Script Defaults-----------------------
|
||||||
|
|||||||
@@ -14,16 +14,6 @@ source "$SCRIPT_DIR/../common.sh"
|
|||||||
|
|
||||||
RSYNC_SCRIPT="$SCRIPT_DIR/../Rsync/rsync.sh"
|
RSYNC_SCRIPT="$SCRIPT_DIR/../Rsync/rsync.sh"
|
||||||
|
|
||||||
# -----------------------------------------------------------------------------------------------
|
|
||||||
# Duration Formatter
|
|
||||||
# -----------------------------------------------------------------------------------------------
|
|
||||||
format_duration() {
|
|
||||||
local secs=$1
|
|
||||||
local mins=$((secs / 60))
|
|
||||||
local rem=$((secs % 60))
|
|
||||||
[[ $mins -gt 0 ]] && echo "${mins}m${rem}s" || echo "${rem}s"
|
|
||||||
}
|
|
||||||
|
|
||||||
# -----------------------------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------------------------
|
||||||
# Tracking
|
# Tracking
|
||||||
# -----------------------------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------------------------
|
||||||
|
|||||||
+4
-1
@@ -29,6 +29,7 @@ parse_args "${RAW_ARGS[@]}"
|
|||||||
|
|
||||||
detect_hosts
|
detect_hosts
|
||||||
resolve_remote_ip
|
resolve_remote_ip
|
||||||
|
check_connectivity
|
||||||
|
|
||||||
# -----------------------------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------------------------
|
||||||
# Profile resolution — inferred from the directory basename
|
# Profile resolution — inferred from the directory basename
|
||||||
@@ -74,6 +75,8 @@ START=$(date +%s)
|
|||||||
RSYNC_SUCCESS=false
|
RSYNC_SUCCESS=false
|
||||||
|
|
||||||
for i in $(seq 1 "$RETRY_COUNT"); do
|
for i in $(seq 1 "$RETRY_COUNT"); do
|
||||||
|
# dirname "$DIRECTORY" is intentional — rsync recreates the final directory on the remote
|
||||||
|
# e.g. source /mnt/user/Movies → remote receives /mnt/user/Movies (not /mnt/user/Movies/Movies)
|
||||||
if rsync "${RSYNC_OPTS[@]}" \
|
if rsync "${RSYNC_OPTS[@]}" \
|
||||||
-e "ssh -i $SSH_KEY -T -o Compression=no -o IPQoS=throughput" \
|
-e "ssh -i $SSH_KEY -T -o Compression=no -o IPQoS=throughput" \
|
||||||
"$DIRECTORY" "root@${REMOTE_SERVER}:$(dirname "$DIRECTORY")/"; then
|
"$DIRECTORY" "root@${REMOTE_SERVER}:$(dirname "$DIRECTORY")/"; then
|
||||||
@@ -94,7 +97,7 @@ echo ""
|
|||||||
echo "===== SUMMARY ====="
|
echo "===== SUMMARY ====="
|
||||||
echo "Directory: $DIRECTORY"
|
echo "Directory: $DIRECTORY"
|
||||||
echo "Profile: $PROFILE_NAME"
|
echo "Profile: $PROFILE_NAME"
|
||||||
echo "Duration: $((END - START))s"
|
echo "Duration: $(format_duration $((END - START)))"
|
||||||
if [[ "$RSYNC_SUCCESS" == true ]]; then
|
if [[ "$RSYNC_SUCCESS" == true ]]; then
|
||||||
echo "Status: $ICON_SUCCESS DONE"
|
echo "Status: $ICON_SUCCESS DONE"
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -2,6 +2,11 @@
|
|||||||
# -----------------------------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------------------------
|
||||||
# ----------------- UNRAID OPS COMMON LIBRARY (STABLE FRAMEWORK v1) ----------------------------
|
# ----------------- UNRAID OPS COMMON LIBRARY (STABLE FRAMEWORK v1) ----------------------------
|
||||||
# -----------------------------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------------------------
|
||||||
|
# Version: 1.1
|
||||||
|
# Changed: format_duration moved here from daily_sync.sh for shared use
|
||||||
|
# SSH_KEY collision documented — gitea key renamed GITEA_SSH_KEY in Master.conf
|
||||||
|
# Version and changelog tracking added
|
||||||
|
# -----------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
# ICONS
|
# ICONS
|
||||||
ICON_INFO="ℹ️"
|
ICON_INFO="ℹ️"
|
||||||
@@ -24,6 +29,18 @@ log() {
|
|||||||
[[ "${ENABLE_LOGGING:-false}" == true ]] && echo "[LOG] $*"
|
[[ "${ENABLE_LOGGING:-false}" == true ]] && echo "[LOG] $*"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# -----------------------------------------------------------------------------------------------
|
||||||
|
# DURATION FORMATTER
|
||||||
|
# Converts raw seconds to human readable format — e.g. 10m53s or 47s
|
||||||
|
# Used by rsync.sh and daily_sync.sh
|
||||||
|
# -----------------------------------------------------------------------------------------------
|
||||||
|
format_duration() {
|
||||||
|
local secs=$1
|
||||||
|
local mins=$((secs / 60))
|
||||||
|
local rem=$((secs % 60))
|
||||||
|
[[ $mins -gt 0 ]] && echo "${mins}m${rem}s" || echo "${rem}s"
|
||||||
|
}
|
||||||
|
|
||||||
# -----------------------------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------------------------
|
||||||
# ARG PARSER
|
# ARG PARSER
|
||||||
# -----------------------------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------------------------
|
||||||
@@ -118,6 +135,20 @@ resolve_remote_ip() {
|
|||||||
info "Remote IP: $REMOTE_SERVER"
|
info "Remote IP: $REMOTE_SERVER"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# -----------------------------------------------------------------------------------------------
|
||||||
|
# CONNECTIVITY CHECK
|
||||||
|
# Verifies remote is reachable before attempting rsync.
|
||||||
|
# Prevents retry loop burning all attempts against an unreachable host.
|
||||||
|
# -----------------------------------------------------------------------------------------------
|
||||||
|
check_connectivity() {
|
||||||
|
log "Checking connectivity to $REMOTE_SERVER..."
|
||||||
|
if ! ping -c1 -W3 "$REMOTE_SERVER" &>/dev/null; then
|
||||||
|
error "Remote $REMOTE_SERVER is unreachable — aborting"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
log "Remote is reachable"
|
||||||
|
}
|
||||||
|
|
||||||
# -----------------------------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------------------------
|
||||||
# CONTAINERS
|
# CONTAINERS
|
||||||
# CRITICAL_CONTAINER_NAMES and DELAYED_CONTAINERS must be bash arrays before calling these.
|
# CRITICAL_CONTAINER_NAMES and DELAYED_CONTAINERS must be bash arrays before calling these.
|
||||||
|
|||||||
Reference in New Issue
Block a user