Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save khoahuynhdev/974282a5e06254977d7079ef94e8b323 to your computer and use it in GitHub Desktop.
Save khoahuynhdev/974282a5e06254977d7079ef94e8b323 to your computer and use it in GitHub Desktop.

Revisions

  1. @dobesv dobesv created this gist Dec 20, 2019.
    58 changes: 58 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,58 @@
    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: {}