Skip to content

Instantly share code, notes, and snippets.

@EmmanuelKasper
Last active December 27, 2015 08:59
Show Gist options
  • Save EmmanuelKasper/7300889 to your computer and use it in GitHub Desktop.
Save EmmanuelKasper/7300889 to your computer and use it in GitHub Desktop.
PO
#!/bin/sh
# to be run as postgres user
# a database should be restored as posgres user with
# dropdb popcon
# createdb --encoding=UNICODE --owner=popcon popcon
# psql popcon < popcon.psql
set -e
do_bkp() {
/usr/bin/pg_dump -U postgres --column-inserts --file=/var/backups/postgres/$i.psql $i
}
databases=$(echo select datname from pg_database | \
/usr/bin/psql -d postgres -U postgres -t)
for i in $databases; do
if [ "$i" != "template0" ] && [ "$i" != "template1" ]; then
do_bkp $i
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment