Skip to content

Instantly share code, notes, and snippets.

@leonsas
Created June 7, 2015 23:22
Show Gist options
  • Save leonsas/dc26fda3d80fae1be78c to your computer and use it in GitHub Desktop.
Save leonsas/dc26fda3d80fae1be78c to your computer and use it in GitHub Desktop.
Heroku Backup to S3
import os
import arrow
from boto.s3.connection import S3Connection
S3_BACKUP_BUCKET = 'backup-bucket-name'
APP_NAME = 'myapp'
S3_REGION_HOSTNAME = 'e.g s3-us-west-1.amazonaws.com'
os.system('curl -o latest.dump `heroku pg:backups public-url --app %s`' % APP_NAME)
conn = S3Connection(host='s3-us-west-2.amazonaws.com')
bucket = conn.get_bucket(S3_BACKUP_BUCKET)
backup_name = arrow.now().format('X')
k = bucket.new_key(backup_name + '.dump')
k.set_contents_from_filename('latest.dump')
os.remove('latest.dump')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment