feat: isolate OCI restore drills and retire stale offsite target

This commit is contained in:
juvenal.diaz 2026-10-28 09:27:17 -06:00
parent 73091460ae
commit 920374c3e3
2 changed files with 18 additions and 7 deletions

View File

@ -4573,10 +4573,14 @@ install_homelab_backup_timer() {
local offsite_uri="${HOMELAB_BACKUP_OFFSITE_URI:-}"
local tmp_env
if [[ -z "${offsite_uri}" && -e "${env_file}" ]]; then
if [[ "${HOMELAB_BACKUP_SKIP_OFFSITE:-false}" != "true" && -z "${offsite_uri}" && -e "${env_file}" ]]; then
offsite_uri="$(sudo awk -F= '$1 == "HOMELAB_BACKUP_OFFSITE_URI" { print substr($0, index($0, "=") + 1); exit }' "${env_file}" 2>/dev/null || true)"
fi
if [[ "${HOMELAB_BACKUP_SKIP_OFFSITE:-false}" == "true" ]]; then
offsite_uri=""
fi
tmp_env="$(mktemp)"
{
cat <<ENV_EOT
@ -4593,7 +4597,7 @@ ENV_EOT
sudo install -m 0640 -o root -g root "${tmp_env}" "${env_file}"
rm -f "${tmp_env}"
if [[ -n "${offsite_uri}" ]]; then
if [[ -n "${offsite_uri}" && "${HOMELAB_BACKUP_SKIP_OFFSITE:-false}" != "true" ]]; then
export HOMELAB_BACKUP_OFFSITE_URI="${offsite_uri}"
fi

View File

@ -80,7 +80,10 @@ case "${ACTION}" in
# Run the complete local backup workflow first so the OCI archive
# includes fresh Gitea and OpenTofu state artifacts, not just the
# Pimox inventory.
"${REPO_ROOT}/jeannie" backup
# OCI Object Storage is the active offsite destination. Do not let a
# retired SSH target from the Debian backup timer add latency or
# misleading warnings to this upload workflow.
HOMELAB_BACKUP_SKIP_OFFSITE=true "${REPO_ROOT}/jeannie" backup
archive="$(latest_archive)"
[[ -n "${archive}" ]] || { echo "No encrypted archive was created." >&2; exit 1; }
upload_archive "${archive}"
@ -100,15 +103,19 @@ case "${ACTION}" in
--region "${OCI_REGION}" --namespace-name "${NAMESPACE}" --bucket-name "${BUCKET}" \
--name "${object}.sha256" --file "${tmpdir}/archive.sha256" >/dev/null
(cd "${tmpdir}" && sha256sum -c archive.sha256)
listing="$(age -d -i "${AGE_KEY_FILE}" "${tmpdir}/archive.tgz.age" | tar -tzf -)"
grep -q 'gitea/latest-gitea-backup.zip' <<<"${listing}" || {
restore_dir="${tmpdir}/restored"
mkdir -p "${restore_dir}"
age -d -i "${AGE_KEY_FILE}" "${tmpdir}/archive.tgz.age" |
tar -xzf - -C "${restore_dir}" --no-same-owner --no-same-permissions
[[ -s "${restore_dir}/gitea/latest-gitea-backup.zip" ]] || {
echo 'restore verification failed: Gitea backup is missing from archive.' >&2
exit 1
}
grep -q '^tofu-state/' <<<"${listing}" || {
find "${restore_dir}/tofu-state" -type f -print -quit 2>/dev/null | grep -q . || {
echo 'restore verification failed: OpenTofu state is missing from archive.' >&2
exit 1
}
printf 'restore_verification=ok\nobject=%s\n' "${object}"
tar -tzf <(age -d -i "${AGE_KEY_FILE}" "${tmpdir}/archive.tgz.age") >/dev/null
printf 'restore_verification=ok\nobject=%s\nrestored_artifacts=gitea,tofu-state\n' "${object}"
;;
esac