Add host-ready restore automation scripts
This commit is contained in:
@@ -0,0 +1,81 @@
|
||||
#!/bin/bash
|
||||
set -euo pipefail
|
||||
|
||||
DUMP_ROOT="${DUMP_ROOT:-/mnt/user/backups/borg/dumps/latest}"
|
||||
REPORT_ROOT="${REPORT_ROOT:-/mnt/user/backups/restore-reports}"
|
||||
MAX_DUMP_AGE_HOURS="${MAX_DUMP_AGE_HOURS:-36}"
|
||||
MAX_REPORT_AGE_DAYS="${MAX_REPORT_AGE_DAYS:-45}"
|
||||
|
||||
now_epoch="$(date +%s)"
|
||||
critical=()
|
||||
warnings=()
|
||||
info=()
|
||||
|
||||
check_file_age_hours() {
|
||||
local path="$1"
|
||||
local mtime
|
||||
mtime="$(stat -c %Y "$path")"
|
||||
echo $(( (now_epoch - mtime) / 3600 ))
|
||||
}
|
||||
|
||||
check_file_age_days() {
|
||||
local path="$1"
|
||||
local mtime
|
||||
mtime="$(stat -c %Y "$path")"
|
||||
echo $(( (now_epoch - mtime) / 86400 ))
|
||||
}
|
||||
|
||||
for dump in postgresql17-paperless.dump postgresql17-mailarchiver.dump mealie.dump immich.dump; do
|
||||
path="$DUMP_ROOT/$dump"
|
||||
if [ ! -f "$path" ]; then
|
||||
critical+=("DUMP_MISSING $dump")
|
||||
continue
|
||||
fi
|
||||
age="$(check_file_age_hours "$path")"
|
||||
if [ "$age" -gt "$MAX_DUMP_AGE_HOURS" ]; then
|
||||
warnings+=("DUMP_STALE $dump age=${age}h")
|
||||
else
|
||||
info+=("DUMP_OK $dump age=${age}h")
|
||||
fi
|
||||
done
|
||||
|
||||
for service in vaultwarden gitea paperless; do
|
||||
latest="$(find "$REPORT_ROOT" -maxdepth 1 -type f -name "$service-*.md" | sort | tail -n 1 || true)"
|
||||
if [ -z "$latest" ]; then
|
||||
warnings+=("REPORT_MISSING $service")
|
||||
continue
|
||||
fi
|
||||
age="$(check_file_age_days "$latest")"
|
||||
if [ "$age" -gt "$MAX_REPORT_AGE_DAYS" ]; then
|
||||
warnings+=("REPORT_STALE $service age=${age}d file=$(basename "$latest")")
|
||||
else
|
||||
info+=("REPORT_OK $service age=${age}d file=$(basename "$latest")")
|
||||
fi
|
||||
done
|
||||
|
||||
echo "# Restore Freshness Check"
|
||||
echo
|
||||
echo "Timestamp: $(date '+%F %T')"
|
||||
echo "Critical: ${#critical[@]}"
|
||||
echo "Warnings: ${#warnings[@]}"
|
||||
echo "Info: ${#info[@]}"
|
||||
echo
|
||||
|
||||
if [ "${#critical[@]}" -gt 0 ]; then
|
||||
echo "## Critical"
|
||||
printf -- '- %s\n' "${critical[@]}"
|
||||
echo
|
||||
fi
|
||||
|
||||
if [ "${#warnings[@]}" -gt 0 ]; then
|
||||
echo "## Warnings"
|
||||
printf -- '- %s\n' "${warnings[@]}"
|
||||
echo
|
||||
fi
|
||||
|
||||
if [ "${#info[@]}" -gt 0 ]; then
|
||||
echo "## Info"
|
||||
printf -- '- %s\n' "${info[@]}"
|
||||
fi
|
||||
|
||||
[ "${#critical[@]}" -eq 0 ]
|
||||
Reference in New Issue
Block a user