Skip to content

chawang90/heroku-database-backups

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

46 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simple heroku app with a bash script for capturing heroku database backups and copying to your s3 bucket. Deploy this as a separate app within heroku and schedule the script to backup your production databases which exist within another heroku project.

Installation

First create a project on heroku with the heroku-buildpack-toolbelt.

heroku create my-database-backups --buildpack https://github.com/heroku/heroku-buildpack-toolbelt

Next push this project to your heroku projects git repository.

git remote add heroku git@heroku.com:josephine-database-backups.git
git push heroku master

Now we need to set some environment variables in order to get the heroku cli working properly using the [heroku-buildpack-toolbet](We are using the https://github.com/gregburek/heroku-buildpack-toolbelt.git).

heroku config:add HEROKU_TOOLBELT_API_EMAIL=your-email@gmail.com -a josephine-database-backups
heroku config:add HEROKU_TOOLBELT_API_PASSWORD=`heroku auth:token` -a josephine-database-backups

Next we need to add the amazon key and secret.

heroku config:add AWS_ACCESS_KEY_ID=123456 -a josephine-database-backups
heroku config:add AWS_DEFAULT_REGION=us-east-1 -a josephine-database-backups
heroku config:add AWS_SECRET_ACCESS_KEY=132345verybigsecret -a josephine-database-backups

And we'll need to also set the bucket and path where we would like to store our database backups:

heroku config:add S3_BUCKET_PATH=jodb-production/pgbackups/production -a josephine-database-backups

Be careful when setting the S3_BUCKET_PATH to leave off a trailing forward slash. Amazon console s3 browser will not be able to locate your file if your directory has "//" (S3 does not really have directories.).

Configure which app is being backed up:

heroku config:add APP=josephine-production

Finally, we need to add heroku scheduler and call backup.sh on a regular interval with the appropriate database and app.

heroku addons:create scheduler -a my-database-backups

Now open it up, in your browser with:

heroku addons:open scheduler -a my-database-backups

And add the following command to run as often as you like:

DATABASE=`/app/vendor/heroku-toolbelt/bin/heroku config:get HEROKU_POSTGRESQL_MAUVE_URL -a $APP` /app/bin/backup.sh

DATABASE is the name of the database you would like to capture and backup. The database should be specified here so that we can dynamically fetch the database URL.

About

Heroku database backups and copies to S3

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • Shell 100.0%