Add persistent partner conf backup across reboots
conf_cache_save.sh runs first on array stop — snapshots partner confs from RAM cache to /boot/config/varaverk/conf_bak/ before anything else shuts down. conf_cache_restore.sh runs after conf_sync.sh on array start — if partner was unreachable and RAM cache is incomplete, loads the backup into RAM then removes it. Normal reboots: backup written, fresh pull succeeds, backup deleted unused. Edge case (partner down at boot): backup fills the gap so fallback.sh has the partner vars it needs to operate correctly.
This commit is contained in:
Executable
+62
@@ -0,0 +1,62 @@
|
||||
#!/bin/bash
|
||||
# ==============================================================================================
|
||||
# ============================= Conf Cache Save ================================================
|
||||
# ==============================================================================================
|
||||
#
|
||||
# PURPOSE
|
||||
# ─────────────────────────────────────────────────────────────────────────────
|
||||
# Snapshots the partner conf RAM cache to /boot/config/varaverk/conf_bak/ on
|
||||
# array stop. Survives reboot. Used by conf_cache_restore.sh at next array start
|
||||
# to reload partner vars into RAM when the partner is unreachable at boot time.
|
||||
#
|
||||
# Runs as the first step in ARRAY_STOP_SCRIPTS — while the RAM cache is fresh
|
||||
# and before anything else changes. If partner is reachable at next start,
|
||||
# conf_sync.sh gets a fresh copy and the backup is never used. If partner is
|
||||
# down, the backup fills the gap so fallback.sh has the vars it needs.
|
||||
#
|
||||
# Only partner confs are saved — own conf is always on disk.
|
||||
# Location is outside the git repo and outside the main plugin folder.
|
||||
# ==============================================================================================
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
source "$SCRIPT_DIR/../load_config.sh"
|
||||
|
||||
parse_args "$@"
|
||||
detect_hosts
|
||||
|
||||
RAM_CACHE="/tmp/.vv/config/cached/.confs"
|
||||
SAVE_DIR="/boot/config/varaverk/conf_bak"
|
||||
|
||||
[[ "$DRY_RUN" == true ]] && warn "DRY RUN — no files will be written"
|
||||
|
||||
if [[ ! -d "$RAM_CACHE" ]]; then
|
||||
log "No RAM conf cache found — nothing to save"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
saved=0
|
||||
for conf in "$RAM_CACHE"/host*.conf; do
|
||||
[[ -f "$conf" ]] || continue
|
||||
base="$(basename "$conf")"
|
||||
[[ "${base,,}" == "${MY_ID,,}.conf" ]] && continue
|
||||
|
||||
if [[ "$DRY_RUN" == true ]]; then
|
||||
warn "DRY RUN — would save $base → $SAVE_DIR/"
|
||||
(( saved++ ))
|
||||
continue
|
||||
fi
|
||||
|
||||
mkdir -p "$SAVE_DIR"
|
||||
if cp "$conf" "$SAVE_DIR/$base"; then
|
||||
echo "Saved $base → $SAVE_DIR ✅"
|
||||
(( saved++ ))
|
||||
else
|
||||
warn "Failed to save $base"
|
||||
fi
|
||||
done
|
||||
|
||||
if [[ "$saved" -eq 0 ]]; then
|
||||
log "No partner confs in RAM cache — nothing saved"
|
||||
else
|
||||
echo "Conf cache saved: $saved partner conf(s) → $SAVE_DIR"
|
||||
fi
|
||||
Reference in New Issue
Block a user