apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: postgres-backup
  namespace: backup-system
spec:
  # Backup the database every day at 5AM
  schedule: "00 05 * * *"
  jobTemplate:
    spec:
      template:
        spec:
          containers:
            - name: postgres-backup
              image: postgres:14
              command: ["/bin/sh"]
              args:
                [
                  "-c",
                  'pg_dump -U benji -h benji-postgresql-headless benji > /var/backups/pgsql/backup-$(date +"%m-%d-%Y-%H-%M").sql',
                ]
              env:
                - name: PGPASSWORD
                  value: secret
              volumeMounts:
                - mountPath: /var/backups
                  name: postgres-storage
          restartPolicy: Never
          volumes:
            - name: postgres-storage
              persistentVolumeClaim:
                claimName: nfs-backup-franxx-pvc
