Last active
May 6, 2022 17:33
-
-
Save edw/5237669 to your computer and use it in GitHub Desktop.
Dump a schema from a Heroku app's 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/sh | |
# Usage: heroku-pg-dump-schema.sh HEROKU-APP-NAME DB-ENV-VAR-NAME SCHEMA-NAME | |
app=$1 | |
env_var=$2 | |
schema=$3 | |
db_url=`heroku config -s --app ${app} | grep ${env_var}` | |
export PGDATABASE=`sed -E 's|^.*/([a-zA-Z0-9]*)$|\1|' <<EOF | |
$db_url | |
EOF` | |
export PGHOST=`sed -E 's|^.*@([-.a-zA-Z0-9]*):.*$|\1|' <<EOF | |
$db_url | |
EOF` | |
export PGPORT=`sed -E 's|^.*:([-.a-zA-Z0-9]*)/.*$|\1|' <<EOF | |
$db_url | |
EOF` | |
export PGUSER=`sed -E 's|^.*//([a-zA-Z0-9]*):.*$|\1|' <<EOF | |
$db_url | |
EOF` | |
export PGPASSWORD=`sed -E 's|^.*:([a-zA-Z0-9]*)@.*$|\1|' <<EOF | |
$db_url | |
EOF` | |
pg_dump --schema ${schema} -Osx |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Original script required modification for it to work (for me anyway). Modified script below in case it might help someone else