Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save khoahuynhdev/974282a5e06254977d7079ef94e8b323 to your computer and use it in GitHub Desktop.
Save khoahuynhdev/974282a5e06254977d7079ef94e8b323 to your computer and use it in GitHub Desktop.
Example of a kubernetes cron job that dumps a postgres database and copies it to s3
apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: postgres-backup
spec:
schedule: "0 12 * * *"
jobTemplate:
spec:
backoffLimit: 0
template:
spec:
initContainers:
- name: dump
image: postgres:12.1-alpine
volumeMounts:
- name: data
mountPath: /backup
args:
- pg_dump
- "-Fc"
- "-f"
- "/backup/redash-postgres.pgdump"
- "-Z"
- "9"
- "-v"
- "-h"
- "postgres"
- "-U"
- "postgres"
- "-d"
- "redash"
env:
- name: PGPASSWORD
valueFrom:
secretKeyRef:
# Retrieve postgres password from a secret
name: postgres
key: POSTGRES_PASSWORD
containers:
- name: save
image: mesosphere/aws-cli
volumeMounts:
- name: data
mountPath: /backup
args:
- aws
- s3
- cp
- "/backup/redash-postgres.pgdump"
- "s3://redash-postgres-backups/redash-postgres.pgdump"
envFrom:
- secretRef:
# Must contain AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_DEFAULT_REGION
name: s3-backup-credentials
restartPolicy: Never
volumes:
- name: data
emptyDir: {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment