A means of automating Heroku's pgbackups and archiving them to Amazon S3 via the
pgbackups:archive rake task that this gem provides will capture a pgbackup, wait for it to complete, then store it within the Amazon S3 bucket you specify. This rake task can be scheduled via the Heroku Scheduler, thus producing automated, offsite, backups.
The rake task will use pgbackups'
--expire flag to remove the oldest pgbackup Heroku is storing when there are no free slots remaining.
You can configure retention settings at the Amazon S3 bucket level from within the AWS Console if you like.
Add the gem to your Gemfile and bundle:
gem "pgbackups-archive" bundle install
Install Heroku addons:
heroku addons:add pgbackups:plus heroku addons:add scheduler:standard
Note: You can use paid-for versions of pgbackups if you'd like, however the dev and basic database offerings only support the free (plus) version.
Apply environment variables:
heroku config:add PGBACKUPS_AWS_ACCESS_KEY_ID="XXX" heroku config:add PGBACKUPS_AWS_SECRET_ACCESS_KEY="YYY" heroku config:add PGBACKUPS_BUCKET="myapp-backups" heroku config:add PGBACKUPS_REGION="us-west-2"
Note: A good security measure would be to use a dedicated set of AWS credentials with a security policy only allowing access to the bucket you're specifying. See this Pro Tip on Assigning an AWS IAM user access to a single S3 bucket.
Add the rake task to scheduler:
heroku addons:open scheduler
rake pgbackups:archive as a task you would like to run at any of the available intervals.
Loading the Rake task
If you're using this gem in a Rails 3 app the rake task will be automatically loaded via a Railtie.
If you're using this gem with a Rails 2 app, or non-Rails app, add the following to your Rakefile:
I shouldn't have to say this, but I will. Your backups are your responsibility. Take charge of ensuring that they run, archive and can be restored periodically as expected. Don't rely on Heroku, this gem, or anything else out there to substitute for a regimented database backup and restore testing strategy.
- Fork it
- Create your feature branch (
git checkout -b my-new-feature)
- Commit your changes (
git commit -am 'Added some feature')
- Push to the branch (
git push origin my-new-feature)
- Create a Pull Request
Many thanks go to the following who have contributed to making this gem even better:
- Robert Bousquet (@bousquet)
- Autoload rake task into Rails 2.x once the gem has been loaded.
- Freely distributable and licensed under the MIT license.
- Copyright (c) 2012 Kenny Johnston