Skip to content

ianneub/pg_dump-to-s3

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pg_dump-to-s3

This docker container will backup a Postgres database using pg_dump and stream that to a file on S3.

You must configure awscli inside the container. This can be done using either ENV variables as shown below or any other method supported by awscli.

Example Usage

docker run -it -e PREFIX=mybackup/path -e AWS_ACCESS_KEY_ID=mykeyid -e AWS_SECRET_ACCESS_KEY=mysecretkey -e AWS_BUCKET=my-s3-bucket -e PGDATABASE=mydatabase -e PGUSER=myuser -e PGPASSWORD=mypassword -e PGHOST=db ianneub/pg_dump_to_s3

To build

make

Sanitize

If SQL_S3 is set, the script first runs aws s3 sync $SQL_S3 $SQL_DIR (default /sql). If any *.sql are then present, it switches from plain backup to sanitize: it dumps the live DB (PGHOST/PGDATABASE/…), restores it into an ephemeral local Postgres, runs every *.sql in filename order with ON_ERROR_STOP=1, then re-dumps the result to $DEST_S3. With no SQL files it performs the normal live-DB backup to s3://$AWS_BUCKET/$PREFIX/Y/M/D.dump.

Sanitize requires: PGHOST, PGDATABASE, PGUSER, PGPASSWORD, DEST_S3. Optional: SQL_S3, SQL_DIR, LOCAL_DB (default sanitize).

A script that RAISEs aborts the run before upload.

About

Dump a Postgres database to S3

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors