]> git.parisson.com Git - docker-django-scripts.git/commitdiff
Allow specifying the dump to load (defaults to latest), and killing clients before...
authorRaphaël Voyazopoulos <raphael.voyazopoulos@ircam.fr>
Thu, 14 Feb 2019 11:35:16 +0000 (12:35 +0100)
committerRaphaël Voyazopoulos <raphael.voyazopoulos@ircam.fr>
Thu, 14 Feb 2019 11:35:16 +0000 (12:35 +0100)
dev/local/restore_db.sh

index 89fbd139ddbde2ae5bf7b7c870adea905fc7b946..330b93b9b48a3ece09b31394ace4135713477620 100755 (executable)
@@ -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!"