Skip to content

Instantly share code, notes, and snippets.

@tpitale

tpitale/db-backup.sh

Forked from bkenny/db-backup.sh
Last active Dec 19, 2015
Embed
What would you like to do?
Simple shell script to backup each postgresql database to s3.
#!/bin/bash
BACKUP="/tmp/s3/db"
DATE=`date +"%Y-%m-%d"`
DIR="${BACKUP}/${DATE}/"
if [ ! -d $DIR ];
then
mkdir -p $DIR
fi
for DATABASE in `echo 'SELECT datname FROM pg_database;' | psql -t -WSECRET -U da_admin template1`
do
echo -n Backing up $DATABASE .....
pg_dump -ROx -WSECRET -U da_admin $DATABASE | gzip -c > ${DIR}/${DATABASE}.sql.gz 2>/dev/null
echo Done
done
echo -n Uploading to Amazon S3
s3cmd put ${DIR} s3://S3-BUCKET-NAME/db/${DATE}/ --recursive
echo -n Removing local directory ...
rm -rf ${DIR}
echo Done
@tpitale

This comment has been minimized.

Copy link
Owner Author

@tpitale tpitale commented Jul 1, 2013

This does include postgres, template0, and template1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.