-
-
Save tpitale/5900882 to your computer and use it in GitHub Desktop.
Simple shell script to backup each postgresql database to s3.
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="/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This does include postgres, template0, and template1.