Created
February 14, 2018 15:54
-
-
Save pogin503/9383dc30a57aa26cc9fa8f8f27048852 to your computer and use it in GitHub Desktop.
This file contains 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
#!/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" |
This file contains 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
#!/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" |
This file contains 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
#!/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