revert to bash based script since postgres image uses it
This commit is contained in:
parent
726f8b2f3a
commit
8993322d48
19
pg_backup.sh
19
pg_backup.sh
@ -1,16 +1,15 @@
|
|||||||
#!/bin/sh
|
#!/bin/bash
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
BACKUP_FILE='/var/lib/postgresql/data/backup.sql'
|
BACKUP_FILE='/var/lib/postgresql/data/backup.sql'
|
||||||
|
|
||||||
backup() {
|
function backup {
|
||||||
PGPASSWORD=$(cat "$POSTGRES_PASSWORD_FILE")
|
export PGPASSWORD=$(cat $POSTGRES_PASSWORD_FILE)
|
||||||
export PGPASSWORD
|
pg_dump -U ${POSTGRES_USER} ${POSTGRES_DB} > $BACKUP_FILE
|
||||||
pg_dump -U "${POSTGRES_USER}" "${POSTGRES_DB}" > $BACKUP_FILE
|
|
||||||
}
|
}
|
||||||
|
|
||||||
restore() {
|
function restore {
|
||||||
cd /var/lib/postgresql/data/
|
cd /var/lib/postgresql/data/
|
||||||
restore_config(){
|
restore_config(){
|
||||||
# Restore allowed connections
|
# Restore allowed connections
|
||||||
@ -24,12 +23,12 @@ restore() {
|
|||||||
trap restore_config EXIT INT TERM
|
trap restore_config EXIT INT TERM
|
||||||
|
|
||||||
# Recreate Database
|
# Recreate Database
|
||||||
psql -U "${POSTGRES_USER}" -d postgres -c "DROP DATABASE ${POSTGRES_DB} WITH (FORCE);"
|
psql -U ${POSTGRES_USER} -d postgres -c "DROP DATABASE ${POSTGRES_DB} WITH (FORCE);"
|
||||||
createdb -U "${POSTGRES_USER}" "${POSTGRES_DB}"
|
createdb -U ${POSTGRES_USER} ${POSTGRES_DB}
|
||||||
psql -U "${POSTGRES_USER}" -d "${POSTGRES_DB}" -1 -f $BACKUP_FILE
|
psql -U ${POSTGRES_USER} -d ${POSTGRES_DB} -1 -f $BACKUP_FILE
|
||||||
|
|
||||||
trap - EXIT INT TERM
|
trap - EXIT INT TERM
|
||||||
restore_config
|
restore_config
|
||||||
}
|
}
|
||||||
|
|
||||||
"$@"
|
$@
|
||||||
|
Loading…
x
Reference in New Issue
Block a user