Created
January 2, 2016 19:48
-
-
Save ekhabarov/fffdb3dbabd07e0a65db to your computer and use it in GitHub Desktop.
PG backup all databases
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 | |
| BACKUP_DIR=${HOME}'/pgbackup/' | |
| DATE=`date +'%Y-%m-%d_%H-%M'` | |
| for d in `psql postgres -c 'select datname from pg_database' -t`; | |
| do | |
| BACKUP_FILE=${BACKUP_DIR}${d}_${DATE}.dump | |
| pg_dump -f ${BACKUP_FILE} --format=d -j 4 -v -x -O --compress=7 ${d} | |
| tar -zcvf ${BACKUP_FILE}.tar ${BACKUP_FILE} | |
| rm -rf ${BACKUP_FILE} | |
| done; | |
| exit 0; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment