Sign inSign up

cl00e9ment/postgresql-backup-s3-crypt

By cl00e9ment

•Updated almost 5 years ago

Image
0

333

cl00e9ment/postgresql-backup-s3-crypt repository overview

⁠PostgreSQL Backup S3 Crypt

Open Source⁠ image based on Alpine Linux⁠.

  • Makes periodic PostgreSQL backups to S3.
  • Compresses and encrypts backups before sending them to S3.
  • Aborts the backup creation if the database was not modified.
  • Can delete old backups from S3 to keep only the most recent ones.
  • Can quickly fetch a backup from S3 then decrypt it and decompress it on the fly.

⁠Start the container

⁠Example
docker run -it --rm --name postgresql-backup-s3-crypt \
	-e POSTGRESQL_HOST=172.17.0.1 \
	-e POSTGRESQL_USER=root \
	-e POSTGRESQL_PASSWORD=SuP3R_5tr0ng-P@S5w0rD \
	-e POSTGRESQL_DATABASES='my_database_1 my_database_2 my_database_3' \
	-e AWS_ACCESS_KEY_ID=MY_AWS_KEY_ID \
	-e AWS_SECRET_ACCESS_KEY=my_super_secret_aws_access_key \
	-e AWS_DEFAULT_REGION=eu-west-3 \
	-e AWS_BUCKET_NAME=my-bucket-name \
	-e ENCRYPTION_PASSPHRASE=My-5uP3R_Str0NG-_p@55PhrAse \
	-e MAX_BACKUPS=7 \
	-e CRON_TIME='0 5 * * *' \
	cl00e9ment/postgresql-backup-s3-crypt
⁠Explanation of environment variables
VariableRequiredDescription
POSTGRESQL_HOSTyesThe hostname or IP address of the PostgreSQL server.
POSTGRESQL_PORTnoThe port of the PostgreSQL server. If not set, it will be 5432.
POSTGRESQL_USERyesThe PostgreSQL user that make the backup.
POSTGRESQL_PASSWORDyesThe password of the PostgreSQL user that make the backup.
POSTGRESQL_DATABASESyesA space separated list of PostgreSQL databases to backup.
AWS_ACCESS_KEY_IDyesThe ID of the AWS access key used to upload backups to S3.
AWS_SECRET_ACCESS_KEYyesThe AWS access key used to upload backups to S3.
AWS_DEFAULT_REGIONyesThe AWS region where the bucket lives.
AWS_BUCKET_NAMEyesThe name of the AWS bucket where to upload the backups.
ENCRYPTION_PASSPHRASEyesThe passphrase used to encrypt the backups before sending them to S3.
MAX_BACKUPSnoThe max number of backups of a specific database to keep on S3. If set, old backups will be deleted. If not set, no backup will be deleted.
CRON_TIMEyesA cron schedule expression⁠ to indicate when the backups must be made (in UTC time).
⁠Important considerations

!!! WARNING !!!
Keep a copy of the ENCRYPTION_PASSPHRASE outside of your server, because if a problem occurs on your server, you will not be able to recover your backups.

!!! WARNING !!!
Do not enable bucket versioning, because PostgreSQL Backup S3 Crypt handle versioning by itself.

⁠CLI

Commands that can be run when the container is running.

⁠Manually start a backup

Replace [DATABASES]... by a list of space separated databases to backup or leave it empty to backup all databases given in POSTGRES_DATABASES environment variable.

docker exec postgresql-backup-s3-crypt backup [DATABASES]...
⁠List all backups
docker exec postgresql-backup-s3-crypt list
⁠List backups of specific database
docker exec postgresql-backup-s3-crypt list my_database_3
⁠Fetch a backup

You can use the fetch command to print on stdin the content of a backup file. The script will download, decrypt and decompress the file for you.

docker exec postgresql-backup-s3-crypt fetch my_database_3-20210227025458-8c34f5b1ef4c5feacb672f75975f26bc655bb842.sql.xz.gpg

Tag summary

Content type

Image

Digest

Size

101.9 MB

Last updated

almost 5 years ago

docker pull cl00e9ment/postgresql-backup-s3-crypt