Skip to content

Commit 5bea3ca

Browse files
Add support to launch initial backups on startup
1 parent 2eacc34 commit 5bea3ca

File tree

4 files changed

+11
-0
lines changed

4 files changed

+11
-0
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ services:
5151
# - POSTGRES_PASSWORD_FILE=/run/secrets/db_password <-- alternative for POSTGRES_PASSWORD (to use with docker secrets)
5252
- POSTGRES_EXTRA_OPTS=-Z1 --schema=public --blobs
5353
- SCHEDULE=@daily
54+
- INITIAL_BACKUP=TRUE
5455
- BACKUP_KEEP_DAYS=7
5556
- BACKUP_KEEP_WEEKS=4
5657
- BACKUP_KEEP_MONTHS=6
@@ -93,6 +94,7 @@ Most variables are the same as in the [official postgres image](https://hub.dock
9394
| POSTGRES_USER | Postgres connection parameter; postgres user to connect with. Required. |
9495
| POSTGRES_USER_FILE | Alternative to POSTGRES_USER, for usage with docker secrets. |
9596
| SCHEDULE | [Cron-schedule](http://godoc.org/github.com/robfig/cron#hdr-Predefined_schedules) specifying the interval between postgres backups. Defaults to `@daily`. |
97+
| INITIAL_BACKUP | If set to `TRUE` performs an initial backup. Defaults to `FALSE`. |
9698
| 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"). |
9799
| 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. |
98100
| WEBHOOK_ERROR_URL | URL to be called in case backup fails. Default disabled. |

alpine.Dockerfile

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ ENV POSTGRES_DB="**None**" \
2121
POSTGRES_EXTRA_OPTS="-Z1" \
2222
POSTGRES_CLUSTER="FALSE" \
2323
SCHEDULE="@daily" \
24+
INITIAL_BACKUP="FALSE" \
2425
BACKUP_DIR="/backups" \
2526
BACKUP_SUFFIX=".sql.gz" \
2627
BACKUP_LATEST_TYPE="symlink" \

debian.Dockerfile

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ ENV POSTGRES_DB="**None**" \
3535
POSTGRES_EXTRA_OPTS="-Z1" \
3636
POSTGRES_CLUSTER="FALSE" \
3737
SCHEDULE="@daily" \
38+
INITIAL_BACKUP="FALSE" \
3839
BACKUP_DIR="/backups" \
3940
BACKUP_SUFFIX=".sql.gz" \
4041
BACKUP_LATEST_TYPE="symlink" \

init.sh

+7
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,11 @@ set -Eeo pipefail
44
# Prevalidate configuration (don't source)
55
/env.sh
66

7+
# Initial background backup
8+
if [ "${INITIAL_BACKUP}" = "TRUE" ]; then
9+
echo "Launching an initial backup as a background job..."
10+
/backup.sh &
11+
fi
12+
13+
echo "Starting go-cron ($SCHEDULE)..."
714
exec /usr/local/bin/go-cron -s "$SCHEDULE" -p "$HEALTHCHECK_PORT" -- /backup.sh

0 commit comments

Comments
 (0)