fix: report OCI restore verification phases

This commit is contained in:
juvenal.diaz 2026-10-28 09:39:18 -06:00
parent 920374c3e3
commit 036bc75169
1 changed files with 21 additions and 9 deletions

View File

@ -89,11 +89,16 @@ case "${ACTION}" in
upload_archive "${archive}"
;;
restore-verify)
printf 'restore_verification=starting\n'
object="$(${oci_bin} os object list --config-file "${OCI_CONFIG}" --profile "${OCI_PROFILE}" \
--region "${OCI_REGION}" --namespace-name "${NAMESPACE}" --bucket-name "${BUCKET}" \
--prefix "${PREFIX%/}/homelab-pimox-profile-" --all \
--query 'data[].name' --raw-output | grep '\.tgz\.age$' | sort | tail -1)"
[[ -n "${object}" && "${object}" != "null" ]] || { echo "No encrypted OCI backup archive found." >&2; exit 1; }
if [[ -z "${object}" || "${object}" == "null" ]]; then
echo "restore_verification=failed reason=no-encrypted-archive" >&2
exit 1
fi
printf 'restore_object=%s\n' "${object}"
tmpdir="$(mktemp -d)"
trap 'rm -rf "${tmpdir}"' EXIT
"${oci_bin}" os object get --config-file "${OCI_CONFIG}" --profile "${OCI_PROFILE}" \
@ -102,20 +107,27 @@ case "${ACTION}" in
"${oci_bin}" os object get --config-file "${OCI_CONFIG}" --profile "${OCI_PROFILE}" \
--region "${OCI_REGION}" --namespace-name "${NAMESPACE}" --bucket-name "${BUCKET}" \
--name "${object}.sha256" --file "${tmpdir}/archive.sha256" >/dev/null
(cd "${tmpdir}" && sha256sum -c archive.sha256)
if ! (cd "${tmpdir}" && sha256sum -c archive.sha256); then
echo 'restore_verification=failed reason=checksum-mismatch' >&2
exit 1
fi
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" ]] || {
if ! age -d -i "${AGE_KEY_FILE}" "${tmpdir}/archive.tgz.age" |
tar -xzf - -C "${restore_dir}" --no-same-owner --no-same-permissions; then
echo 'restore_verification=failed reason=decrypt-or-extract' >&2
exit 1
fi
if [[ ! -s "${restore_dir}/gitea/latest-gitea-backup.zip" ]]; then
echo 'restore verification failed: Gitea backup is missing from archive.' >&2
echo 'restore_verification=failed reason=missing-gitea-backup' >&2
exit 1
}
find "${restore_dir}/tofu-state" -type f -print -quit 2>/dev/null | grep -q . || {
fi
if ! find "${restore_dir}/tofu-state" -type f -print -quit 2>/dev/null | grep -q .; then
echo 'restore verification failed: OpenTofu state is missing from archive.' >&2
echo 'restore_verification=failed reason=missing-tofu-state' >&2
exit 1
}
tar -tzf <(age -d -i "${AGE_KEY_FILE}" "${tmpdir}/archive.tgz.age") >/dev/null
fi
printf 'restore_verification=ok\nobject=%s\nrestored_artifacts=gitea,tofu-state\n' "${object}"
;;
esac