With any website, having a regular backup is critical. Heroku, the awesome Rails cloud service that hosts Pocket Tabs and a handful of other sites for me, provides the ability to do backups of code and data through a concept called bundles.
When you enable the free bundles support on Heroku, you only get 1 bundle. You can download it and destroy it to free up the space for the next bundle, but results in 3-4 commands just to get a backup of the site. You can pay for additional bundles, but with a little script we can get by with just one.
Here’s the typical workflow:
1 2 3 4
With some help, I created a rake task to do this work for me.
In your rails project, place a new rake file in the `lib/tasks` folder. I called mine `backup_site.rake`. The standard Rails Rakefile knows how to load up any of your custom rake files in this folder. It’s a good idea to give your rake tasks a namespace to keep everything tidy. Here’s mine:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
Now I can easily just run a rake task any time I want to backup the site.
1 2 3
Next step is to put this in a cron job so that I don’t have to remember to do it.