Last active
December 11, 2015 17:28
-
-
Save epleterte/4634149 to your computer and use it in GitHub Desktop.
postgresql-backup
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -ue | |
# Postgres backup script | |
# Christian Bryn | |
backup_mountpoint="/var/nfs-backup" | |
backup_path="${backup_mountpoint}/${HOSTNAME}/postgresql" | |
[ ! -d "${backup_path}" ] && mkdir -p "${backup_path}" | |
#backup_timestamp=$( date '+%d' ) | |
backup_timestamp=$( date +%d-%m-%Y:%H:%M ) | |
# select all databases except the default 'postgres': | |
dbnames=$( psql --quiet --no-align --tuples-only --dbname=postgres -c "select datname from pg_database where datistemplate is false and datallowconn is true and datname !='postgres'"; ) | |
for db in $dbnames; do | |
#pg_dump -C -Z9 -f "${backup_path}/${db}.${backup_timestamp}.sql.gz" "${db}" | |
pg_dump -C "${db}" | pbzip2 > "${backup_path}/${db}.${backup_timestamp}.sql.bz2" | |
done | |
# dump metadata of all sorts. | |
#pg_dumpall -g | gzip -9 > "${backup_path}/postgres.global.${backup_timestamp}.sql.gz" | |
pg_dumpall -g | pbzip2 > "${backup_path}/postgres.global.${backup_timestamp}.sql.bz2" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment