|
@@ -6,10 +6,19 @@ metadata:
|
|
|
rollme: {{ randAlphaNum 5 | quote }}
|
|
|
data:
|
|
|
entrypoint.sh: |-
|
|
|
- #!/bin/sh
|
|
|
- cmd="/docker-entrypoint.sh postgres"
|
|
|
- eval "${cmd}" & disown;
|
|
|
- until pg_isready; do
|
|
|
- sleep 5;
|
|
|
- done;
|
|
|
- pg_dump -U $POSTGRES_USER -d {{ template "postgres.DatabaseName" . }} > /postgres_backups/$BACKUP_NAME;
|
|
|
+ #!/bin/bash
|
|
|
+ echo "Fetching password from config.php"
|
|
|
+
|
|
|
+ # sed removes ' , => spaces and db* from the string
|
|
|
+ DBUSER=$(cat /nc-config/config.php | grep "dbuser" | sed "s/dbuser\| \|'\|,\|=>//g")
|
|
|
+ DBPASS=$(cat /nc-config/config.php | grep "dbpassword" | sed "s/dbpassword\| \|'\|,\|=>//g")
|
|
|
+ DBNAME=$(cat /nc-config/config.php | grep "dbname" | sed "s/dbname\| \|'\|,\|=>//g")
|
|
|
+ [ -n "$DBUSER" ] && [ -n "$DBPASS" ] && [ -n "$DBNAME" ] && echo "User, Database and password fetched from config.php"
|
|
|
+
|
|
|
+ until pg_isready -U ${POSTGRES_USER} -h ${POSTGRES_HOST}; do sleep 2; done
|
|
|
+
|
|
|
+ # pg_dump will automatically use the password from the PGPASSWORD environment variable
|
|
|
+ echo "Creating backup of ${DBNAME} database as ${DBUSER}"
|
|
|
+ PGPASSWORD=${DBPASS} pg_dump -U $DBUSER -d $DBNAME --host=${POSTGRES_HOST} > /postgres_backups/$BACKUP_NAME \
|
|
|
+ && echo "Backup created successfully" \
|
|
|
+ || echo "Backup failed"
|