Skip to content

Instantly share code, notes, and snippets.

@luanlmd
Created November 3, 2010 21:15
Show Gist options
  • Save luanlmd/661728 to your computer and use it in GitHub Desktop.
Save luanlmd/661728 to your computer and use it in GitHub Desktop.
Backup PostgreSQL Databases
#!/bin/bash
LIST=$(/usr/bin/psql -l | /usr/bin/awk '{ print $1}' | grep -vE '^-|^\(|^List|^N[o|a]me|template[0|1]')
for d in $LIST
do
echo "Backuping: " $d
pg_dump -i -h 127.0.0.1 -p 5432 -U postgres -F t -b -f "/backup/backup/$d.backup" $d
tar -zcf /backup/backup/$d.tar.gz -C / backup/backup/$d.backup
rm /backup/backup/$d.backup
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment