apiVersion: batch/v1
kind: CronJob
metadata:
  name: postgres-backup-authentik
  namespace: backup-system
spec:
  # Backup the database every day at 2AM
  schedule: "01 00 * * *"
  concurrencyPolicy: "Forbid"
  successfulJobsHistoryLimit: 3
  failedJobsHistoryLimit: 5
  jobTemplate:
    spec:
      template:
        spec:
          containers:
            - name: postgres-backup
              image: postgres:14-alpine
              command: ["/bin/sh"]
              args:
                [
                  "-c",
                  'apk --no-cache add wget && pg_dump -U authentik -h ${SECRET_POSTGRES_HOST} authentik > /var/backups/authentik/backup-$(date +"%m-%d-%Y-%H-%M").sql && wget https://healthchecks.k8s.aml.ink/ping/181a9bed-6919-4ef6-9f54-282ecc018e57 -T 10 -t 5 -O /dev/null',
                ]
              env:
                - name: PGPASSWORD
                  value: ${SECRET_AUTHENTIK_POSTGRES_PASSWORD}
              volumeMounts:
                - mountPath: /var/backups
                  name: postgres-storage
          restartPolicy: Never
          volumes:
            - name: postgres-storage
              persistentVolumeClaim:
                claimName: backup-system-nfs-tank-share-pvc
