Last active
August 29, 2015 14:22
-
-
Save bradbergeron-us/5d508396d58b2ac442b3 to your computer and use it in GitHub Desktop.
Use for importing a database -> Add to init shell script then drop into ***/docker-entrypoint-initdb.d *** Start Postgres import via "pg_restore" then "stop database"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
: ${DB_USER:=db_user} | |
: ${DB_PASSWORD:=db_pass} | |
: ${DB_NAME:=db_name} | |
: ${DB_ENCODING:=UTF-8} | |
: ${DB_PG_DUMP_FILE:=/tmp/db.pgdump} | |
{ gosu postgres postgres --single -jE <<-EOSQL | |
CREATE USER "$DB_USER" WITH PASSWORD '$DB_PASSWORD'; | |
EOSQL | |
} && { gosu postgres postgres --single -jE <<-EOSQL | |
CREATE DATABASE "$DB_NAME" WITH OWNER="$DB_USER" TEMPLATE=template0 ENCODING='$DB_ENCODING'; | |
EOSQL | |
} && { gosu postgres pg_ctl start -w && gosu postgres pg_restore -d "$DB_NAME" "$DB_PG_DUMP_FILE" && gosu postgres pg_ctl stop -w | |
} && /bin/rm -f ${DB_PG_DUMP_FILE} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment