Skip to content

Commit

Permalink
Add support to launch initial backups on startup
Browse files Browse the repository at this point in the history
  • Loading branch information
prodrigestivill committed Sep 4, 2024
1 parent 2eacc34 commit 5bea3ca
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ services:
# - POSTGRES_PASSWORD_FILE=/run/secrets/db_password <-- alternative for POSTGRES_PASSWORD (to use with docker secrets)
- POSTGRES_EXTRA_OPTS=-Z1 --schema=public --blobs
- SCHEDULE=@daily
- INITIAL_BACKUP=TRUE
- BACKUP_KEEP_DAYS=7
- BACKUP_KEEP_WEEKS=4
- BACKUP_KEEP_MONTHS=6
Expand Down Expand Up @@ -93,6 +94,7 @@ Most variables are the same as in the [official postgres image](https://hub.dock
| POSTGRES_USER | Postgres connection parameter; postgres user to connect with. Required. |
| POSTGRES_USER_FILE | Alternative to POSTGRES_USER, for usage with docker secrets. |
| SCHEDULE | [Cron-schedule](http://godoc.org/github.com/robfig/cron#hdr-Predefined_schedules) specifying the interval between postgres backups. Defaults to `@daily`. |
| INITIAL_BACKUP | If set to `TRUE` performs an initial backup. Defaults to `FALSE`. |
| TZ | [POSIX TZ variable](https://www.gnu.org/software/libc/manual/html_node/TZ-Variable.html) specifying the timezone used to evaluate SCHEDULE cron (example "Europe/Paris"). |
| WEBHOOK_URL | URL to be called after an error or after a successful backup (POST with a JSON payload, check `hooks/00-webhook` file for more info). Default disabled. |
| WEBHOOK_ERROR_URL | URL to be called in case backup fails. Default disabled. |
Expand Down
1 change: 1 addition & 0 deletions alpine.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ ENV POSTGRES_DB="**None**" \
POSTGRES_EXTRA_OPTS="-Z1" \
POSTGRES_CLUSTER="FALSE" \
SCHEDULE="@daily" \
INITIAL_BACKUP="FALSE" \
BACKUP_DIR="/backups" \
BACKUP_SUFFIX=".sql.gz" \
BACKUP_LATEST_TYPE="symlink" \
Expand Down
1 change: 1 addition & 0 deletions debian.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ ENV POSTGRES_DB="**None**" \
POSTGRES_EXTRA_OPTS="-Z1" \
POSTGRES_CLUSTER="FALSE" \
SCHEDULE="@daily" \
INITIAL_BACKUP="FALSE" \
BACKUP_DIR="/backups" \
BACKUP_SUFFIX=".sql.gz" \
BACKUP_LATEST_TYPE="symlink" \
Expand Down
7 changes: 7 additions & 0 deletions init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,11 @@ set -Eeo pipefail
# Prevalidate configuration (don't source)
/env.sh

# Initial background backup
if [ "${INITIAL_BACKUP}" = "TRUE" ]; then
echo "Launching an initial backup as a background job..."
/backup.sh &
fi

echo "Starting go-cron ($SCHEDULE)..."
exec /usr/local/bin/go-cron -s "$SCHEDULE" -p "$HEALTHCHECK_PORT" -- /backup.sh

0 comments on commit 5bea3ca

Please sign in to comment.