Skip to content

Instantly share code, notes, and snippets.

@0xDing
Created January 6, 2019 07:03
Show Gist options
  • Save 0xDing/0b5c7deccf0c527f3a517a20b596746a to your computer and use it in GitHub Desktop.
Save 0xDing/0b5c7deccf0c527f3a517a20b596746a to your computer and use it in GitHub Desktop.
backup postgresql database to aws s3
#!/bin/sh
CURRENT=`date +%s`
HOST="xxx.rds.amazonaws.com"
S3BUCKET = 'XXX'
DUMP="${DB}.${CURRENT}-full.tar"
echo "starting dump datbase..."
pg_dump -h ${HOST} -p 5432 -U ${USER} -w -d ${DB} -O -v -F tar -f ${DUMP}
lzop -Uv ${DUMP}
# apt-get install lzop
md5sum --tag ${DUMP}.lzo > ${DUMP}.lzo.md5
aws s3 cp ${DUMP}.lzo s3://${S3BUCKET}/
aws s3 cp ${DUMP}.lzo.md5 s3://${S3BUCKET}/
echo "done"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment