Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

62 Commits

Repository files navigation

postgres-backup is a Postgres backup helper that:

  • Takes the dump of the Postgres database
  • Uploads it to either AWS S3 or SFTP server
  • Reports to WebGazer (optional)
  • Reports to Gatus (optional)

Usage

Environment variables

VariableRequiredDefault valueDescription
DESTINATION_KINDDestination type: s3 or sftp
DESTINATION_PATHDestination path (e.g. "postgres-backup" for S3 bucket path or "/backups" for SFTP directory)
GATUS_EXTERNAL_ENDPOINT_TOKENBearer token for Gatus external endpoint authentication
GATUS_EXTERNAL_ENDPOINT_URLGatus external endpoint URL
POSTGRES_DBPostgres server database
POSTGRES_HOSTpostgresPostgres server host
POSTGRES_PASSWORDPostgres server password
POSTGRES_PORT5432Postgres server port
POSTGRES_USERpostgresPostgres server user
POSTGRES_VERSION18Postgres server version (16, 17 or 18).
WEBGAZER_HEARTBEAT_URLWebGazer Heartbeat Monitor URL

S3-specific variables (required when DESTINATION_KIND=s3)

VariableRequiredDefault valueDescription
S3_ACCESS_KEY_IDAccess key id for the S3-compatible storage
S3_REGIONRegion for the S3 bucket
S3_SECRET_ACCESS_KEYSecret access key for the S3-compatible storage
S3_PROVIDERAWSS3 provider (AWS, MinIO, etc.)
S3_ENDPOINTEndpoint URL for the S3-compatible storage
S3_STORAGE_CLASSSTANDARD_IAS3 storage class (see https://aws.amazon.com/s3/storage-classes/ and https://rclone.org/s3/#s3-storage-class for options)

SFTP-specific variables (required when DESTINATION_KIND=sftp)

VariableRequiredDefault valueDescription
SFTP_HOSTSFTP server hostname
SFTP_USERSFTP server username
SFTP_PORT22SFTP server port
SFTP_PASSWORD⚠️SFTP server password (either this or SFTP_PRIVATE_KEY must be set)
SFTP_PRIVATE_KEY⚠️SFTP private key content (base64 encoded, either this or SFTP_PASSWORD must be set)

Note: For SFTP authentication, you must provide either SFTP_PASSWORD or SFTP_PRIVATE_KEY, but not both. The private key will be temporarily stored in the container and automatically cleaned up after use. The SFTP_PRIVATE_KEY should be base64 encoded to avoid issues with special characters and newlines in environment variables. Passwords are automatically obscured using rclone's built-in obscure command for compatibility with rclone's SFTP backend.

Running

S3 backup example

$ docker run \
-e DESTINATION_KIND=s3 \
-e DESTINATION_PATH=postgres-backup \
-e S3_ACCESS_KEY_ID=<s3_access_key_id> \
-e S3_REGION=<s3_region> \
-e S3_SECRET_ACCESS_KEY=<s3_secret_access_key> \
-e S3_STORAGE_CLASS=<s3_storage_class[STANDARD_IA]> \
-e POSTGRES_DB=<database> \
-e POSTGRES_HOST=<postgres_hostname[postgres]> \
-e POSTGRES_PASSWORD=<postgres_password> \
-e POSTGRES_PORT=<postgres_port[5432]> \
-e POSTGRES_USER=<postgres_user[postgres]> \
-e POSTGRES_VERSION=<postgres_version[18]> \
-e WEBGAZER_HEARTBEAT_URL=<webgazer_heartbeat_url> \
code.unius.sh/unius/postgres-backup:1.0.6

SFTP backup example

Using password authentication:

$ docker run \
-e DESTINATION_KIND=sftp \
-e DESTINATION_PATH=/backups \
-e SFTP_HOST=<sftp_host> \
-e SFTP_PASSWORD=<sftp_password> \
-e SFTP_USER=<sftp_user> \
-e SFTP_PORT=<sftp_port[22]> \
-e POSTGRES_DB=<database> \
-e POSTGRES_HOST=<postgres_hostname[postgres]> \
-e POSTGRES_PASSWORD=<postgres_password> \
-e POSTGRES_PORT=<postgres_port[5432]> \
-e POSTGRES_USER=<postgres_user[postgres]> \
-e POSTGRES_VERSION=<postgres_version[18]> \
-e WEBGAZER_HEARTBEAT_URL=<webgazer_heartbeat_url> \
code.unius.sh/unius/postgres-backup:1.0.6

Using private key authentication:

$ docker run \
-e DESTINATION_KIND=sftp \
-e DESTINATION_PATH=/backups \
-e SFTP_HOST=<sftp_host> \
-e SFTP_PRIVATE_KEY="$(cat ~/.ssh/id_rsa | base64)" \
-e SFTP_USER=<sftp_user> \
-e SFTP_PORT=<sftp_port[22]> \
-e POSTGRES_DB=<database> \
-e POSTGRES_HOST=<postgres_hostname[postgres]> \
-e POSTGRES_PASSWORD=<postgres_password> \
-e POSTGRES_PORT=<postgres_port[5432]> \
-e POSTGRES_USER=<postgres_user[postgres]> \
-e POSTGRES_VERSION=<postgres_version[18]> \
-e WEBGAZER_HEARTBEAT_URL=<webgazer_heartbeat_url> \
code.unius.sh/unius/postgres-backup:1.0.6

Shameless plug

I am an indie hacker, and I am running two services that might be useful for your business. Check them out :)

WebGazer

WebGazer

WebGazer is a monitoring service that checks your website, cron jobs, or scheduled tasks on a regular basis. It notifies you with instant alerts in case of a problem. That way, you have peace of mind about the status of your service without manually checking it.

PoeticMetric

PoeticMetric

PoeticMetric is a privacy-first, regulation-compliant, blazingly fast analytics tool.

No cookies or personal data collection. So you don't have to worry about cookie banners or GDPR, CCPA, and PECR compliance.

License

Copyright © 2025, Gokhan Sari. Released under the GPL License.

About

A docker utility to backup PostgreSQL databases.

Topics

Resources

Stars

6 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages