From 4e7ab667ed02b5658269373d7251d14305b23400 Mon Sep 17 00:00:00 2001 From: Kit OC5 Date: Thu, 1 Oct 2026 03:23:41 -0400 Subject: [PATCH] backup_state: pin restic cache dir (systemd has no HOME); init only on a MISSING repo, log other errors Co-Authored-By: Claude Sonnet 5.5 --- scripts/backup_state.sh | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/scripts/backup_state.sh b/scripts/backup_state.sh index 272cf4b..1bf94de 100755 --- a/scripts/backup_state.sh +++ b/scripts/backup_state.sh @@ -22,7 +22,16 @@ GIT_ROOT="${GIT_DATA_ROOT:-/srv/windygit/git}" umask 077 mkdir -p "$STAGE"; chmod 700 "$STAGE"; rm -f "$STAGE"/*.dump "$STAGE"/globals.sql -restic cat config >/dev/null 2>&1 || { log "initialising restic repo"; restic init >/dev/null; } +# systemd gives units no $HOME, and restic wants a cache dir: pin one. +export RESTIC_CACHE_DIR="${RESTIC_CACHE_DIR:-/var/cache/windygit-restic}"; mkdir -p "$RESTIC_CACHE_DIR" +if ! err=$(restic cat config 2>&1 >/dev/null); then + # only a MISSING repo may be initialised; any other error (auth, network, wrong password) must stop here + if grep -qiE "does not exist|is there a repository|unable to open config file" <<<"$err"; then + log "initialising restic repo"; restic init >/dev/null + else + log "FATAL: restic cannot open the repository: $(head -c 300 <<<"$err" | tr '\n' ' ')"; exit 1 + fi +fi PGU=$(timeout 30 docker exec "$DB" printenv POSTGRES_USER) [[ -n "$PGU" ]] || { log "FATAL: no POSTGRES_USER in $DB"; exit 1; }