argocd/apps/postgres/backup-cronjob.yaml
2026-10-11 21:03:33 +02:00

38 lines
1.4 KiB
YAML
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Nightly pg_dumpall streamed into restic on LXC 105, then a ping to the
# "Backup – Postgres (k3s)" Push monitor in Uptime Kuma.
# Suspended until postgres-backup-secrets exists (README, "Postgres backups").
apiVersion: batch/v1
kind: CronJob
metadata:
name: postgres-backup
spec:
suspend: true
schedule: "45 2 * * *"
timeZone: Europe/Paris
concurrencyPolicy: Forbid
jobTemplate:
spec:
backoffLimit: 1
template:
spec:
restartPolicy: Never
containers:
- name: backup
image: postgres:17.11-alpine
envFrom:
- secretRef:
name: postgres-secrets
- secretRef:
name: postgres-backup-secrets
command:
- /bin/sh
- -ec
- |
set -o pipefail
apk add --no-cache restic curl >/dev/null
restic cat config >/dev/null 2>&1 || restic init
export PGPASSWORD="$POSTGRES_PASSWORD"
pg_dumpall -h postgres -U postgres \
| restic backup --stdin --stdin-filename pg_dumpall.sql --host k3s-postgres
restic forget --host k3s-postgres --keep-daily 7 --keep-weekly 4 --keep-monthly 3 --prune
curl -fsS -m 10 -o /dev/null "$KUMA_PUSH_URL"