Skip to content

Instantly share code, notes, and snippets.

@michelemina
Created September 19, 2013 17:03
Show Gist options
  • Save michelemina/6626493 to your computer and use it in GitHub Desktop.
Save michelemina/6626493 to your computer and use it in GitHub Desktop.
create dump foreach db on postgresql
#!/bin/bash
echo "Postgresql complete hot backup started"
DIR="/dump-path"
[ ! $DIR ] && mkdir -p $DIR || :
LIST=$(su postgres -c "psql -l" | awk '{ print $1}' | grep -vE '^-|^List|^Name|template[0|1]|^\(|^\||^$')
for d in $LIST
do
echo "Dump $d started"
su postgres -c "/usr/bin/pg_dump $d" | gzip -c > $DIR/$d.dump.gz
echo "Dump $d finished"
done
echo "Postgresql complete hot backup finished"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment