My company’s main site (http://www.viaviela.nl) is now using Heroku as a hosting provider. I really like it because it forces the company to stick to certain boundaries and not make a total mess of the hosting server. The one thing Heroku doesn’t take care of is backups. Well they do make backups, but they only store 2 backups and you have to download and schedule them yourselves. I created a little script to do that:
#!/bin/bashTARGET=/opt/heroku_backups/website-`/bin/date +%d`.pgdumpAPPNAME=mainwebsiteHEROKU=/var/lib/gems/1.8/bin/heroku$HEROKU pgbackups:capture --expire --app $APPNAMEwget `$HEROKU pgbackups:url --app $APPNAME` -O $TARGET
Target is the path where you want the backups to be stored, it uses the number of the day (0-31) to name te backup. This way you’ll have automatic rotation. Backups will be stored for 1 month. And some for 2 months because not every month has 31 days. It also assumes that you have the heroku gem installed system wide. If you didn’t or you are unsure, use “which heroku” to find your heroku gem. You should replace “mainwebsite” with you app’s name.
Be careful because there is no error checking in this script. You should run it from cron and have errors mailed to you.
