update pg_backup.sh

This commit is contained in:
Moritz 2024-10-22 21:31:41 +02:00
parent 182a42ff1f
commit ee2c5a2b42
2 changed files with 11 additions and 4 deletions

View File

@ -5,7 +5,7 @@ export NGINX_CONF_VERSION=v7
export MY_CNF_VERSION=v5
export ENTRYPOINT_VERSION=v3
export CRONTAB_VERSION=v1
export PG_BACKUP_VERSION=v1
export PG_BACKUP_VERSION=v2
run_occ() {
su -p www-data -s /bin/sh -c "/var/www/html/occ $@"

View File

@ -11,17 +11,24 @@ function backup {
function restore {
cd /var/lib/postgresql/data/
restore_config(){
# Restore allowed connections
cat pg_hba.conf.bak > pg_hba.conf
su postgres -c 'pg_ctl reload'
}
# Don't allow any other connections than local
cp pg_hba.conf pg_hba.conf.bak
echo "local all all trust" > pg_hba.conf
su postgres -c 'pg_ctl reload'
trap restore_config EXIT INT TERM
# Recreate Database
psql -U ${POSTGRES_USER} -d postgres -c "DROP DATABASE ${POSTGRES_DB} WITH (FORCE);"
createdb -U ${POSTGRES_USER} ${POSTGRES_DB}
psql -U ${POSTGRES_USER} -d ${POSTGRES_DB} -1 -f $BACKUP_FILE
# Restore allowed connections
cat pg_hba.conf.bak > pg_hba.conf
su postgres -c 'pg_ctl reload'
trap - EXIT INT TERM
restore_config
}
$@