|
2 | 2 | Docker image for universal postgres backups
|
3 | 3 |
|
4 | 4 | # Roadmap
|
5 |
| -- [ ] Add support for S3 |
| 5 | +- [X] Add support for S3 |
| 6 | +- [X] Add CI/CD to publish image to DockerHub |
6 | 7 | - [ ] Add retention policy settings by env vars
|
7 |
| -- [ ] Notify about backup status by HTTP-request |
| 8 | +- [X] Notify about backup status by HTTP-request |
| 9 | +- [ ] Add docker-compose example |
| 10 | + |
| 11 | +## Docker build |
| 12 | +```shell |
| 13 | +docker build . -t numdes/nd_postgres_backup:v*.*.* |
| 14 | +``` |
| 15 | + |
| 16 | +# Usage |
| 17 | +## Backup manually: |
| 18 | +```shell |
| 19 | +docker run --rm -it \ |
| 20 | + -e POSTGRES_HOST="FQDN-OR-IP" \ |
| 21 | + -e POSTGRES_DB="DB-NAME" \ |
| 22 | + -e POSTGRES_USER="DB-USER" \ |
| 23 | + -e POSTGRES_PASSWORD="PASS" \ |
| 24 | + -e S3_ENDPOINT=http://YOUR-S3 \ |
| 25 | + -e S3_ACCESS_KEY_ID="KEY-ID" \ |
| 26 | + -e S3_SECRET_ACCESS_KEY="KEY-SECRET" \ |
| 27 | + -e S3_BUCKET="BUCKET-NAME" \ |
| 28 | + -e PRIVATE_NOTIFICATION_URL=http://webhook \ |
| 29 | + -e TELEGRAM_CHAT_ID=point_to_notify_group \ |
| 30 | + -e POSTGRES_PORT=if_not_5432 \ |
| 31 | + --entrypoint /bin/bash \ |
| 32 | + numdes/nd_postgres_backup:v*.*.* |
| 33 | +``` |
| 34 | +To run backup, in active container shell call `backup.sh` script |
| 35 | +```shell |
| 36 | +./backup.sh |
| 37 | +``` |
| 38 | + |
| 39 | +## Backup using `go-cron` |
| 40 | +```shell |
| 41 | +docker run -d \ |
| 42 | + -e POSTGRES_HOST="FQDN-OR-IP" \ |
| 43 | + -e POSTGRES_DB="DB-NAME" \ |
| 44 | + -e POSTGRES_USER="DB-USER" \ |
| 45 | + -e POSTGRES_PASSWORD="PASS" \ |
| 46 | + -e S3_ENDPOINT=http://YOUR-S3 \ |
| 47 | + -e S3_ACCESS_KEY_ID="KEY-ID" \ |
| 48 | + -e S3_SECRET_ACCESS_KEY="KEY-SECRET" \ |
| 49 | + -e S3_BUCKET="BUCKET-NAME" \ |
| 50 | + -e PRIVATE_NOTIFICATION_URL=http://webhook \ |
| 51 | + -e TELEGRAM_CHAT_ID=point_to_notify_group \ |
| 52 | + -e POSTGRES_PORT=if_not_5432 \ |
| 53 | + -e SCHEDULE=Chosen_schedule |
| 54 | + numdes/nd_postgres_backup:v*.*.* |
| 55 | +``` |
| 56 | +:wave: By default `SCHEDULE` variable is set to `@daily` in case if you need other scheduling options, please refer to `go-cron` *[Documentation](https://pkg.go.dev/github.com/robfig/cron?utm_source=godoc#hdr-Predefined_schedules)*. |
| 57 | + |
| 58 | +## Variables |
| 59 | +### `Gitlab Actions` *[variables](https://docs.github.com/en/actions/security-guides/encrypted-secrets#creating-encrypted-secrets-for-a-repository)*: |
| 60 | +| Name | Description | |
| 61 | +|-------------------|-----------------------------------------------------| |
| 62 | +|DOCKERHUB_LOGIN | `Actions` Repository secret | |
| 63 | +|DOCKERHUB_PASSWORD | `Actions` Repository secret | |
| 64 | + |
| 65 | +### Notification environmental variables |
| 66 | +| Name | Description | |
| 67 | +|---------------------------|-----------------------------------------------------| |
| 68 | +|TELEGRAM_CHAT_ID | Notifying group | |
| 69 | +|PRIVATE_NOTIFICATION_URL | Private notifier URL | |
| 70 | +|TELEGRAM_BOT_TOKEN | Only used to call Telegram's public API | |
| 71 | + |
| 72 | +### Environmental variables |
| 73 | +| Name | Default value | Description | |
| 74 | +|------------------------| :------ |------------------------------------------------| |
| 75 | +| POSTGRES_DB | - | Database name | |
| 76 | +| POSTGRES_HOST | - | PostgreSQL IP address or hostname | |
| 77 | +| POSTGRES_PORT | 5432 | Connection TCP port | |
| 78 | +| POSTGRES_USER | - | Database user | |
| 79 | +| POSTGRES_PASSWORD | - | Database user password | |
| 80 | +| POSTGRES_EXTRA_OPTS | --blobs | Extra options `pg_dump` run | |
| 81 | +| SCHEDULE | @daily | `go-cron` schedule. See [this](#backup-using-go-cron) | |
| 82 | +| HEALTHCHECK_PORT | 8080 | Port listening for cron-schedule health check. | |
| 83 | +| S3_ACCESS_KEY_ID | - | Key or username with RW access to bucket | |
| 84 | +| S3_SECRET_ACCESS_KEY | - | Secret or password for `S3_ACCESS_KEY_ID` | |
| 85 | +| S3_BUCKET | - | Name of bucket created for backups | |
| 86 | +| S3_ENDPOINT | - | URL of S3 storage | |
| 87 | + |
| 88 | +### Notification selection |
| 89 | + |
| 90 | +It is possible to use either private Telegram bot if you have it or Telegram public API. |
| 91 | + |
| 92 | +In scenario with private bot `PRIVATE_NOTIFICATION_URL` must be set alongside with `TELEGRAM_CHAT_ID`. |
| 93 | + |
| 94 | +In scenario with Telegram's public API `TELEGRAM_BOT_TOKEN` must be set as it is received (`Use this token to access the HTTP API:`) from `@BotFather` Telegram Bot. Variable `TELEGRAM_CHAT_ID` must be a proper Telegram ID of bot |
| 95 | + |
| 96 | +In `docker ...` command need to replace: |
| 97 | +``` |
| 98 | + -e PRIVATE_NOTIFICATION_URL=http://webhook \ |
| 99 | + -e TELEGRAM_CHAT_ID=point_to_notify_group \ |
| 100 | +``` |
| 101 | +to |
| 102 | +``` |
| 103 | + -e TELEGRAM_BOT_TOKEN='XXXXXXX:XXXXxxxxXXXXxxx' \ |
| 104 | + -e TELEGRAM_CHAT_ID=000000000 \ |
| 105 | +``` |
| 106 | +- If `TELEGRAM_CHAT_ID` has a proper format (Only digits not less than 5 not more than 32) and `TELEGRAM_BOT_TOKEN` is set, script will try to send notification through Telegram's public API. |
0 commit comments