https://github.com/ableco/heroku_s3_backups
Easy S3 backups
https://github.com/ableco/heroku_s3_backups
Last synced: about 1 year ago
JSON representation
Easy S3 backups
- Host: GitHub
- URL: https://github.com/ableco/heroku_s3_backups
- Owner: ableco
- License: mit
- Created: 2018-05-08T03:18:31.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2018-05-11T19:30:08.000Z (about 8 years ago)
- Last Synced: 2025-02-23T04:27:32.408Z (over 1 year ago)
- Language: Ruby
- Size: 28.3 KB
- Stars: 0
- Watchers: 80
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# HerokuS3Backups
**Experimental**
This gem allows you to easily backup your PG database in Heroku to an S3 bucket.
## Requirements
- [Heroku CLI](https://devcenter.heroku.com/articles/heroku-cli) if you're running this locally
- [Heroku Buildpack CLI](https://github.com/heroku/heroku-buildpack-cli) if you're running this on a Heroku application
- [S3](https://github.com/qoobaa/s3)
- {optional} Heroku Scheduler(automated backups)
## Installation
Add this line to your application's Gemfile:
```ruby
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](https://github.com/heroku/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:
1) Create a rake task in `db.rake` named `s3_production_backup`
2) Have the task run `HerokuS3Backups::Heroku.new("name-of-application").backup("path/to/backup/folder")`
3) 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](https://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](http://contributor-covenant.org) code of conduct.
## License
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
## 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](https://github.com/[USERNAME]/heroku_s3_backups/blob/master/CODE_OF_CONDUCT.md).