Last active
December 30, 2015 11:09
-
-
Save iambibhas/7820947 to your computer and use it in GitHub Desktop.
Postgresql database backup script
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
# IMPORTANT: Run this from the machine that's running the DB | |
# e.g. Vagrant box. Or change the HOST variable | |
# Destination directory where backups should be put | |
DEST_DIR="." | |
HOST="localhost" | |
DBUSER="user" | |
# List of directories to backup | |
# each directory in a new line | |
DBS="this_db | |
that_db" | |
for d in $DBS | |
do | |
echo "Backing up $d" | |
# SLUG="$(echo -n "${d}" | sed -e 's/[^[:alnum:]]/-/g' | tr -s '-' | tr A-Z a-z)" | |
# binary backup file | |
pg_dump -U $DBUSER -h $HOST -W -F c --file=$DEST_DIR/$d-`date +"%d-%b-%y"`.backup $d | |
# plain SQL without owner/role | |
pg_dump -Ox -h $HOST -U $DBUSER $d > $DEST_DIR/$d-`date +"%d-%b-%y"`.pgsql | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment