backup.sh

From RtMF (Quinn Storm), 1 Year ago, written in Plain Text, viewed 139 times.
URL http://paste.beautifulsunrise.org/view/f440c440 Embed
Download Paste or View Raw
  1. #!/bin/bash
  2. SRCDIR="/home/rtmf/workspace/django/sunrise"
  3. PGUSER="rtmf"
  4. PGPASSWORD="testpass"
  5. PGDATABASE="test"
  6. STAGEPATH="$(mktemp -d --tmpdir backup-XXXXXXX)"
  7. DBDUMPPATH="${PGDATABASE}.psql"
  8. TARBALL="${STAGEPATH}/backup-$(date -Iseconds)-$(uuidgen).tar.gz"
  9. GPGKEYID="backups@foo.bar"
  10. # XXX - on many systems /tmp is tmpfs, may wish to explicitly set a tmpdir for these to avoid consuming all ram
  11. pg_dump -Fc > "${STAGEPATH}/${DBDUMPPATH}"
  12. tar -czpf "${TARBALL}" -C "${STAGEPATH}" "${SRCDIR}" "${DBDUMPPATH}" 2>/dev/null
  13. rm "${STAGEPATH}/${DBDUMPPATH}"
  14. # TODO - move finished product out of STAGEPATH
  15. gpg --encrypt -r "${GPGKEYID}" < "${TARBALL}" > "${TARBALL}.gpg"
  16. rm "${TARBALL}"
  17. echo "${TARBALL}.gpg"
  18. echo python -c "\
  19. import boto
  20. s3_connection = boto.connect_s3()
  21. bucket = s3_connection.get_bucket('${S3BUCKET}')
  22. key = boto.s3.key.Key(bucket, '$(basename ${TARBALL}.gpg)')
  23. with open('${TARBALL}.gpg') as f:
  24.         key.send_file(f)
  25. "
  26. rm -r "${STAGEPATH}"

Reply to "backup.sh"

Here you can reply to the paste above