Created
February 27, 2019 22:05
-
-
Save austinorth/f3d887d04c0a3f26fdd7499e0c4db8ec to your computer and use it in GitHub Desktop.
Bash script to backup each schema in a database in a separate backup file.
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
#!/bin/bash | |
if [ $# -eq 0 ]; then | |
echo "Usage: ./backup-schemas-separately.sh yourdatabasename" 1>&2 | |
exit 1; | |
fi; | |
db=$1 | |
schemas=$(psql -U postgres -w -h localhost -qAt -c "SELECT nspname FROM pg_catalog.pg_namespace;" "${db}") | |
for schema in $schemas; do | |
pg_dump -F c -w -h localhost -U postgres -n "${schema}" "${db}" > /home/$USER/backups/"${schema}".custom | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment