# hourly backup of pg12 database to NAS volume
apiVersion: batch/v1
kind: CronJob
metadata:
  name: pg12-backup
spec:
  schedule: "12 * * * *"
  concurrencyPolicy: Forbid
  startingDeadlineSeconds: 600
  failedJobsHistoryLimit: 10
  successfulJobsHistoryLimit: 36
  jobTemplate:
    spec:
      activeDeadlineSeconds: 1200
      template:
        spec:
          containers:
          - name: pg12-backup
            image: bitnami/postgresql:12.9.0-debian-10-r62
            imagePullPolicy: IfNotPresent
            command:
            - /bin/sh
            args:
            - -c
            - umask 0177 ; /opt/bitnami/postgresql/bin/pg_dumpall -h app-database-pg12 -p 6432 -U postgres > /backup/pg12_dump_$(date -u +%H).sql
            env:
            - name: PGPASSWORD
              valueFrom:
                secretKeyRef:
                  name: pg12-creds
                  key: postgresql-password
            volumeMounts:
              - name: pg12-backup
                mountPath: /backup
          volumes:
            - name: pg12-backup
              persistentVolumeClaim:
                claimName: pg12-backup-claim
          restartPolicy: OnFailure
