#!/bin/sh
. /etc/profile
dt=$(date +%Y-%m-%d-%H%M)
pg_dump -F c -Z 9 -d exampleDb > /var/local/pg_dump/exampleDb.all.$dt.dump
pg_restore -d exampleDb exampleDb.all.dump
sudo -u postgres bash -c "psql -c \"ALTER USER postgres WITH PASSWORD 'postgres';\""
sudo -u postgres bash -c "psql -c \"CREATE USER exampleDb WITH PASSWORD 'exampleDb';\""
sudo -u postgres bash -c "psql -c \"CREATE DATABASE exampleDb OWNER exampleDb;\""
sudo -u postgres bash -c "psql -c \"GRANT ALL PRIVILEGES ON DATABASE exampleDb to exampleDb;\""
cp postgresql.conf /etc/postgresql/9.4/main
cp pg_hba.conf /etc/postgresql/9.4/main
sudo -u postgres pg_restore -d exampleDb exampleDb.all.dump