From: Raphaƫl Voyazopoulos Date: Thu, 14 Feb 2019 11:35:16 +0000 (+0100) Subject: Allow specifying the dump to load (defaults to latest), and killing clients before... X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=12aecb5ba3881adb6095e8e015a84b0825da3f4b;p=docker-django-scripts.git Allow specifying the dump to load (defaults to latest), and killing clients before restoring --- diff --git a/dev/local/restore_db.sh b/dev/local/restore_db.sh index 89fbd13..330b93b 100755 --- a/dev/local/restore_db.sh +++ b/dev/local/restore_db.sh @@ -11,9 +11,14 @@ if [ ! -z "$MYSQL_ROOT_PASSWORD" ]; then gunzip < /srv/backup/mariadb.dump.gz | mysql -h db $MYSQL_DATABASE -uroot -p$MYSQL_ROOT_PASSWORD elif [ ! -z "$POSTGRES_PASSWORD" ]; then export PGPASSWORD=$POSTGRES_PASSWORD + echo "Killing clients..." + psql -hdb -Upostgres -dpostgres -c "SELECT pid, (SELECT pg_terminate_backend(pid)) as killed from pg_stat_activity WHERE state LIKE 'idle';" + echo "Dropping db..." dropdb -hdb -Upostgres postgres + echo "Creating new db..." createdb -hdb -Upostgres -T template0 postgres - pg_restore -C -c -hdb -Upostgres -dpostgres /srv/backup/postgres_latest.dump + echo "Importing dump..." + pg_restore -C -c -hdb -Upostgres -dpostgres /srv/backup/${1:-postgres_latest.dump} fi echo "Restore done!"