Skip to content

Instantly share code, notes, and snippets.

@dkastl
Created January 4, 2014 13:25
Show Gist options
  • Save dkastl/8255309 to your computer and use it in GitHub Desktop.
Save dkastl/8255309 to your computer and use it in GitHub Desktop.
#!/bin/bash
MYDATE=$(date +%d-%m-%Y)
for PORT in 5432 5433 5434
do
echo "Backups on port $PORT"
export PGPORT=$PORT
LIST=$(psql -l | awk '{ print $1 }' | grep '^[a-z]' | grep -v template | grep -v postgres)
for ITEM in $LIST
do
NAME=${ITEM}-${MYDATE}.dmp
echo "Backing up $ITEM to $NAME"
pg_dump -Fc -f $NAME ${ITEM}
done
done
# To restore any of the dumps, you can do:
#createdb foo; pg_restore foo.dmp | psql foo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment