Created
April 14, 2014 07:18
-
-
Save mmrwoods/10623665 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
#!/bin/bash | |
# Create a clean SQL dump of each non-template postgres database | |
# Should be run as root to avoid any permissions issues | |
dest_dir=/var/local/backup/postgres | |
db_list_sql="SELECT datname FROM pg_database WHERE NOT datistemplate AND datallowconn ORDER BY datname" | |
for db in $(su - postgres -c "psql -At -c '$db_list_sql'"); do | |
su - postgres -c "pg_dump --clean $db" | gzip -9 > $dest_dir/$db.sql.gz | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment