Compare commits

..
Author SHA1 Message Date
Danijel Simeunovic 3a963b4705 Merge branch 'main' of ssh://git.forteapps.net:2222/Forte/launchpad into hotfix/gitea-backup
scan.yaml / test (pull_request) Successful in 7s
2026-11-17 15:28:35 +01:00
danijel.simeunovic 875a8babaa Delete .gitea/workflows/ai-review.yaml
scan.yaml / test (pull_request) Successful in 5s
2026-10-14 00:51:28 +02:00
danijel.simeunovic 90b8e6f2a4 fix backups
scan.yaml / test (pull_request) Successful in 7s
2026-10-14 00:42:57 +02:00
2 changed files with 45 additions and 36 deletions
@@ -29,11 +29,10 @@ kubectl -n forte-drop get pods -l app.kubernetes.io/name=postgresql
## List available backups ## List available backups
```bash ```bash
# Run an ephemeral rclone pod with the app's S3 creds (the backup job's image # Run an ephemeral mc pod with the app's S3 creds:
# and env-var remote; the mc image used here before can no longer be pulled): kubectl -n forte-drop run mc-list --rm -it --restart=Never \
kubectl -n forte-drop run rclone-list --rm -it --restart=Never \ --image=quay.io/minio/mc:RELEASE.2024-11-21T17-21-54Z \
--image=rclone/rclone:1.75.2 \ --overrides='{"spec":{"containers":[{"name":"mc","image":"quay.io/minio/mc:RELEASE.2024-11-21T17-21-54Z","command":["sh","-c","mc alias set obj \"$S3_ENDPOINT\" \"$S3_KEY\" \"$S3_SECRET\" >/dev/null && mc ls obj/drops/_pgbackups/"],"envFrom":[{"secretRef":{"name":"forte-drop-secrets"}}]}]}}'
--overrides='{"spec":{"containers":[{"name":"rclone","image":"rclone/rclone:1.75.2","command":["sh","-c","export RCLONE_CONFIG_S3_TYPE=s3 RCLONE_CONFIG_S3_PROVIDER=Other RCLONE_CONFIG_S3_ENDPOINT=\"$S3_ENDPOINT\" RCLONE_CONFIG_S3_ACCESS_KEY_ID=\"$S3_KEY\" RCLONE_CONFIG_S3_SECRET_ACCESS_KEY=\"$S3_SECRET\" HOME=/tmp; rclone lsl s3:drops/_pgbackups/ 2>/dev/null"],"envFrom":[{"secretRef":{"name":"forte-drop-secrets"}}]}]}}'
``` ```
## Manually trigger a backup (before risky changes) ## Manually trigger a backup (before risky changes)
@@ -54,17 +53,41 @@ kubectl -n forte-drop logs -l app.kubernetes.io/component=backup --tail=40
List backups (above), choose `forte-drop-<TS>.sql.gz`. List backups (above), choose `forte-drop-<TS>.sql.gz`.
### 2. Download the dump, then pipe it into Postgres ### 2. Run a restore pod that pulls the dump and pipes it into Postgres
```bash ```bash
DUMP="forte-drop-20260530T020000Z.sql.gz" # <-- set to the chosen file DUMP="forte-drop-20260530T020000Z.sql.gz" # <-- set to the chosen file
kubectl -n forte-drop run pg-restore --rm -it --restart=Never \
--image=postgres:16-alpine \
--overrides='{
"spec": {
"containers": [{
"name": "restore",
"image": "postgres:16-alpine",
"command": ["sh","-c","set -euo pipefail; \
apk add --no-cache curl >/dev/null; \
# download via mc is simpler — use a 2-step instead (see note). \
echo placeholder"],
"envFrom": [
{"secretRef":{"name":"forte-drop-pg-creds"}},
{"secretRef":{"name":"forte-drop-secrets"}}
]
}]
}
}'
```
**Simpler 2-pod approach (recommended — avoids cramming mc + psql in one image):**
```bash
DUMP="forte-drop-20260530T020000Z.sql.gz"
# (a) Download the dump from object storage to a local file: # (a) Download the dump from object storage to a local file:
kubectl -n forte-drop run rclone-get --rm -i --restart=Never --quiet \ kubectl -n forte-drop run mc-get --rm -it --restart=Never \
--image=rclone/rclone:1.75.2 \ --image=quay.io/minio/mc:RELEASE.2024-11-21T17-21-54Z \
--overrides='{"spec":{"containers":[{"name":"rclone","image":"rclone/rclone:1.75.2","command":["sh","-c","export RCLONE_CONFIG_S3_TYPE=s3 RCLONE_CONFIG_S3_PROVIDER=Other RCLONE_CONFIG_S3_ENDPOINT=\"$S3_ENDPOINT\" RCLONE_CONFIG_S3_ACCESS_KEY_ID=\"$S3_KEY\" RCLONE_CONFIG_S3_SECRET_ACCESS_KEY=\"$S3_SECRET\" HOME=/tmp; rclone cat s3:drops/_pgbackups/'"$DUMP"' 2>/dev/null"],"envFrom":[{"secretRef":{"name":"forte-drop-secrets"}}]}]}}' \ --overrides='{"spec":{"containers":[{"name":"mc","image":"quay.io/minio/mc:RELEASE.2024-11-21T17-21-54Z","command":["sh","-c","mc alias set obj \"$S3_ENDPOINT\" \"$S3_KEY\" \"$S3_SECRET\" >/dev/null && mc cat obj/drops/_pgbackups/'"$DUMP"'"],"envFrom":[{"secretRef":{"name":"forte-drop-secrets"}}]}]}}' \
> /tmp/$DUMP > /tmp/$DUMP
gunzip -t /tmp/$DUMP && ls -lh /tmp/$DUMP # must pass before you go on
# (b) Pipe it into the live Postgres via the service: # (b) Pipe it into the live Postgres via the service:
gunzip -c /tmp/$DUMP | kubectl -n forte-drop run pg-restore --rm -i --restart=Never \ gunzip -c /tmp/$DUMP | kubectl -n forte-drop run pg-restore --rm -i --restart=Never \
@@ -104,7 +127,7 @@ UpCloud-managed/replicated, so no separate file backup is configured. If a
file-level backup is later required, mirror the bucket to a second bucket/region: file-level backup is later required, mirror the bucket to a second bucket/region:
```bash ```bash
rclone sync s3:drops/ backup-target:drops-mirror/ --exclude "_pgbackups/**" mc mirror --overwrite obj/drops/ backup-target/drops-mirror/
``` ```
(Exclude `_pgbackups/` from the app-data mirror if you split them.) (Exclude `_pgbackups/` from the app-data mirror if you split them.)
@@ -2,7 +2,7 @@
# Dumps to s3://drops/_pgbackups/ (the `_` prefix is collision-proof: app slugs match # Dumps to s3://drops/_pgbackups/ (the `_` prefix is collision-proof: app slugs match
# /^[a-z0-9][a-z0-9-]{0,62}$/ and can never start with `_`). Retains 30 days. # /^[a-z0-9][a-z0-9-]{0,62}$/ and can never start with `_`). Retains 30 days.
# #
# Pod shape: initContainer pg_dump → shared emptyDir → rclone upload + retention prune. # Pod shape: initContainer pg_dump → shared emptyDir → mc upload + retention prune.
# Both images pinned. S3 creds reuse forte-drop-secrets (the app's UpCloud user has # Both images pinned. S3 creds reuse forte-drop-secrets (the app's UpCloud user has
# s3:* on the drops bucket). PG creds from forte-drop-pg-creds. # s3:* on the drops bucket). PG creds from forte-drop-pg-creds.
apiVersion: batch/v1 apiVersion: batch/v1
@@ -65,38 +65,24 @@ spec:
mountPath: /work mountPath: /work
containers: containers:
- name: upload - name: upload
# Was quay.io/minio/mc until MinIO made the mc repository private: image: quay.io/minio/mc:RELEASE.2024-11-21T17-21-54Z
# every tag now answers 401 on quay.io and Docker Hub, so the pod
# cannot pull it (same cause and fix as cluster-resources/
# gitea-backup-cronjob.yaml). rclone is a public, pinned equivalent:
# `delete --min-age` replaces `mc rm --older-than`.
image: rclone/rclone:1.75.2
command: command:
- sh - sh
- -c - -c
- | - |
set -euo pipefail set -euo pipefail
export RCLONE_CONFIG_S3_ENDPOINT="${S3_ENDPOINT}" mc alias set obj "$S3_ENDPOINT" "$S3_KEY" "$S3_SECRET"
export RCLONE_CONFIG_S3_ACCESS_KEY_ID="${S3_KEY}" mc cp /work/*.sql.gz "obj/${S3_BUCKET}/_pgbackups/"
export RCLONE_CONFIG_S3_SECRET_ACCESS_KEY="${S3_SECRET}"
# Only ever this prefix: the bucket also holds every drop.
DEST="s3:${S3_BUCKET}/_pgbackups/"
rclone copy /work "$DEST" --include "*.sql.gz"
echo "uploaded. pruning backups older than 30d:" echo "uploaded. pruning backups older than 30d:"
rclone delete --min-age 30d --use-server-modtime "$DEST" || true mc rm --recursive --force --older-than 30d "obj/${S3_BUCKET}/_pgbackups/" || true
echo "backup retention pass complete" echo "backup retention pass complete"
env: env:
# rclone wants a writable home for its cache; the root fs is not # mc writes its config under $MC_CONFIG_DIR; point it at the shared
# writable for uid 65532, the shared emptyDir is (fsGroup). # emptyDir (writable by uid 65532 via fsGroup). Without this it tries
- name: HOME # to mkdir /.mc on the read-only-to-nonroot root fs -> "mkdir /.mc:
value: "/work" # permission denied" and every run fails before uploading.
- name: RCLONE_CONFIG_S3_TYPE - name: MC_CONFIG_DIR
value: s3 value: "/work/.mc"
- name: RCLONE_CONFIG_S3_PROVIDER
value: Other
# Do not call CreateBucket before the first write.
- name: RCLONE_S3_NO_CHECK_BUCKET
value: "true"
- name: S3_ENDPOINT - name: S3_ENDPOINT
valueFrom: valueFrom:
secretKeyRef: { name: forte-drop-secrets, key: S3_ENDPOINT } secretKeyRef: { name: forte-drop-secrets, key: S3_ENDPOINT }