Coder Social home page Coder Social logo

docker-postgres-backup's Introduction

Postgres Backup

This little Docker container is for using pg_dump to backup a PostgreSQL instance to Google Cloud Storage.

It's designed to be run as a Kubernetes CronJob.

Environment Variables

  • POSTGRES_HOST - Postgres host (or Kubernetes service) to connect to.
  • POSTGRES_USER - Username with permissions for database.
  • POSTGRES_PASSWORD - Password for user.
  • POSTGRES_DATABASE - Database to dump
  • DUMP_ARGS - Extra arguments to pass to pg_dump in case you want to ignore files or otherwise.
    • Such as --exclude-table-data bad_table
  • PROJECT - Name of the project
  • BUCKET_NAME - Bucket to store the backups in.
  • CREDENTIAL_PATH - Path to where the Google Cloud service account with permissions for the given bucket are stored.

What happens

After a little shuffling of environment variables, it will run pg_dump and stream the raw sql dump into gsutil to create a object with a name like 2018-09-30_09:49:04.dump.sql in the given bucket.

Service Account Permissions

The service account will need 'Storage Object Creator' and 'Storage Object Viewer' permissions.

Example CronJob config

apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: postgresql-backup
spec:
  schedule: "45 1 * * *"
  jobTemplate:
    spec:
      template:
        spec:
          containers:
          - name: backup
            image: abkfenris/postgres-gs-backup:0.17
            env:
            - name: POSTGRES_USER
              value: postgres
            - name: POSTGRES_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: shared-secrets
                  key: POSTGRES_PASSWORD
            - name: POSTGRES_HOST
              value: postgresql
            - name: POSTGRES_DATABASE
              value: postgres
            - name: PROJECT
              value: my_project
            - name: BUCKET_NAME
              value: auto-backup
            - name: CREDENTIAL_PATH
              value: /credentials/service-account.json
            - name: DUMP_ARGS
              value: "--exclude-table-data=massiveTable"
            volumeMounts:
            - name: credentials
              mountPath: "/credentials"
          restartPolicy: Never
          volumes:
          - name: credentials
            secret:
              secretName: backup-account

docker-postgres-backup's People

Contributors

abkfenris avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.