fix(backup): run forgejo dump in-pod to avoid exec websocket EOF
All checks were successful
CI Smoke / host-smoke (push) Successful in 0s
CI Smoke / container-smoke (push) Successful in 18s

Long forgejo dump sessions were aborting kubectl exec with websocket
close 1006. Launch dump via nohup inside the pod and poll for the zip.
This commit is contained in:
tegwick 2026-07-12 01:09:49 +02:00
parent de8f11e721
commit e644ce150f

View file

@ -74,8 +74,30 @@ ok "forgejo-db" "${FORGEJO_DB_NAMESPACE}/${FORGEJO_DB_POD}"
# 1. Application dump (repos, packages, attachments, LFS, avatars)
ok "forgejo dump" "running in pod…"
DUMP_REMOTE="/tmp/forgejo-backup-${TS}.zip"
# Long dumps drop the kubectl exec websocket if attached to the process; run in-pod
# background and poll for the archive file instead.
kubectl exec --request-timeout=0 -n "${FORGEJO_NAMESPACE}" "${PROD_POD}" -c gitea -- \
forgejo dump -f "${DUMP_REMOTE}"
sh -eu -c "rm -f '${DUMP_REMOTE}'; nohup forgejo dump -f '${DUMP_REMOTE}' >/tmp/forgejo-dump.log 2>&1 &"
dump_wait=0
while [[ "${dump_wait}" -lt 1800 ]]; do
if kubectl exec --request-timeout=30 -n "${FORGEJO_NAMESPACE}" "${PROD_POD}" -c gitea -- \
test -s "${DUMP_REMOTE}" 2>/dev/null; then
if kubectl exec --request-timeout=30 -n "${FORGEJO_NAMESPACE}" "${PROD_POD}" -c gitea -- \
sh -c "pgrep -f 'forgejo dump' >/dev/null"; then
sleep 10
dump_wait=$((dump_wait + 10))
continue
fi
break
fi
sleep 10
dump_wait=$((dump_wait + 10))
done
if ! kubectl exec --request-timeout=30 -n "${FORGEJO_NAMESPACE}" "${PROD_POD}" -c gitea -- \
test -s "${DUMP_REMOTE}" 2>/dev/null; then
bad "forgejo dump" "timed out or empty archive (see /tmp/forgejo-dump.log in pod)"
exit 1
fi
# Large dumps (~700M) fail via stdout stream or single kubectl cp — use chunks.
dump_size="$(kubectl exec -n "${FORGEJO_NAMESPACE}" "${PROD_POD}" -c gitea -- \
stat -c%s "${DUMP_REMOTE}" 2>/dev/null || echo 0)"