#!/usr/bin/env bash # Back up Gitea (repositories, packages, attachments, Actions data, app.ini) to # AIStor (HDD sdb3). Root only. Run by platform-gitea-backup.timer. # # `gitea dump --skip-db` runs inside the live Gitea container and streams a # tar.gz to stdout (logs go to stderr). The database is backed up separately by # CloudNativePG (services/platform-postgres-backup). The dump contains app.ini, # whose secrets are needed to restore, so the archive is sensitive. set -Eeuo pipefail umask 077 # shellcheck source=../lib/host-backup.sh source "$(dirname -- "${BASH_SOURCE[0]}")/../lib/host-backup.sh" readonly NAME=gitea_backup readonly KCFG=/etc/rancher/k3s/k3s.yaml [[ "$(id -u)" -eq 0 ]] || hb_fail "run as root" hb_load_aistor_env kubectl() { command /usr/local/bin/k3s kubectl --kubeconfig "$KCFG" "$@"; } started="$(date +%s)" previous_success="$(awk '/^platform_backup_last_success_timestamp_seconds/ {print $2}' "$TEXTFILE_DIR/$NAME.prom" 2>/dev/null || echo 0)" on_error() { hb_write_metrics "$NAME" <"$work/$archive" 2>"$work/dump.log" tar -tzf "$work/$archive" >"$work/list.txt" grep -qx 'app.ini' "$work/list.txt" || hb_fail "the dump has no app.ini" repos="$(grep -c -E '^repos/[^/]+/[^/]+\.git/HEAD$' "$work/list.txt" || true)" (( repos > 0 )) || hb_fail "the dump has no repositories" sha256sum "$work/$archive" | awk '{print $1}' >"$work/$archive.sha256" size="$(stat -c %s "$work/$archive")" hb_mc "$work" cp --quiet "/work/$archive" "/work/$archive.sha256" "backup/$AISTOR_BUCKET/gitea/" >/dev/null hb_mc "$work" stat "backup/$AISTOR_BUCKET/gitea/$archive" >/dev/null trap - ERR hb_write_metrics "$NAME" <