From 413c86d908169dcf2f0f27c4c14caa5d3e12592d Mon Sep 17 00:00:00 2001 From: Christopher Usher Date: Thu, 19 Sep 2019 23:48:46 +0100 Subject: [PATCH] script to read in dumps --- postgres/db_restore | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 postgres/db_restore diff --git a/postgres/db_restore b/postgres/db_restore new file mode 100644 index 0000000..d42763c --- /dev/null +++ b/postgres/db_restore @@ -0,0 +1,25 @@ +#! /bin/bash + +if [ -z $1 ] + then + echo "No SQL script file" + exit 1 +fi + +NAME=${2:-postgres} +CONTAINER=$(docker ps --format "{{.Names}}" | grep "$NAME") +if [ -z "$CONTAINER" ] + then + echo "Container not found" + exit 1 +fi + +#need to do this in case db dump file has a colon in it +cp $1 tmp.sql +docker cp tmp.sql "$CONTAINER:/" +rm tmp.sql + +docker exec $CONTAINER dropdb wubloader -U postgres +docker exec $CONTAINER createdb wubloader -U postgres +docker exec $CONTAINER psql -d wubloader -f dump.sql -U postgres +docker exec $CONTAINER rm tmp.sql