HerokuS3Backups
Experimental
This gem allows you to easily backup your PG database in Heroku to an S3 bucket.
Requirements
- Heroku CLI if you're running this locally
- Heroku Buildpack CLI if you're running this on a Heroku application
- S3
- {optional} Heroku Scheduler(automated backups)
Installation
Add this line to your application's Gemfile:
gem "heroku_s3_backups"
And then execute:
$ bundle
Or install it yourself as:
$ gem install heroku_s3_backups
Usage
Backing up a Heroku database to S3
The following environment variables must be set:
- S3_ACCESS_KEY_ID - Key of an account that has write access to the backup bucket
- S3_SECRET_ACCESS_KEY - Key of an account that has write access to the backup bucket
- S3_PRODUCTION_BACKUP_BUCKET - Bucket to backup db to
- HEROKU_API_KEY - Auth token for Heroku to access the app’s DB settings(ie pg:backup). This can be generated by running
heroku auth:token
from the CLI.
If you're running this script on a Heroku application, ensure
Example of the API keys being set:
S3_ACCESS_KEY_ID="abcd1234"
S3_SECRET_ACCESS_KEY="qwerty4321"
S3_PRODUCTION_BACKUP_BUCKET="backups/production"
HEROKU_API_KEY="1234-abcd"
To run:
HerokuS3Backups::Heroku.new("name-of-application").backup_to_s3("path/to/backup/folder")
If you're running this in a Heroku application, ensure that you have the Heroku Buildpack CLI installed.
Automating Heroku to S3 backups
To automate backups in Heroku, you can create a rake task and add the ‘Heroku Scheduler’ add-on to have it run the task in preset intervals.
Example:
- Create a rake task in
db.rake
nameds3_production_backup
- Have the task run
HerokuS3Backups::Heroku.new("name-of-application").backup("path/to/backup/folder")
- Set Heroku scheduler to run
rake db:s3_production_backup
Capturing a new backup
The following environment variable must be set:
- HEROKU_API_KEY - Auth token for Heroku to access the app’s DB settings(ie pg:backup). This can be generated by running
heroku auth:token
from the CLI.
To run:
HerokuS3Backups::Heroku.new("name-of-application").capture
- maintenance_mode - When enabled, will set the target application into maintenance mode as the database is backed up
Automating backup captures
TODO
Downloading a backup
TODO
Development
After checking out the repo, run bin/setup
to install dependencies. Then, run rake spec
to run the tests. You can also run bin/console
for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install
. To release a new version, update the version number in version.rb
, and then run bundle exec rake release
, which will create a git tag for the version, push git commits and tags, and push the .gem
file to rubygems.org.
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/heroku_s3_backups. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
License
The gem is available as open source under the terms of the MIT License.
Code of Conduct
Everyone interacting in the HerokuS3Backups project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.