Fix #17 issue handling _FILE env vars

This commit is contained in:
Pau Rodriguez-Estivill
2019-03-26 16:02:34 +01:00
parent 681e358069
commit 09dfc24fa6
2 changed files with 10 additions and 8 deletions
+1 -1
View File
@@ -57,7 +57,7 @@ Most variables are the same as in the [official postgres image](https://hub.dock
| BACKUP_KEEP_MONTHS | Number of monthly backups to keep before removal. Defaults to `6`. | | BACKUP_KEEP_MONTHS | Number of monthly backups to keep before removal. Defaults to `6`. |
| HEALTHCHECK_PORT | Port listening for cron-schedule health check. Defaults to `8080`. | | HEALTHCHECK_PORT | Port listening for cron-schedule health check. Defaults to `8080`. |
| POSTGRES_DB | Comma or space separated list of postgres databases to backup. Required. | | POSTGRES_DB | Comma or space separated list of postgres databases to backup. Required. |
| POSTGRES_DB_FILE | Alternative to POSTGRES_DB, for usage with docker secrets. | | POSTGRES_DB_FILE | Alternative to POSTGRES_DB, but with one database per line, for usage with docker secrets. |
| POSTGRES_EXTRA_OPTS | Additional options for `pg_dump`. Defaults to `-Z9`. | | POSTGRES_EXTRA_OPTS | Additional options for `pg_dump`. Defaults to `-Z9`. |
| POSTGRES_HOST | Postgres connection parameter; postgres host to connect to. Required. | | POSTGRES_HOST | Postgres connection parameter; postgres host to connect to. Required. |
| POSTGRES_PASSWORD | Postgres connection parameter; postgres password to connect with. Required. | | POSTGRES_PASSWORD | Postgres connection parameter; postgres password to connect with. Required. |
+9 -7
View File
@@ -28,24 +28,26 @@ if [ "${POSTGRES_PASSWORD}" = "**None**" -a "${POSTGRES_PASSWORD_FILE}" = "**Non
fi fi
#Process vars #Process vars
if [ "${POSTGRES_DB}" = "**None**" -a -r "${POSTGRES_DB_FILE}" ]; then if [ "${POSTGRES_DB_FILE}" = "**None**" ]; then
POSTGRES_DB=$(cat ${POSTGRES_DB_FILE}) POSTGRES_DBS=$(echo "${POSTGRES_DB}" | tr , " ")
elif [ -r "${POSTGRES_DB_FILE}" ]; then
POSTGRES_DBS=$(cat "${POSTGRES_DB_FILE}")
else else
echo "Missing POSTGRES_DB_FILE file." echo "Missing POSTGRES_DB_FILE file."
exit 1 exit 1
fi fi
if [ "${POSTGRES_USER_FILE}" = "**None**" ]; then if [ "${POSTGRES_USER_FILE}" = "**None**" ]; then
export PGUSER=$POSTGRES_USER export PGUSER="$POSTGRES_USER"
elif [ -r "${POSTGRES_USER_FILE}" ]; then elif [ -r "${POSTGRES_USER_FILE}" ]; then
export PGUSER=$(cat ${POSTGRES_USER_FILE}) export PGUSER=$(cat "${POSTGRES_USER_FILE}")
else else
echo "Missing POSTGRES_USER_FILE file." echo "Missing POSTGRES_USER_FILE file."
exit 1 exit 1
fi fi
if [ "${POSTGRES_PASSWORD_FILE}" = "**None**" ]; then if [ "${POSTGRES_PASSWORD_FILE}" = "**None**" ]; then
export PGPASSWORD=$POSTGRES_PASSWORD export PGPASSWORD="$POSTGRES_PASSWORD"
elif [ -r "${POSTGRES_PASSWORD_FILE}" ]; then elif [ -r "${POSTGRES_PASSWORD_FILE}" ]; then
export PGPASSWORD=$(cat ${POSTGRES_PASSWORD_FILE}) export PGPASSWORD=$(cat "${POSTGRES_PASSWORD_FILE}")
else else
echo "Missing POSTGRES_PASSWORD_FILE file." echo "Missing POSTGRES_PASSWORD_FILE file."
exit 1 exit 1
@@ -59,7 +61,7 @@ KEEP_MONTHS=`expr $((($BACKUP_KEEP_MONTHS * 31) + 1))`
mkdir -p "$BACKUP_DIR/daily/" "$BACKUP_DIR/weekly/" "$BACKUP_DIR/monthly/" mkdir -p "$BACKUP_DIR/daily/" "$BACKUP_DIR/weekly/" "$BACKUP_DIR/monthly/"
#Loop all databases #Loop all databases
for DB in $(echo $POSTGRES_DB | tr , " "); do for DB in $POSTGRES_DBS; do
#Initialize filename vers #Initialize filename vers
DFILE="$BACKUP_DIR/daily/$DB-`date +%Y%m%d-%H%M%S`.sql.gz" DFILE="$BACKUP_DIR/daily/$DB-`date +%Y%m%d-%H%M%S`.sql.gz"
WFILE="$BACKUP_DIR/weekly/$DB-`date +%G%V`.sql.gz" WFILE="$BACKUP_DIR/weekly/$DB-`date +%G%V`.sql.gz"