Skip to content

Commit 0ec0360

Browse files
Add support to launch backups on startup
1 parent 9160ab9 commit 0ec0360

File tree

4 files changed

+11
-0
lines changed

4 files changed

+11
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
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+
- BACKUP_ON_START=TRUE
5455
- BACKUP_KEEP_DAYS=7
5556
- BACKUP_KEEP_WEEKS=4
5657
- BACKUP_KEEP_MONTHS=6
@@ -75,6 +76,7 @@ Most variables are the same as in the [official postgres image](https://hub.dock
7576
|--|--|
7677
| BACKUP_DIR | Directory to save the backup at. Defaults to `/backups`. |
7778
| BACKUP_SUFFIX | Filename suffix to save the backup. Defaults to `.sql.gz`. |
79+
| BACKUP_ON_START | If set to `TRUE` performs an backup on each container start or restart. Defaults to `FALSE`. |
7880
| BACKUP_KEEP_DAYS | Number of daily backups to keep before removal. Defaults to `7`. |
7981
| BACKUP_KEEP_WEEKS | Number of weekly backups to keep before removal. Defaults to `4`. |
8082
| BACKUP_KEEP_MONTHS | Number of monthly backups to keep before removal. Defaults to `6`. |

alpine.Dockerfile

Lines changed: 1 addition & 0 deletions
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+
BACKUP_ON_START="FALSE" \
2425
BACKUP_DIR="/backups" \
2526
BACKUP_SUFFIX=".sql.gz" \
2627
BACKUP_LATEST_TYPE="symlink" \

debian.Dockerfile

Lines changed: 1 addition & 0 deletions
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+
BACKUP_ON_START="FALSE" \
3839
BACKUP_DIR="/backups" \
3940
BACKUP_SUFFIX=".sql.gz" \
4041
BACKUP_LATEST_TYPE="symlink" \

init.sh

Lines changed: 7 additions & 0 deletions
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 [ "${BACKUP_ON_START}" = "TRUE" ]; then
9+
echo "Launching an startup 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)