Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,13 @@ ENV POSTGRES_DB="**None**" \
COPY backup.sh /backup.sh
RUN chmod +x backup.sh

COPY init_script.sh /init_script.sh
RUN chmod +x init_script.sh

COPY hooks /hooks

ENTRYPOINT ["/bin/sh", "-c"]
CMD ["exec /usr/local/bin/go-cron -s \"$SCHEDULE\" -p \"$HEALTHCHECK_PORT\" -- /backup.sh"]
CMD ["./init_script.sh"]

HEALTHCHECK --interval=5m --timeout=3s \
CMD curl -f "http://localhost:$HEALTHCHECK_PORT/" || exit 1
28 changes: 14 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,20 +70,20 @@ docker run -d \
|TELEGRAM_BOT_TOKEN | Only used to call Telegram's public API |

### Environmental variables
| Name | Default value | Description |
|------------------------| :------ |------------------------------------------------|
| POSTGRES_DB | - | Database name |
| POSTGRES_HOST | - | PostgreSQL IP address or hostname |
| POSTGRES_PORT | 5432 | Connection TCP port |
| POSTGRES_USER | - | Database user |
| POSTGRES_PASSWORD | - | Database user password |
| POSTGRES_EXTRA_OPTS | --blobs | Extra options `pg_dump` run |
| SCHEDULE | @daily | `go-cron` schedule. See [this](#backup-using-go-cron) |
| HEALTHCHECK_PORT | 8080 | Port listening for cron-schedule health check. |
| S3_ACCESS_KEY_ID | - | Key or username with RW access to bucket |
| S3_SECRET_ACCESS_KEY | - | Secret or password for `S3_ACCESS_KEY_ID` |
| S3_BUCKET | - | Name of bucket created for backups |
| S3_ENDPOINT | - | URL of S3 storage |
| Name | Default value | Is mandatory | Description |
|------------------------| :------ | :------: |------------------------------------------------|
| POSTGRES_DB | - | YES | Database name |
| POSTGRES_HOST | - | YES | PostgreSQL IP address or hostname |
| POSTGRES_PORT | 5432 | - | Connection TCP port |
| POSTGRES_USER | - | YES | Database user |
| POSTGRES_PASSWORD | - | YES | Database user password |
| POSTGRES_EXTRA_OPTS | --blobs | - | Extra options `pg_dump` run |
| SCHEDULE | @daily | - | `go-cron` schedule. See [this](#backup-using-go-cron) |
| HEALTHCHECK_PORT | 8080 | - | Port listening for cron-schedule health check. |
| S3_ACCESS_KEY_ID | - | YES | Key or username with RW access to bucket |
| S3_SECRET_ACCESS_KEY | - | YES | Secret or password for `S3_ACCESS_KEY_ID` |
| S3_BUCKET | - | YES | Name of bucket created for backups |
| S3_ENDPOINT | - | YES | URL of S3 storage |

### Notification selection

Expand Down
2 changes: 1 addition & 1 deletion backup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Script made for backup PostgreSQL database from local (${POSTGRES_HOST}=127.0.0.1)
# or remote host. Created backup stores in S3 storage. On completion script calls
# notification scripts from hooks/ directory to send report to given Telegram Chat
# based on variables set private or public notification method will be selected
# based on variables set private or public notification method will be selected

set -euo pipefail
IFS=$'\n\t'
Expand Down
25 changes: 25 additions & 0 deletions init_script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env bash
#
# Script checks if mandatory variables are set and starts cron job for DB backup

set -euo pipefail
IFS=$'\n\t'


# Begin values check
if [[ ${POSTGRES_DB} == "**None**" ]] ||
[[ ${S3_ACCESS_KEY_ID} == "**None**" ]] ||
[[ ${S3_SECRET_ACCESS_KEY} == "**None**" ]] ||
[[ ${S3_BUCKET} == "**None**" ]] ||
[[ ${S3_ENDPOINT} == "**None**" ]] ||
[[ ${POSTGRES_HOST} == "**None**" ]] ||
[[ ${POSTGRES_USER} == "**None**" ]] ||
[[ ${POSTGRES_PASSWORD} == "**None**" ]] ||
[[ ${S3_ACCESS_KEY_ID} == "**None**" ]]; then
echo "One or more mandatory values is missing. Check your configuration..." >&2
exit 0
else
# Will create base backup
echo "All needed variables seems set. Starting main procedure"
exec /usr/local/bin/go-cron -s $SCHEDULE -p $HEALTHCHECK_PORT -- /backup.sh
fi