Skip to content

Instantly share code, notes, and snippets.

@zukka77
Created December 4, 2017 09:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zukka77/db57eb9570008b466dcfc89471407587 to your computer and use it in GitHub Desktop.
Save zukka77/db57eb9570008b466dcfc89471407587 to your computer and use it in GitHub Desktop.
pg_dump script
#!/bin/bash -e
DATA=$(date -I)
DEST_DIR=${DEST_DIR}
CURRENT_DIR="${DEST_DIR}/${DATA}"
mkdir -p $CURRENT_DIR
cd $CURRENT_DIR
pg_dumpall -Upostgres -g > global.dmp
for db in $(psql -Upostgres -At -c 'select datname from pg_database where not datistemplate and datallowconn order by datname');do
echo backup ${db}
pg_dump -Upostgres -Fc $db > ${db}.dump
done
~
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment