32 lines
1020 B
YAML
32 lines
1020 B
YAML
apiVersion: batch/v1beta1
|
|
kind: CronJob
|
|
metadata:
|
|
name: postgres-backup
|
|
spec:
|
|
# Backup the database every day at 2AM
|
|
schedule: "0 2 * * *"
|
|
jobTemplate:
|
|
spec:
|
|
template:
|
|
spec:
|
|
containers:
|
|
- name: postgres-backup
|
|
image: postgres:12
|
|
command: ["/bin/sh"]
|
|
args: ["-c", 'echo "$PGPASS" > /root/.pgpass && chmod 600 /root/.pgpass && pg_dump -U postgres_admin -h postgres test_database > /var/backups/backup-$(date +"%m-%d-%Y-%H-%M").sql']
|
|
env:
|
|
- name: PGPASS
|
|
valueFrom:
|
|
secretKeyRef:
|
|
name: pgpass
|
|
key: pgpass
|
|
volumeMounts:
|
|
- mountPath: /var/backups
|
|
name: postgres-storage
|
|
restartPolicy: Never
|
|
volumes:
|
|
- name: postgres-storage
|
|
hostPath:
|
|
# Ensure the file directory is created.
|
|
path: /var/volumes/postgres-backups
|
|
type: DirectoryOrCreate |