-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #158 from prodrigestivill/initial-backup
Add support to perform an initial backup on startup
- Loading branch information
Showing
8 changed files
with
95 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#!/usr/bin/env bash | ||
# Pre-validate the environment | ||
if [ "${POSTGRES_DB}" = "**None**" -a "${POSTGRES_DB_FILE}" = "**None**" ]; then | ||
echo "You need to set the POSTGRES_DB or POSTGRES_DB_FILE environment variable." | ||
exit 1 | ||
fi | ||
|
||
if [ "${POSTGRES_HOST}" = "**None**" ]; then | ||
if [ -n "${POSTGRES_PORT_5432_TCP_ADDR}" ]; then | ||
POSTGRES_HOST=${POSTGRES_PORT_5432_TCP_ADDR} | ||
POSTGRES_PORT=${POSTGRES_PORT_5432_TCP_PORT} | ||
else | ||
echo "You need to set the POSTGRES_HOST environment variable." | ||
exit 1 | ||
fi | ||
fi | ||
|
||
if [ "${POSTGRES_USER}" = "**None**" -a "${POSTGRES_USER_FILE}" = "**None**" ]; then | ||
echo "You need to set the POSTGRES_USER or POSTGRES_USER_FILE environment variable." | ||
exit 1 | ||
fi | ||
|
||
if [ "${POSTGRES_PASSWORD}" = "**None**" -a "${POSTGRES_PASSWORD_FILE}" = "**None**" -a "${POSTGRES_PASSFILE_STORE}" = "**None**" ]; then | ||
echo "You need to set the POSTGRES_PASSWORD or POSTGRES_PASSWORD_FILE or POSTGRES_PASSFILE_STORE environment variable or link to a container named POSTGRES." | ||
exit 1 | ||
fi | ||
|
||
#Process vars | ||
if [ "${POSTGRES_DB_FILE}" = "**None**" ]; then | ||
POSTGRES_DBS=$(echo "${POSTGRES_DB}" | tr , " ") | ||
elif [ -r "${POSTGRES_DB_FILE}" ]; then | ||
POSTGRES_DBS=$(cat "${POSTGRES_DB_FILE}") | ||
else | ||
echo "Missing POSTGRES_DB_FILE file." | ||
exit 1 | ||
fi | ||
if [ "${POSTGRES_USER_FILE}" = "**None**" ]; then | ||
export PGUSER="${POSTGRES_USER}" | ||
elif [ -r "${POSTGRES_USER_FILE}" ]; then | ||
export PGUSER=$(cat "${POSTGRES_USER_FILE}") | ||
else | ||
echo "Missing POSTGRES_USER_FILE file." | ||
exit 1 | ||
fi | ||
if [ "${POSTGRES_PASSWORD_FILE}" = "**None**" -a "${POSTGRES_PASSFILE_STORE}" = "**None**" ]; then | ||
export PGPASSWORD="${POSTGRES_PASSWORD}" | ||
elif [ -r "${POSTGRES_PASSWORD_FILE}" ]; then | ||
export PGPASSWORD=$(cat "${POSTGRES_PASSWORD_FILE}") | ||
elif [ -r "${POSTGRES_PASSFILE_STORE}" ]; then | ||
export PGPASSFILE="${POSTGRES_PASSFILE_STORE}" | ||
else | ||
echo "Missing POSTGRES_PASSWORD_FILE or POSTGRES_PASSFILE_STORE file." | ||
exit 1 | ||
fi | ||
export PGHOST="${POSTGRES_HOST}" | ||
export PGPORT="${POSTGRES_PORT}" | ||
KEEP_MINS=${BACKUP_KEEP_MINS} | ||
KEEP_DAYS=${BACKUP_KEEP_DAYS} | ||
KEEP_WEEKS=`expr $(((${BACKUP_KEEP_WEEKS} * 7) + 1))` | ||
KEEP_MONTHS=`expr $(((${BACKUP_KEEP_MONTHS} * 31) + 1))` | ||
|
||
# Validate backup dir | ||
if [ '!' -d "${BACKUP_DIR}" -o '!' -w "${BACKUP_DIR}" -o '!' -x "${BACKUP_DIR}" ]; then | ||
echo "BACKUP_DIR points to a file or folder with insufficient permissions." | ||
exit 1 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/usr/bin/env bash | ||
set -Eeo pipefail | ||
|
||
# Prevalidate configuration (don't source) | ||
/env.sh | ||
|
||
EXTRA_ARGS="" | ||
# Initial background backup | ||
if [ "${BACKUP_ON_START}" = "TRUE" ]; then | ||
EXTRA_ARGS="-i" | ||
fi | ||
|
||
exec /usr/local/bin/go-cron -s "$SCHEDULE" -p "$HEALTHCHECK_PORT" $EXTRA_ARGS -- /backup.sh |