Skip to content

Instantly share code, notes, and snippets.

@pogin503
Created February 14, 2018 15:54
Show Gist options
  • Save pogin503/9383dc30a57aa26cc9fa8f8f27048852 to your computer and use it in GitHub Desktop.
Save pogin503/9383dc30a57aa26cc9fa8f8f27048852 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
set -eu
# set -x
# shellcheck source=env.sh
. env.sh
mkdir -p $OUTPUT_DIR
echo "DROP DATABASE IF EXISTS $DBNAME;" | psql --username="$USERNAME" -h "$HOST" template1
echo "CREATE DATABASE $DBNAME with encoding = 'UTF8';" | psql --username="$USERNAME" -h "$HOST" template1
psql --username="$USERNAME" -h "$HOST" "$DBNAME" < "$OUTPUT_DIR/$SCHEMA"
psql --username="$USERNAME" -h "$HOST" "$DBNAME" < "$OUTPUT_DIR/$DATA"
#!/usr/bin/env bash
set -eu
# set -x
# shellcheck source=env.sh
. env.sh
mkdir -p "$OUTPUT_DIR"
pg_dump --username="$USERNAME" -h "$HOST" --schema-only "$DBNAME" --if-exists --clean > "$OUTPUT_DIR/$SCHEMA"
pg_dump --username="$USERNAME" -h "$HOST" --data-only --disable-triggers "$DBNAME" > "$OUTPUT_DIR/$DATA"
#!/usr/bin/env bash
# shellcheck disable=SC2034
# DBPASSWD=postgres
USERNAME=postgres
DBNAME=postgres
SCHEMA=mydb.schema.sql
DATA=mydb.data.sql
HOST=localhost
EXTRA=
OUTPUT_DIR=~/var/lib/postgresql/10/data/dump
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment