Merge pull request #16 from dargmuesli/secret_files

Add _FILE Support For User And Databases
This commit is contained in:
PauRE
2019-03-25 13:48:01 +01:00
committed by GitHub
2 changed files with 25 additions and 7 deletions
+3 -1
View File
@@ -57,12 +57,14 @@ 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`. |
| 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_FILE | Alternative to POSTGRES_DB, for usage with docker secrets. |
| POSTGRES_EXTRA_OPTS | Additional options for `pg_dump`. Defaults to `-Z9`. |
| POSTGRES_HOST | Postgres connection parameter; postgres host to connect to. Required. |
| POSTGRES_PASSWORD | Postgres connection parameter; postgres password to connect with. Required. |
| POSTGRES_PASSWORD_FILE | Alternative to POSTGRES_PASSWORD, useful with docker secrets. |
| POSTGRES_PASSWORD_FILE | Alternative to POSTGRES_PASSWORD, for usage with docker secrets. |
| POSTGRES_PORT | Postgres connection parameter; postgres port to connect to. Defaults to `5432`. |
| POSTGRES_USER | Postgres connection parameter; postgres user to connect with. Required. |
| POSTGRES_USER_FILE | Alternative to POSTGRES_USER, for usage with docker secrets. |
| SCHEDULE | [Cron-schedule](http://godoc.org/github.com/robfig/cron#hdr-Predefined_schedules) specifying the interval between postgres backups. Defaults to `@daily`. |
### Manual Backups
+22 -6
View File
@@ -2,8 +2,8 @@
set -e
if [ "${POSTGRES_DB}" = "**None**" ]; then
echo "You need to set the POSTGRES_DB environment variable."
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
@@ -17,17 +17,25 @@ if [ "${POSTGRES_HOST}" = "**None**" ]; then
fi
fi
if [ "${POSTGRES_USER}" = "**None**" ]; then
echo "You need to set the POSTGRES_USER environment variable."
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**" ]; then
echo "You need to set the POSTGRES_PASSWORD environment variable or link to a container named POSTGRES."
echo "You need to set the POSTGRES_PASSWORD or POSTGRES_PASSWORD_FILE environment variable or link to a container named POSTGRES."
exit 1
fi
#Proces vars
#Process vars
if [ "${POSTGRES_DB_FILE}" = "**None**" ]; then
export POSTGRES_DB=$POSTGRES_DB
elif [ -r "${POSTGRES_DB_FILE}" ]; then
export POSTGRES_DB=$(cat ${POSTGRES_DB_FILE})
else
echo "Missing POSTGRES_DB_FILE file."
exit 1
fi
if [ "${POSTGRES_PASSWORD_FILE}" = "**None**" ]; then
export PGPASSWORD=$POSTGRES_PASSWORD
elif [ -r "${POSTGRES_PASSWORD_FILE}" ]; then
@@ -36,6 +44,14 @@ else
echo "Missing POSTGRES_PASSWORD_FILE file."
exit 1
fi
if [ "${POSTGRES_USER_FILE}" = "**None**" ]; then
export POSTGRES_USER=$POSTGRES_USER
elif [ -r "${POSTGRES_USER_FILE}" ]; then
export POSTGRES_USER=$(cat ${POSTGRES_USER_FILE})
else
echo "Missing POSTGRES_USER_FILE file."
exit 1
fi
POSTGRES_HOST_OPTS="-h $POSTGRES_HOST -p $POSTGRES_PORT -U $POSTGRES_USER $POSTGRES_EXTRA_OPTS"
KEEP_DAYS=$BACKUP_KEEP_DAYS
KEEP_WEEKS=`expr $((($BACKUP_KEEP_WEEKS * 7) + 1))`