Add monthly offsite restore tests and automatic cleanup

This commit is contained in:
admin committed 2026-09-12 19:47:32 +02:00
1 parent 64eab1d3c2
commit f0c761213d
18 files changed
+1386 -16

No files matched your search

+16 -4
View File
@@ -127,7 +127,7 @@ if [[ $UP_WORKER == false ]]; then
UP_HAD_GITEA=${ENABLE_GITEA+x}
UP_ORIGINAL_RCLONE=${RCLONE_CONFIG:-}
load_config
acquire_backup_lock
acquire_backup_lock 1
# Preserve original text and append effective safety settings. Repeated upgrades
# may append another small block; the last explicit values remain authoritative.
cp -- "$CONFIG_FILE" "$UP_STATE/candidate.conf"
@@ -242,6 +242,11 @@ if [[ $UP_WORKER == false ]]; then
APP_BACKUP_INHERIT_LOCK=1 bash "$UPDATE_ROOT/usr-local-sbin/app-backup.sh" --config "$UP_STATE/check.conf" --check > "$UP_STATE/preflight.log" 2>&1 || {
tail -n 40 "$UP_STATE/preflight.log"; die "Preflight failed; installed package/config/timer unchanged. Details: $UP_STATE";
}
if [[ $ENABLE_RESTORE_TEST == true ]]; then
APP_BACKUP_INHERIT_LOCK=1 bash "$UPDATE_ROOT/usr-local-sbin/app-restore-test.sh" --config "$UP_STATE/check.conf" --check >> "$UP_STATE/preflight.log" 2>&1 || {
tail -n 20 "$UP_STATE/preflight.log"; die 'Restore-test prerequisites failed; prepare local DB image and disk budget first';
}
fi
sha256sum "$UP_STATE/candidate.conf" | cut -d ' ' -f 1 > "$UP_STATE/candidate.sha256"
echo "Vorpruefung erfolgreich. Writer: $(tr '\n' ' ' < "$UP_STATE/writers")"
echo 'Jetzt folgen Installation, ein vollstaendiges Backup und Remote-Restore-Pruefung.'
@@ -294,7 +299,7 @@ worker_finish() {
if [[ $UP_OK == true && $code == 0 ]]; then
printf 'SUCCESS\nPaket aktualisiert, Backup und Remote-Restore-Pruefung erfolgreich.\nBackup-Timer aktiv.\n' > "$UP_STATE/result.txt"
else
if [[ $UP_CHANGED == true ]]; then systemctl stop app-backup.timer; fi
if [[ $UP_CHANGED == true ]]; then systemctl stop app-backup.timer app-restore-test.timer; fi
printf 'FAILED (exit %s)\nDetails: %s/update.log\n' "$code" "$UP_STATE" > "$UP_STATE/result.txt"
if [[ -f $UP_STATE/rollback-update.sh ]]; then
printf 'Rollback: sudo bash %s/rollback-update.sh\n' "$UP_STATE" >> "$UP_STATE/result.txt"
@@ -311,11 +316,12 @@ trap 'exit 143' TERM
flock -w 60 8 || die 'Timed out waiting for update coordinator lock (60s); installation not started'
[[ $(cat "$UP_STATE/result.txt") == QUEUED ]] || die 'Upgrade is not queued or submission was cancelled; rerun updater'
printf 'RUNNING\n' > "$UP_STATE/result.txt"
acquire_backup_lock
acquire_backup_lock 1
export APP_BACKUP_INHERIT_LOCK=1
[[ $(sha256sum "$CONFIG_FILE" | cut -d ' ' -f 1) == "$(cat "$UP_STATE/original.sha256")" ]] || die 'Configuration changed after preparation; rerun updater'
[[ $(sha256sum "$UP_STATE/candidate.conf" | cut -d ' ' -f 1) == "$(cat "$UP_STATE/candidate.sha256")" ]] || die 'Prepared configuration changed unexpectedly'
systemctl stop app-backup.timer
if systemctl is-active --quiet app-restore-test.timer; then systemctl stop app-restore-test.timer; fi
UP_CHANGED=true
# The ordinary installer records all replaced package files. Its timer remains
# disabled here until this coordinator has verified the complete new backup.
@@ -334,7 +340,7 @@ flock -n 8 || { echo 'Update still active'; exit 1; }
systemctl stop app-backup.timer
LOCKFILE=$lock
source "$here/locking.sh"
acquire_backup_lock
acquire_backup_lock 1
export APP_BACKUP_INHERIT_LOCK=1
if [[ -f $here/package-rollback/rollback.sh ]]; then
bash "$here/package-rollback/rollback.sh"
@@ -376,4 +382,10 @@ printf '%s\n' "$backup_run" > "$UP_STATE/verified-backup-run"
unset APP_BACKUP_INHERIT_LOCK
flock -u 9
systemctl enable --now app-backup.timer
if [[ $ENABLE_RESTORE_TEST == true ]]; then
systemctl enable app-restore-test-cleanup.service
systemctl enable --now app-restore-test.timer
else
systemctl disable --now app-restore-test.timer || true
fi
UP_OK=true