This container can be used to easily take snapshots of your Postgres database and upload them to Amazon S3
DATABASE_URL
postgres://user:password@host:5432/databaseAlternatively, you may provide the individual connection values:
DB_NAME required - the database nameDB_USER required - the usernameDB_PASS required - the passwordDB_HOST required - the hostname ONLY (do not include the port)DB_PORT (default: 5432)S3_BUCKET requiredS3_ACL (default: private)S3_PREFIX (default: scheduled-)
/)The easiest way to configure permissions is by using an IAM instance role, and granting the instance running the snapshot the ability to upload objects to the specified S3 bucket. If that is not possible, then you can provide your credentials using the following environment variables:
S3_ACCESS_KEYS3_SECRET_KEYDUMP_FOLDER (default: /tmp)
DUMP_FORMAT (default: custom)
pg_dump. If you are planning to use pg_restore to recover, you should stick with the default of custom.THREADS (default: 1)
You can read a more detailed explanation about these options on the pg_dump documentation.
If your main docker location does not have enough space, you will need to change the DUMP_FOLDER variable and mount a host directory into your container. You should include ExecStartPost=-/usr/bin/rm -f /host/folder/snapshot.dump in your service file just in case something goes wrong.
IMPORTANT: If you mount a host folder, you are completely responsible for ensuring that two snapshot tasks are not accessing the same host folder at the same time. If a second instance starts changing the backup file while it is being uploaded or exported, bad things can happen.
This is best used with a timer and service combination in your cluster.
# postgres-s3-snapshot.timer
[Unit]
Description=PostgreSQL Scheduled Snapshot Timer
[Timer]
OnCalendar=daily
Persistent=false
[Install]
WantedBy=multi-user.target
[X-Fleet]
Conflicts=%p.timer
MachineOf=%p.service
# postgres-s3-snapshot.service
[Unit]
Description=PostgreSQL Scheduled Snapshot
Requires=docker.service
After=docker.service
[Service]
TimeoutStartSec=0
Type=simple
ExecStartPre=-/usr/bin/docker pull webdestroya/postgres-s3-snapshot
ExecStart=/usr/bin/docker run --rm=true \
-e DATABASE_URL=postgres://postgres:[email protected]:5432/database \
-e S3_BUCKET=postgres-snapshots \
-e S3_PREFIX=cluster1-snaps/ \
webdestroya/postgres-s3-snapshot
[Install]
WantedBy=multi-user.target
[X-Fleet]
Conflicts=%p.service
Content type
Image
Digest
sha256:f269fbda7…
Size
79.9 MB
Last updated
over 11 years ago
docker pull webdestroya/postgres-s3-snapshot