feat(backup): keep k3s datastore archives outside AIStor on the HDD
AIStor runs inside the k3s cluster that the datastore archive restores. After losing the whole cluster the AIStor copy cannot be read until k3s is running again, which is what the archive is for. Also keep the seven newest archives in /srv/k3s/aistor/host-backups/k3s-datastore (root 0700) on the same HDD filesystem (sdb3). The directory is next to AIStor's drive directory data/, so AIStor does not list it as a bucket, and it is readable by mounting sdb3 alone. A metric reports how many local copies exist. Rejected: the NTFS archive partition (sdb2). It has no Unix permissions and Windows on the same machine can read it; the archive holds the server token. Risk: the files live inside the AIStor PersistentVolume root, which is mounted into the MinIO pod (uid 1000); mode 0700 root keeps the pod from reading them. Verification: bash -n; /srv/k3s/aistor contains only data/ (2026-11-12).
This commit is contained in:
@@ -57,6 +57,16 @@ size="$(stat -c %s "$work/k3s-datastore-$ts.tar.gz")"
|
||||
hb_mc "$work" cp --quiet "/work/k3s-datastore-$ts.tar.gz" "/work/k3s-datastore-$ts.tar.gz.sha256" "backup/$AISTOR_BUCKET/k3s-datastore/" >/dev/null
|
||||
hb_mc "$work" stat "backup/$AISTOR_BUCKET/k3s-datastore/k3s-datastore-$ts.tar.gz" >/dev/null
|
||||
|
||||
# Local copy outside AIStor on the same HDD (sdb3). AIStor runs inside the
|
||||
# cluster this archive restores, so after losing the cluster the AIStor copy
|
||||
# cannot be read until k3s is back; this copy can. The directory sits next to
|
||||
# AIStor's drive directory (data/), so AIStor does not see it as a bucket.
|
||||
readonly LOCAL_DIR=/srv/k3s/aistor/host-backups/k3s-datastore
|
||||
install -d -m 0700 -o root -g root "$(dirname "$LOCAL_DIR")" "$LOCAL_DIR"
|
||||
install -m 0600 "$work/k3s-datastore-$ts.tar.gz" "$work/k3s-datastore-$ts.tar.gz.sha256" "$LOCAL_DIR/"
|
||||
ls -1t "$LOCAL_DIR"/k3s-datastore-*.tar.gz | tail -n +8 | while read -r old; do rm -f -- "$old" "$old.sha256"; done
|
||||
local_copies="$(ls -1 "$LOCAL_DIR"/k3s-datastore-*.tar.gz | wc -l)"
|
||||
|
||||
offhost=0
|
||||
if [[ -n "${OFFHOST_GPG_RECIPIENT_FILE:-}" && -n "${OFFHOST_RCLONE_TARGET:-}" ]]; then
|
||||
command -v rclone >/dev/null || hb_fail "OFFHOST_RCLONE_TARGET is set but rclone is not installed"
|
||||
@@ -79,6 +89,9 @@ platform_backup_last_run_timestamp_seconds{backup="k3s-datastore"} $(date +%s)
|
||||
# TYPE platform_backup_last_size_bytes gauge
|
||||
platform_backup_last_size_bytes{backup="k3s-datastore"} $size
|
||||
platform_backup_last_duration_seconds{backup="k3s-datastore"} $(( $(date +%s) - started ))
|
||||
# HELP platform_backup_local_copies Archives kept outside AIStor on the HDD.
|
||||
# TYPE platform_backup_local_copies gauge
|
||||
platform_backup_local_copies{backup="k3s-datastore"} $local_copies
|
||||
# HELP platform_backup_offhost_copy 1 when the last run also wrote the encrypted off-host copy.
|
||||
# TYPE platform_backup_offhost_copy gauge
|
||||
platform_backup_offhost_copy{backup="k3s-datastore"} $offhost
|
||||
|
||||
@@ -8,7 +8,7 @@ desktop 호스트에서 systemd 타이머로 도는 백업과 점검이다. 결
|
||||
|
||||
| 대상 | 방법 | 주기 | 보관 | 위치 |
|
||||
| --- | --- | --- | --- | --- |
|
||||
| k3s datastore + `server/token` | `sqlite3 .backup` → tar.gz + sha256 | 매일 03:30 KST | 30일 | AIStor `platform-host-backups/k3s-datastore/` (HDD sdb3) |
|
||||
| k3s datastore + `server/token` | `sqlite3 .backup` → tar.gz + sha256 | 매일 03:30 KST | AIStor 30일 + 로컬 최근 7개 | AIStor `platform-host-backups/k3s-datastore/`와 `/srv/k3s/aistor/host-backups/k3s-datastore/`(root 0700). 둘 다 HDD sdb3 |
|
||||
| Gitea (저장소·패키지·첨부·Actions·`app.ini`) | 라이브 파드에서 `gitea dump --skip-db` | 일요일 04:00 KST | 56일(8주) | AIStor `platform-host-backups/gitea/` |
|
||||
| platform-postgres (Gitea·Keycloak·tech-log DB) | CloudNativePG base backup + WAL | 매일 03:00 KST | 30일 | AIStor `platform-postgres-backups/` (W1, `services/platform-postgres-backup`) |
|
||||
| AIStor 데이터(Loki·Tempo) | **백업하지 않는다** | — | — | 8절 결정 6: 잃어도 되는 관측 데이터. 디스크를 잃으면 로그·추적 기록만 사라진다 |
|
||||
@@ -18,6 +18,9 @@ desktop 호스트에서 systemd 타이머로 도는 백업과 점검이다. 결
|
||||
- k3s 백업에는 `token`이 들어 있다. token과 datastore가 같이 있으면 클러스터의 모든 Secret을 풀 수 있다.
|
||||
Gitea dump의 `app.ini`에도 비밀 값이 있다. 그래서 둘 다 AIStor의 전용 사용자만 읽고 쓴다.
|
||||
- AIStor는 같은 desktop의 HDD다. SSD가 죽으면 남지만 desktop 자체를 잃으면 같이 잃는다.
|
||||
- k3s 백업을 AIStor 밖에도 두는 이유: AIStor는 바로 그 k3s 위에서 돈다. 클러스터를 통째로 잃으면 AIStor를
|
||||
다시 띄우기 전에는 AIStor 안의 사본을 꺼낼 수 없다. 로컬 사본은 sdb3를 mount하기만 하면 읽힌다
|
||||
(`docs/runbooks/k3s-datastore-restore.md`). 폴더는 AIStor 드라이브 폴더(`data/`) 옆이라 bucket으로 보이지 않는다.
|
||||
|
||||
## off-host 사본 (준비만, 기본 꺼짐)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user