annotate trainingdb/setupDatabase.sh @ 48:809ba4a960bc

reduce memory options for training app instances
author smith@nwoca.org
date Thu, 04 Feb 2016 22:43:12 +0000
parents a5175713518c
children
rev   line source
36
a5175713518c add training db images
smith@nwoca.org
parents:
diff changeset
1 #!/bin/bash
a5175713518c add training db images
smith@nwoca.org
parents:
diff changeset
2
a5175713518c add training db images
smith@nwoca.org
parents:
diff changeset
3 export PGUSER=postgres
a5175713518c add training db images
smith@nwoca.org
parents:
diff changeset
4 TEST=`psql <<- EOSQL
a5175713518c add training db images
smith@nwoca.org
parents:
diff changeset
5 SELECT 1 FROM pg_database WHERE datname='$DB_NAME';
a5175713518c add training db images
smith@nwoca.org
parents:
diff changeset
6 EOSQL`
a5175713518c add training db images
smith@nwoca.org
parents:
diff changeset
7
a5175713518c add training db images
smith@nwoca.org
parents:
diff changeset
8 if [[ $TEST == "1" ]]; then
a5175713518c add training db images
smith@nwoca.org
parents:
diff changeset
9 echo "$DB_NAME exists. continuing startup."
a5175713518c add training db images
smith@nwoca.org
parents:
diff changeset
10 # database exists
a5175713518c add training db images
smith@nwoca.org
parents:
diff changeset
11 # $? is 0
a5175713518c add training db images
smith@nwoca.org
parents:
diff changeset
12 exit 0
a5175713518c add training db images
smith@nwoca.org
parents:
diff changeset
13 else
a5175713518c add training db images
smith@nwoca.org
parents:
diff changeset
14 echo "Creating $DB_NAME for $DB_USER"
a5175713518c add training db images
smith@nwoca.org
parents:
diff changeset
15 psql <<- EOSQL
a5175713518c add training db images
smith@nwoca.org
parents:
diff changeset
16 CREATE ROLE $DB_USER WITH LOGIN ENCRYPTED PASSWORD '${DB_PASS}' CREATEDB;
a5175713518c add training db images
smith@nwoca.org
parents:
diff changeset
17 CREATE DATABASE $DB_NAME WITH OWNER $DB_USER TEMPLATE template0 ENCODING 'UTF8';
a5175713518c add training db images
smith@nwoca.org
parents:
diff changeset
18 GRANT ALL PRIVILEGES ON DATABASE $DB_NAME TO $DB_USER;
a5175713518c add training db images
smith@nwoca.org
parents:
diff changeset
19 EOSQL
a5175713518c add training db images
smith@nwoca.org
parents:
diff changeset
20
a5175713518c add training db images
smith@nwoca.org
parents:
diff changeset
21 echo "Restoring backup file"
a5175713518c add training db images
smith@nwoca.org
parents:
diff changeset
22
a5175713518c add training db images
smith@nwoca.org
parents:
diff changeset
23 gunzip -f $BACKUP_FILE -c | psql
a5175713518c add training db images
smith@nwoca.org
parents:
diff changeset
24
a5175713518c add training db images
smith@nwoca.org
parents:
diff changeset
25 fi
a5175713518c add training db images
smith@nwoca.org
parents:
diff changeset
26
a5175713518c add training db images
smith@nwoca.org
parents:
diff changeset
27 echo ""
a5175713518c add training db images
smith@nwoca.org
parents:
diff changeset
28 echo "$DB_NAME database created"