This gem allows you to send postgres dumps from Heroku to an S3 bucket. It also allows you restore your current database from any of the backups on S3.
To install on your system
gem install pgbackups_s3
To install in rails app, add the following line to your Gemfile
Then create the initialzer that will hold all the settings for the packups
rails g pgbackups_s3:install
config/initializers/pgbackups_s3.rb and follow the documentation to get your backups cranking!
After the initializer is all setup, run:
if you need to create the bucket on S3
Using the gem
Back dat database up
To run a backup you can either run it in the rails console:
or through a rake task
List all the backups for a certain day
To list all backups for today just run:
All the values will default to today if there is no input
To specify a specific day of backups, run:
PgbackupsS3.list_backups(YEAR, MONTH, DAY)
This command will print out the keys of all the backups like so:
Backups for 7-25-2014 ----------------------- -- backups/2014/7/25/21:16:14.dump -- backups/2014/7/25/21:17:52.dump -- backups/2014/7/25/21:19:00.dump -- backups/2014/7/25/21:19:43.dump -- backups/2014/7/25/21:20:22.dump -- backups/2014/7/25/21:21:32.dump -- backups/2014/7/25/21:22:13.dump
To restore from a backup
WARNING: This will wipe out all data in your specified restore database, 'DATABASE_URL' is the default, with the backup.
Take one of the above keys and enter it as the param for the following function
You will have to confirm the restore but the database specified will be overwritten with your backup data.
Configuring your Amazon S3 bucket to archive and drop old backups
If you want to archive your postgres backups to Amazon Glacier and/or delete them after so many days, you'll need to set up a Lifecycle for your bucket.
To set this up
- Go into you AWS console
- Click on S3
- Click on the bucket you have setup in the initalizer
- Once in your bucket, click on properties
- Then open the lifecycle, and click 'add rule'
- Then just follow the instructions
Feel free to contribute or improve the code. Just fork the repo and open a pull request with you code. Also if you there are any issues just go ahead and create a new issue.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.