Created
February 8, 2016 18:07
-
-
Save nicerobot/c24d2659652e0a14ecb3 to your computer and use it in GitHub Desktop.
Backup a PostgreSQL database with each schema in a separate folder.
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/bash | |
| export PGDATABASE=${PGDATABASE:-${1:-postgres}} PGUSER=${PGUSER:-${2:-postgres}} PGHOST=${PGHOST:-localhost} | |
| echo '\dn' \ | |
| | psql -t \ | |
| | awk '/[a-z]/ && /etl/ && !/topology|tiger/ && !/_20/ && $1 != "public" {printf "%s\n",$1}' \ | |
| | while read n; do | |
| echo ${n%%_*} | |
| done \ | |
| | sort -u \ | |
| | while read n; do | |
| echo ${n} | |
| pg_dump -Fc -Fd -C -j2 -O -x -f ${n} -n "${n}*" 2>&1 \ | |
| | tee ${n}.log | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment