Add support to launch backups on startup

This commit is contained in:
Pau RE
2024-09-04 11:26:45 +02:00
parent 9160ab9290
commit 0ec036071e
4 changed files with 11 additions and 0 deletions
+2
View File
@@ -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
- BACKUP_ON_START=TRUE
- BACKUP_KEEP_DAYS=7
- BACKUP_KEEP_WEEKS=4
- BACKUP_KEEP_MONTHS=6
@@ -75,6 +76,7 @@ Most variables are the same as in the [official postgres image](https://hub.dock
|--|--|
| BACKUP_DIR | Directory to save the backup at. Defaults to `/backups`. |
| BACKUP_SUFFIX | Filename suffix to save the backup. Defaults to `.sql.gz`. |
| BACKUP_ON_START | If set to `TRUE` performs an backup on each container start or restart. Defaults to `FALSE`. |
| BACKUP_KEEP_DAYS | Number of daily backups to keep before removal. Defaults to `7`. |
| BACKUP_KEEP_WEEKS | Number of weekly backups to keep before removal. Defaults to `4`. |
| BACKUP_KEEP_MONTHS | Number of monthly backups to keep before removal. Defaults to `6`. |
+1
View File
@@ -21,6 +21,7 @@ ENV POSTGRES_DB="**None**" \
POSTGRES_EXTRA_OPTS="-Z1" \
POSTGRES_CLUSTER="FALSE" \
SCHEDULE="@daily" \
BACKUP_ON_START="FALSE" \
BACKUP_DIR="/backups" \
BACKUP_SUFFIX=".sql.gz" \
BACKUP_LATEST_TYPE="symlink" \
+1
View File
@@ -35,6 +35,7 @@ ENV POSTGRES_DB="**None**" \
POSTGRES_EXTRA_OPTS="-Z1" \
POSTGRES_CLUSTER="FALSE" \
SCHEDULE="@daily" \
BACKUP_ON_START="FALSE" \
BACKUP_DIR="/backups" \
BACKUP_SUFFIX=".sql.gz" \
BACKUP_LATEST_TYPE="symlink" \
+7
View File
@@ -4,4 +4,11 @@ set -Eeo pipefail
# Prevalidate configuration (don't source)
/env.sh
# Initial background backup
if [ "${BACKUP_ON_START}" = "TRUE" ]; then
echo "Launching an startup 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