{"id":18564340,"url":"https://github.com/heyman/postgresql-backup","last_synced_at":"2025-07-16T08:12:26.500Z","repository":{"id":45291069,"uuid":"44742773","full_name":"heyman/postgresql-backup","owner":"heyman","description":"Docker image that periodically dumps a Postgres database, and uploads it to an Amazon S3 bucket.","archived":false,"fork":false,"pushed_at":"2025-01-02T13:10:36.000Z","size":83,"stargazers_count":57,"open_issues_count":1,"forks_count":41,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-30T13:10:39.620Z","etag":null,"topics":["backup","docker","postgresql"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/heyman.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-10-22T12:08:05.000Z","updated_at":"2025-01-02T13:10:40.000Z","dependencies_parsed_at":"2025-02-27T08:30:13.203Z","dependency_job_id":"447cc988-ac78-4167-97d5-b1b6660228c0","html_url":"https://github.com/heyman/postgresql-backup","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heyman%2Fpostgresql-backup","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heyman%2Fpostgresql-backup/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heyman%2Fpostgresql-backup/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heyman%2Fpostgresql-backup/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/heyman","download_url":"https://codeload.github.com/heyman/postgresql-backup/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247500469,"owners_count":20948880,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["backup","docker","postgresql"],"created_at":"2024-11-06T22:14:53.941Z","updated_at":"2025-04-06T15:13:18.922Z","avatar_url":"https://github.com/heyman.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Docker PostgreSQL Backup\n\n[![Build Status](https://github.com/heyman/postgresql-backup/workflows/Test/badge.svg)](https://github.com/heyman/postgresql-backup/actions?query=workflow%3ATest)\n\nDocker image that periodically dumps a Postgres database, and optionally uploads it to an Amazon S3 bucket.\n\nAvailable on Docker Hub: [heyman/postgresql-backup](https://hub.docker.com/r/heyman/postgresql-backup)\n\n## Example\n\n```\ndocker run -it --rm --name=pgbackup \\\n    -e CRON_SCHEDULE=\"* * * * *\" \\\n    -e DB_HOST=the.db.host \\\n    -e DB_USER=username \\\n    -e DB_PASS=password \\\n    -e DB_NAME=database_name \\\n    -e S3_PATH='s3://my-bucket/backups/' \\\n    -e AWS_ACCESS_KEY_ID='[aws key id]' \\\n    -e AWS_SECRET_ACCESS_KEY='[aws secret key]' \\\n    heyman/postgresql-backup:15\n```\n\n## Required environment variables\n\n* `CRON_SCHEDULE`: The time schedule part of a crontab file (e.g: `15 3 * * *` for every night 03:15)\n* `DB_HOST`: Postgres hostname\n* `DB_PASS`: Postgres password\n* `DB_USER`: Postgres username\n* `DB_NAME`: Name of database\n\n## Optional environment variables\n\n* `S3_PATH`: Amazon S3 path in the format: s3://bucket-name/some/path\n* `AWS_ACCESS_KEY_ID`\n* `AWS_SECRET_ACCESS_KEY`\n* `AWS_DEFAULT_REGION`\n* `S3_STORAGE_CLASS`: Specify [storage class](https://docs.aws.amazon.com/AmazonS3/latest/userguide/storage-class-intro.html) for the uploaded object, defaults to `STANDARD_IA`.\n* `S3_EXTRA_OPTIONS`: Specify additional options for S3, e.g. `--endpoint=` for using custom S3 provider.\n* `DB_USE_ENV`: Inject [postgres environment variables](https://www.postgresql.org/docs/13/libpq-envars.html) from the environment. Ignores `DB_HOST`, `DB_PASS`, `DB_USER` and `DB_NAME`. Can be used to specify advanced connections, e.g. using mTLS connection.\n    Example of `--env-file=.env` for container:\n    ```\n        DB_USE_ENV=True\n        PGSSLMODE=verify-full\n        PGSSLROOTCERT=/path/ca.crt\n        PGSSLCERT=\u003cpath\u003e/user.crt\n        PGSSLKEY=\u003cpath\u003e/user.key\n        PGHOSTADDR=1.2.3.4\n        PGHOST=db.domain.com\n        PGUSER=myuser\n        PGDATABASE=mydb\n    ```\n* `MAIL_TO`: If `MAIL_TO` and `MAIL_FROM` is specified, an e-mail will be sent, using Amazon SES, every time a backup is taken\n* `MAIL_FROM`\n* `WEBHOOK`: If specified, an HTTP request will be sent to this URL\n* `WEBHOOK_METHOD`: By default the webhook's HTTP method is GET, but can be changed using this variable\n* `WEBHOOK_CURL_OPTIONS`: Add additional headers or other option to curl command calling the webhook. E.g. `-H 'Content-type: application/json'`\n* `WEBHOOK_DATA`: Add a body to the webhook being called, unless changed it implies that `POST` method is used. E.g. `{\"text\":\"Backup completed at %(date)s %(time)s!\"}`\n* `KEEP_BACKUP_DAYS`: The number of days to keep backups for when pruning old backups. Defaults to `7`.\n* `FILENAME`: String that is passed into `strftime()` and used as the backup dump's filename. Defaults to `$DB_NAME_%Y-%m-%d`.\n* `PG_DUMP_EXTRA_OPTIONS`: Specify additional options for `pg_dump`, e.g. `--exclude-table-data=table_name` to exclude table data from the dump.\n\n### Interpolation\n\nText in `WEBHOOK_DATA` is interpolated with variabels `%(my_var)s`\n - `date`: Date in yyyy-mm-dd format\n - `time`: Date in hh:mm:ss format\n - `duration`: Number of seconds take to backup\n - `filename`: Name of the file uploaded to S3\n - `size`: Size of the backup file with suitable suffix, like MB, GB, ...\n\n#### Example on how to post a Slack message when a backup is complete\n\n1. Configure a webhook as described in the Slack [documentation](https://api.slack.com/messaging/webhooks).\n2. Set `WEBHOOK` and `WEBHOOK_` accodringly:\n   ```\n   WEBHOOK=https://hooks.slack.com/services/.../.../...\n   WEBHOOK_METHOD=POST\n   WEBHOOK_CURL_OPTIONS=-H 'Content-type: application/json'\n   WEBHOOK_DATA={\"text\":\":white_check_mark: Backup completed at %(date)s %(time)s\\nDuration: %(duration)s seconds\\nUpload: %(filename)s: %(size)s\"}\n    ```\n\n## Volumes\n\n* `/data/backups` - The database is dumped into this directory\n\n## Restoring a backup\n\nThis image can also be run as a one off task to restore one of the backups.\nTo do this, we run the container with the command: `python -u /backup/restore.py [backup-filename]`\n(`backup-filename` should only be the name of the file, the directory is set through the `S3_PATH` env variable, if it needs to be downloaded).\n\nThe following environment variables are required:\n\n* `DB_HOST`: Postgres hostname\n* `DB_PASS`: Postgres password\n* `DB_USER`: Postgres username\n* `DB_NAME`: Name of database to import into\n\nThe following environment variables are required if the file to restore is not already in the backup volume:\n\n* `S3_PATH`: Amazon S3 directory path in the format: s3://bucket-name/some/path\n* `AWS_ACCESS_KEY_ID`\n* `AWS_SECRET_ACCESS_KEY`\n* `AWS_DEFAULT_REGION`\n\n### Other optional environment variables\n\n* `S3_EXTRA_OPTIONS`: Specify additional options for S3, e.g. `--endpoint=` for using custom S3 provider.\n* `DB_USE_ENV`: See [Optional environment variables](#optional-environment-variables) above.\n\n## Taking a one off backup\n\nTo run a one off backup job, e.g. to test that it works when setting it up for the first time, simply start\nthe container with the docker run command set to `python -u /backup/backup.py` (as well as all the required environment\nvariables set).\n\n## Docker tags\n\nThis image uses the alpine version(s) of the [official postgres](https://hub.docker.com/_/postgres) image as base\nimage.\n\nThe following docker tags are available for this image, and they are based on the corresponding official postgres\nalpine image:\n\n* `16`, `latest`\n* `15`\n* `14`\n* `13`\n* `12`\n* `11`\n* `10`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fheyman%2Fpostgresql-backup","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fheyman%2Fpostgresql-backup","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fheyman%2Fpostgresql-backup/lists"}