2023-11-28 22:28:34 +01:00

38 lines
1.1 KiB
YAML

apiVersion: batch/v1
kind: CronJob
metadata:
name: postgres-backup
spec:
# Backup the database every day at 1AM
schedule: "0 1 * * *"
jobTemplate:
spec:
template:
spec:
containers:
- name: postgres-backup
image: postgres:15
command: ["/bin/sh"]
args:
- "-c"
- >-
echo "$postgress_password" > /root/.pgpass
&&
chmod 600 /root/.pgpass
&&
pg_dumpall -U postgres -h postgrespostgres-postgresql.postgres > /backup/backup-$(date +"%m-%d-%Y-%H-%M").sql
env:
- name: PGpostgress_passwordPASS
valueFrom:
secretKeyRef:
name: postgres-password
key: password
volumeMounts:
- mountPath: /backup
name: postgres-backup-claim
restartPolicy: Never
volumes:
- name: postgres-backup-claim
persistentVolumeClaim:
claimName: postgres-backup-claim