Backup automatico script del 2026-09-04 07:00
This commit is contained in:
1 parent
795a15a7b6
commit
aab8502e27
10 files changed
+1001
-5
No files matched your search
@@ -20,6 +20,8 @@ PIHOLE_BIN="/usr/local/bin/pihole"
|
||||
REBOOT_DELAY_MIN=2
|
||||
WATCHTOWER_IMAGE="nickfedor/watchtower:latest"
|
||||
WATCHTOWER_TIMEOUT=900
|
||||
# Compose HA usati al pivot: Watchtower aggiorna solo i container esistenti.
|
||||
FAILOVER_COMPOSE_DIR="${FAILOVER_COMPOSE_DIR:-/home/daniely/rete/compose/failover}"
|
||||
|
||||
HOST_LABEL="$(hostname -s)"
|
||||
REBOOT_ON_SUCCESS=true
|
||||
@@ -218,6 +220,99 @@ run_watchtower() {
|
||||
fi
|
||||
}
|
||||
|
||||
# Espande ${VAR:-default} (usato nei compose Turni). Altri ${VAR} → scarta.
|
||||
expand_compose_image() {
|
||||
local raw="$1"
|
||||
while [[ "$raw" =~ \$\{([A-Za-z_][A-Za-z0-9_]*):-([^}]*)\} ]]; do
|
||||
raw="${raw/${BASH_REMATCH[0]}/${BASH_REMATCH[2]}}"
|
||||
done
|
||||
[[ "$raw" == *'$'* ]] && return 1
|
||||
printf '%s' "$raw"
|
||||
}
|
||||
|
||||
# Build locali / no registry: non fare docker pull (fallirebbe o scaricherebbe un omonimo Hub).
|
||||
failover_image_is_local_build() {
|
||||
local image="$1"
|
||||
local name="${image%%:*}"
|
||||
image_is_ignored "$image" && return 0
|
||||
case "$name" in
|
||||
nodus-backend|nodus-frontend|loogle-casa|loogle-mcp|irrigazione|ewelink_smart_home|turni-app)
|
||||
return 0
|
||||
;;
|
||||
esac
|
||||
return 1
|
||||
}
|
||||
|
||||
collect_failover_registry_images() {
|
||||
local dir="${FAILOVER_COMPOSE_DIR:-/home/daniely/rete/compose/failover}"
|
||||
local f line img expanded
|
||||
[[ -d "$dir" ]] || return 1
|
||||
while IFS= read -r f; do
|
||||
[[ -f "$f" ]] || continue
|
||||
while IFS= read -r line; do
|
||||
[[ -z "$line" ]] && continue
|
||||
img=$(expand_compose_image "$line") || continue
|
||||
failover_image_is_local_build "$img" && continue
|
||||
printf '%s\n' "$img"
|
||||
done < <(sed -n 's/^[[:space:]]*image:[[:space:]]*//p' "$f" | sed 's/["'\'']//g')
|
||||
done < <(find "$dir" -type f \( -name '*.yml' -o -name '*.yaml' \) | sort)
|
||||
}
|
||||
|
||||
pull_failover_standby_images() {
|
||||
command -v docker >/dev/null 2>&1 || return 0
|
||||
|
||||
local dir="${FAILOVER_COMPOSE_DIR:-/home/daniely/rete/compose/failover}"
|
||||
log "▶ Pull immagini failover (registry, anche senza container)"
|
||||
append_report ""
|
||||
append_report "=== Pull immagini failover (standby) ==="
|
||||
append_report "Compose: $dir"
|
||||
|
||||
if [[ ! -d "$dir" ]]; then
|
||||
WARNINGS+=("Directory compose failover assente: $dir")
|
||||
append_report "Directory assente"
|
||||
return 0
|
||||
fi
|
||||
|
||||
local -a images=()
|
||||
local img
|
||||
while IFS= read -r img; do
|
||||
[[ -z "$img" ]] && continue
|
||||
images+=("$img")
|
||||
done < <(collect_failover_registry_images | sort -u)
|
||||
|
||||
if ((${#images[@]} == 0)); then
|
||||
WARNINGS+=("Nessuna immagine registry nei compose failover")
|
||||
append_report "Lista vuota"
|
||||
return 0
|
||||
fi
|
||||
|
||||
local pulled=0 failed=0 skipped=0
|
||||
local before after
|
||||
for img in "${images[@]}"; do
|
||||
before=$(docker image inspect "$img" --format '{{.Id}}' 2>/dev/null || true)
|
||||
if docker pull "$img" >> "$REPORT_FILE" 2>&1; then
|
||||
after=$(docker image inspect "$img" --format '{{.Id}}' 2>/dev/null || true)
|
||||
if [[ -n "$before" && "$before" == "$after" ]]; then
|
||||
skipped=$((skipped + 1))
|
||||
log " = $img (già aggiornata)"
|
||||
append_report "unchanged: $img"
|
||||
else
|
||||
pulled=$((pulled + 1))
|
||||
log " ↑ $img"
|
||||
append_report "updated: $img"
|
||||
fi
|
||||
else
|
||||
failed=$((failed + 1))
|
||||
WARNINGS+=("docker pull fallito: $img")
|
||||
log " ✗ $img"
|
||||
fi
|
||||
done
|
||||
|
||||
NOTES+=("Failover images: ${#images[@]} registry, $pulled aggiornate, $skipped già ok, $failed errori")
|
||||
append_report "Riepilogo: ${#images[@]} immagini, aggiornate=$pulled, invariate=$skipped, errori=$failed"
|
||||
log "✓ Pull failover: aggiornate=$pulled invariate=$skipped errori=$failed"
|
||||
}
|
||||
|
||||
audit_apt() {
|
||||
local holds
|
||||
holds=$(apt-mark showhold 2>/dev/null || true)
|
||||
@@ -442,6 +537,8 @@ audit_eeprom
|
||||
|
||||
# 4. Aggiornamento container Docker (Watchtower run-once; il daemon è MONITOR_ONLY)
|
||||
run_watchtower
|
||||
# 4b. Immagini registry dei compose failover (Paperless, Vaultwarden, …) anche se non c'è container
|
||||
pull_failover_standby_images
|
||||
|
||||
# 5. Audit residui
|
||||
audit_docker
|
||||
|
||||
@@ -20,6 +20,8 @@ PIHOLE_BIN="/usr/local/bin/pihole"
|
||||
REBOOT_DELAY_MIN=2
|
||||
WATCHTOWER_IMAGE="nickfedor/watchtower:latest"
|
||||
WATCHTOWER_TIMEOUT=900
|
||||
# Compose HA usati al pivot: Watchtower aggiorna solo i container esistenti.
|
||||
FAILOVER_COMPOSE_DIR="${FAILOVER_COMPOSE_DIR:-/home/daniely/rete/compose/failover}"
|
||||
|
||||
HOST_LABEL="$(hostname -s)"
|
||||
REBOOT_ON_SUCCESS=true
|
||||
@@ -218,6 +220,99 @@ run_watchtower() {
|
||||
fi
|
||||
}
|
||||
|
||||
# Espande ${VAR:-default} (usato nei compose Turni). Altri ${VAR} → scarta.
|
||||
expand_compose_image() {
|
||||
local raw="$1"
|
||||
while [[ "$raw" =~ \$\{([A-Za-z_][A-Za-z0-9_]*):-([^}]*)\} ]]; do
|
||||
raw="${raw/${BASH_REMATCH[0]}/${BASH_REMATCH[2]}}"
|
||||
done
|
||||
[[ "$raw" == *'$'* ]] && return 1
|
||||
printf '%s' "$raw"
|
||||
}
|
||||
|
||||
# Build locali / no registry: non fare docker pull (fallirebbe o scaricherebbe un omonimo Hub).
|
||||
failover_image_is_local_build() {
|
||||
local image="$1"
|
||||
local name="${image%%:*}"
|
||||
image_is_ignored "$image" && return 0
|
||||
case "$name" in
|
||||
nodus-backend|nodus-frontend|loogle-casa|loogle-mcp|irrigazione|ewelink_smart_home|turni-app)
|
||||
return 0
|
||||
;;
|
||||
esac
|
||||
return 1
|
||||
}
|
||||
|
||||
collect_failover_registry_images() {
|
||||
local dir="${FAILOVER_COMPOSE_DIR:-/home/daniely/rete/compose/failover}"
|
||||
local f line img expanded
|
||||
[[ -d "$dir" ]] || return 1
|
||||
while IFS= read -r f; do
|
||||
[[ -f "$f" ]] || continue
|
||||
while IFS= read -r line; do
|
||||
[[ -z "$line" ]] && continue
|
||||
img=$(expand_compose_image "$line") || continue
|
||||
failover_image_is_local_build "$img" && continue
|
||||
printf '%s\n' "$img"
|
||||
done < <(sed -n 's/^[[:space:]]*image:[[:space:]]*//p' "$f" | sed 's/["'\'']//g')
|
||||
done < <(find "$dir" -type f \( -name '*.yml' -o -name '*.yaml' \) | sort)
|
||||
}
|
||||
|
||||
pull_failover_standby_images() {
|
||||
command -v docker >/dev/null 2>&1 || return 0
|
||||
|
||||
local dir="${FAILOVER_COMPOSE_DIR:-/home/daniely/rete/compose/failover}"
|
||||
log "▶ Pull immagini failover (registry, anche senza container)"
|
||||
append_report ""
|
||||
append_report "=== Pull immagini failover (standby) ==="
|
||||
append_report "Compose: $dir"
|
||||
|
||||
if [[ ! -d "$dir" ]]; then
|
||||
WARNINGS+=("Directory compose failover assente: $dir")
|
||||
append_report "Directory assente"
|
||||
return 0
|
||||
fi
|
||||
|
||||
local -a images=()
|
||||
local img
|
||||
while IFS= read -r img; do
|
||||
[[ -z "$img" ]] && continue
|
||||
images+=("$img")
|
||||
done < <(collect_failover_registry_images | sort -u)
|
||||
|
||||
if ((${#images[@]} == 0)); then
|
||||
WARNINGS+=("Nessuna immagine registry nei compose failover")
|
||||
append_report "Lista vuota"
|
||||
return 0
|
||||
fi
|
||||
|
||||
local pulled=0 failed=0 skipped=0
|
||||
local before after
|
||||
for img in "${images[@]}"; do
|
||||
before=$(docker image inspect "$img" --format '{{.Id}}' 2>/dev/null || true)
|
||||
if docker pull "$img" >> "$REPORT_FILE" 2>&1; then
|
||||
after=$(docker image inspect "$img" --format '{{.Id}}' 2>/dev/null || true)
|
||||
if [[ -n "$before" && "$before" == "$after" ]]; then
|
||||
skipped=$((skipped + 1))
|
||||
log " = $img (già aggiornata)"
|
||||
append_report "unchanged: $img"
|
||||
else
|
||||
pulled=$((pulled + 1))
|
||||
log " ↑ $img"
|
||||
append_report "updated: $img"
|
||||
fi
|
||||
else
|
||||
failed=$((failed + 1))
|
||||
WARNINGS+=("docker pull fallito: $img")
|
||||
log " ✗ $img"
|
||||
fi
|
||||
done
|
||||
|
||||
NOTES+=("Failover images: ${#images[@]} registry, $pulled aggiornate, $skipped già ok, $failed errori")
|
||||
append_report "Riepilogo: ${#images[@]} immagini, aggiornate=$pulled, invariate=$skipped, errori=$failed"
|
||||
log "✓ Pull failover: aggiornate=$pulled invariate=$skipped errori=$failed"
|
||||
}
|
||||
|
||||
audit_apt() {
|
||||
local holds
|
||||
holds=$(apt-mark showhold 2>/dev/null || true)
|
||||
@@ -442,6 +537,8 @@ audit_eeprom
|
||||
|
||||
# 4. Aggiornamento container Docker (Watchtower run-once, sostituisce il daemon schedulato)
|
||||
run_watchtower
|
||||
# 4b. Immagini registry dei compose failover (Paperless, Vaultwarden, …) anche se non c'è container
|
||||
pull_failover_standby_images
|
||||
|
||||
# 5. Audit residui
|
||||
audit_docker
|
||||
|
||||
Reference in new issue
Block a user