Giter Site home page Giter Site logo

nosredna / docker-backup-postgres-s3 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from lucaspiller/docker-backup-postgres-s3

0.0 1.0 0.0 4 KB

Docker image to periodically backup a PostgreSQL database to S3.

Home Page: https://hub.docker.com/r/lucaspiller/backup-postgres-s3

License: MIT License

Dockerfile 10.59% Shell 89.41%

docker-backup-postgres-s3's Introduction

backup-postgres-s3

Docker image to periodically backup a PostgreSQL database to S3.

Why this container?

Yes there are a lot of other containers that promise to do similar things, however I found they didn't fulfil my requirements.

  • I needed an image that was up to date - you can't backup Postgres 11 with a 10 client.
  • A lot of the other images do weird stuff like re-implement cron.
  • This image runs on Alpine, so it's small. Additionally it's based on the official PostgreSQL image, so if you already have that, then there is even less to download.

Required Envionment Variables

  • S3_ACCESS_KEY_ID - Your AWS access key.

  • S3_SECRET_ACCESS_KEY - Your secret access key.

  • S3_PATH - S3 bucket, and optionally path. Should not end in a trailing slash, e.g. s3://myapp/db-backups.

  • POSTGRES_HOST - Hostname of the PostgreSQL database to backup, alternatively this container can be linked to the container with the name postgres.

  • POSTGRES_DATABASE - Name of the PostgreSQL database to backup.

  • POSTGRES_USER - PostgreSQL user, with priviledges to dump the database.

Optional Enviroment Variables

  • POSTGRES_PASSWORD - Password for the PostgreSQL user, if you are using a database on the same machine this isn't usually needed.
  • POSTGRES_PORT - Port of the PostgreSQL database, uses the default 5432.
  • POSTGRES_EXTRA_OPTS - Extra arguments to pass to the pg_dump command.
  • S3_REGION - Set the default AWS region to send the upload request to.
  • AWS_EXTRA_OPTS - Extra arguments to pass to the aws command.
  • SCHEDULE - Cron schedule to run periodic backups.

Examples

By default if you run the container without any extra arguments it'll run cron and backup periodically based on SCHEDULE:

$ docker run --rm
  -e S3_ACCESS_KEY_ID=<aws-key> \
  -e S3_SECRET_ACCESS_KEY=<aws-secret-key> \
  -e S3_BUCKET=<bucket> \
  -e S3_PATH=s3://myapp/db-backups \
  -e POSTGRES_DATABASE=postgres \
  -e POSTGRES_HOST=localhost \
  -e POSTGRES_USER=postgres \
  -e SCHEDULE=@daily \
  lucaspiller/backup-postgres-s3
crond: crond (busybox 1.28.4) started, log level 8

SCHEDULE can either be a cron five field format 45 3 * * * (every day at 3:45am) or a predefined format (@weekly). See crontab guru for more details.

If you pass the backup argument it'll run a backup right now:

$ docker run --rm
  -e S3_ACCESS_KEY_ID=<aws-key> \
  -e S3_SECRET_ACCESS_KEY=<aws-secret-key> \
  -e S3_BUCKET=<bucket> \
  -e S3_PATH=s3://myapp/db-backups \
  -e POSTGRES_DATABASE=postgres \
  -e POSTGRES_HOST=localhost \
  -e POSTGRES_USER=postgres \
  -e SCHEDULE=@daily \
  lucaspiller/backup-postgres-s3 backup
Creating dump of postgres database from localhost...
Uploading dump to s3://myapp/db-backups/postgres_2019-01-24T20:23:25Z.sql.gz
SQL backup uploaded successfully

The tags are based on the PostgreSQL version the image is built with. You should just be able to use the latest version, even with older PostgreSQL server versions, but if you need a different version for any reason they are available.

Acknowledgements

Some scripts based on schickling/postgres-backup-s3.

docker-backup-postgres-s3's People

Contributors

lucaspiller avatar

Watchers

 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.