apiVersion: batch/v1
kind: Job
metadata:
  name: pg-bakcup-once
  namespace: db
spec:
  backoffLimit: 3
  ttlSecondsAfterFinished: 60
  template:
    spec:
      containers:
        - name: backup
          # Same image as in /etc/kubernetes/manifests/etcd.yaml
          image: mirror.gcr.io/postgres:14
          env:
            - name: DB_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: postgresql-credentials
                  key: password
            - name: DB_USER
              value: postgres
            - name: DB_HOST
              value: 192.168.1.2
          command: ["/bin/sh"]
          args: ["-c", "PGPASSWORD=$DB_PASSWORD pg_dumpall -c -h $DB_HOST -p 5432 -U $DB_USER| gzip > /backups/postgres/dump-$(date +%Y-%m-%d_%H-%M-%S_%Z).tar.gz"]
          volumeMounts:
            - mountPath: /backups/postgres
              subPath: postgres
              name: backup
      restartPolicy: OnFailure
      # tolerations:
      #   - effect: NoSchedule
      #     operator: Exists
      volumes:
        - name: backup
          persistentVolumeClaim:
            claimName: backups-nfs-pvc
