Skip to content

Instantly share code, notes, and snippets.

@killercup
Last active December 18, 2015 00:09
Show Gist options
  • Save killercup/5694025 to your computer and use it in GitHub Desktop.
Save killercup/5694025 to your computer and use it in GitHub Desktop.
Backup Postgres DB to S3 (app specific)
#! /bin/csh
##
# Backup Postgres and Avatars to S3
#
# Requires:
# - postgres with pg_dump
# - xz to compress
# - openssl to encrypt
# - pv for nice output (two progress bars, for sql dump and compress)
# - s3cmd to send all this stuff to our S3 bucket
# Run `s3cmd --configure` first to add your AWS API keys!
##
setenv APPNAME (PASTE_HERE)
setenv PASSPHRASE (PASTE_HERE)
setenv AWS_BUCKET (PASTE_HERE)
setenv WORKINGDIR "/home/app/$APPNAME/backup/postgres/"
pg_dump $APPNAME | pv -cN sql | xz -z -9 | pv -cN xz | openssl enc -aes-256-cbc -e -pass pass:$PASSPHRASE -out "$WORKINGDIR/${APPNAME}.sql.xz.enc"
s3cmd sync --delete-removed $WORKINGDIR s3://${AWS_BUCKET}/postgres/
setenv AVATARS "/home/app/$APPNAME/shared/uploads/user/avatar/"
s3cmd sync --delete-removed $AVATARS s3://${AWS_BUCKET}/avatars/
# Unset environment variables
setenv PASSPHRASE
setenv APPNAME
setenv AVATARS
setenv WORKINGDIR
setenv AWS_BUCKET
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment