From 12aecb5ba3881adb6095e8e015a84b0825da3f4b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rapha=C3=ABl=20Voyazopoulos?= Date: Thu, 14 Feb 2019 12:35:16 +0100 Subject: [PATCH] Allow specifying the dump to load (defaults to latest), and killing clients before restoring --- dev/local/restore_db.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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!" -- 2.39.5