Git Product home page Git Product logo

pgbackups-archive's Introduction

pgbackups-archive

Gem Version Code Climate

A means of automating Heroku PGBackups and archiving them to Amazon S3.

Upgrade Alert

As of v1.0.0, pgbackups-archive works with the new Heroku PGBackups service, which replaced the older PG Backups add-on.

If you're still using an older version of pgbackups-archive, it's time to upgrade!

Read more about this transition in Heroku's offerings on the Heroku Blog: PG Backups Levels Up

Please note that the environment variables that need to be defined have changed with v1.0.0.

Overview

The pgbackups:archive rake task this gem provides will capture a Heroku 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.

This gem doesn't interfere with or utilze automated backups, so feel free to schedule those with the pg:backups schedule command as you desire.

You can configure how many manual backups (created by you or this gem) you'd like to keep at the Heroku PGBackups level to ensure there is always space to capture a new backup.

You can configure retention settings at the Amazon S3 bucket level from within the AWS Console if you like.

Use

Install the gem

Add the gem to your Gemfile and bundle:

gem "pgbackups-archive"
bundle install

Install Heroku Scheduler add-on

heroku addons:create scheduler

Setup an AWS IAM user, S3 bucket and policy

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.

Apply Environment Variables

# Required
heroku config:add HEROKU_API_KEY="collaborator-api-key"
heroku config:add PGBACKUPS_APP="myapp"
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"

# Optional: If you wish to backup a database other than the one that
# DATABASE_URL points to, set this to the name of the variable for that
# database (useful for follower databases).
heroku config:add PGBACKUPS_DATABASE="HEROKU_POSTGRESQL_BLACK_URL"

Add the rake task to scheduler

heroku addons:open scheduler

Then specify rake pgbackups:archive as a task you would like to run at any of the available intervals.

In case you would like to make backups at different intervals simply "protect" a daily task using a bash if-statement, for example to run a task every 1st day in a month:

if [ "$(date +%d)" = 01 ]; then rake pgbackups:archive; fi

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:

require "pgbackups-archive"

Testing

To run the test suite, use the guard command and save a file or hit enter to run the full suite.

Use the pgbackups-archive-dummy test harness to setup a dummy database on Heroku to test against.

Disclaimer

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.

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a Pull Request

Contributors

Many thanks go to the following who have contributed to making this gem even better:

License

  • Freely distributable and licensed under the MIT license.
  • Copyright (c) 2012-2015 Kenny Johnston endorse

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.