- scripts/entrypoint.sh (new): prefers the live bind-mounted backup-cron.sh, but falls back to a copy baked into the image at build time if the mount is missing. If neither exists, it stays up and idle (instead of crash-looping) so the container remains reachable via console/exec for diagnosis. - scripts/backup-cron.sh (updated): resolves db-backup.sh the same live-or-fallback way, re-checked on every loop iteration, so if the bind mount comes back healthy later, this container picks up the live scripts on its next backup run with no restart needed. - scripts/backup.Dockerfile (updated): bakes all three scripts into the image under /app/scripts-default/ as the fallback, and sets the new wrapper as ENTRYPOINT.
36 lines
1.3 KiB
Bash
36 lines
1.3 KiB
Bash
#!/bin/sh
|
|
# Entry point for the `backup` sidecar container's periodic loop. Runs
|
|
# db-backup.sh on a fixed interval (default: daily) -- a sleep loop instead of
|
|
# a cron daemon, kept deliberately simple so it works in a bare
|
|
# postgres:16-alpine image.
|
|
#
|
|
# Resolves db-backup.sh the same way entrypoint.sh resolves this file: prefer
|
|
# the live bind-mounted copy at /scripts (so edits don't need a rebuild), fall
|
|
# back to the copy baked into the image at build time if the mount is
|
|
# missing, empty, or stale. Resolving fresh on every loop iteration also means
|
|
# that if the mount comes back healthy later (e.g. someone fixes the host
|
|
# directory) this container picks it up on the very next run, with no
|
|
# restart needed.
|
|
set -eu
|
|
|
|
resolve() {
|
|
# $1 = script filename, e.g. db-backup.sh
|
|
if [ -f "/scripts/$1" ]; then
|
|
echo "/scripts/$1"
|
|
else
|
|
echo "/app/scripts-default/$1"
|
|
fi
|
|
}
|
|
|
|
INTERVAL="${BACKUP_INTERVAL_SECONDS:-86400}" # 86400 = once a day
|
|
echo "[backup] sidecar started; interval=${INTERVAL}s, keep=${BACKUP_KEEP:-14}, dir=${BACKUP_DIR:-/backups}"
|
|
|
|
# Take one backup shortly after start so a freshly-deployed stack has an
|
|
# immediate restore point instead of waiting a whole interval.
|
|
sleep 20
|
|
while true; do
|
|
DB_BACKUP="$(resolve db-backup.sh)"
|
|
sh "$DB_BACKUP" || echo "[backup] run failed; will retry next interval" >&2
|
|
sleep "$INTERVAL"
|
|
done
|