Skip to content
store your rails database backups in the cloud
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.



This gem is not supported anymore. You can find last version of this gem in


A rails plugin to backup Mysql or PostgreSQL to a cloud storage provider. You're looking at a monthly spend of four cents. So pony up you cheap bastard, and store your backups offsite.

A grandfather style system is used to decide what backups to keep copies of:

  • all backups from the past 24 hours

  • one backup per day for the past week

  • one backup per week forever

Depending on your tolerance for data loss you should be running a backup at least once a day, probably more.


Add the following to your project Gemfile

gem "db2fog"


Add the following to config/initializers/db2fog.rb

In general, you can use any configuration options supported by, plus the :directory option. If fog adds support for extra providers they should work with just a config change to Db2Fog.

Amazon S3

DB2Fog.config = {
  :aws_access_key_id     => 'yourkey',
  :aws_secret_access_key => 'yoursecretkey',
  :directory             => 'bucket-name',
  :provider              => 'AWS'

Rackspace Cloudfiles

DB2Fog.config = {
  :rackspace_username => 'username',
  :rackspace_api_key  => 'api key',
  :directory          => 'bucket-name',
  :provider           => 'Rackspace'

Local Storage

DB2Fog.config = {
  :directory  => 'bucket-name',
  :local_root => Rails.root.to_s + '/db/backups',
  :provider   => 'Local'

Passing options to the database driver

Database adaptors may support further configuration via the :database_options hash.

DB2Fog.config = {
  :directory  => 'bucket-name',
  :local_root => Rails.root.to_s + '/db/backups',
  :provider   => 'Local',
  :database_options => {
    :pg_version => 8

Supported database options:

pg_version 8 or 9

The major version of PostgreSQL installed on the server. Defaults to 9.


# Add to your crontab or whatever
rake db2fog:backup:full

# Handy tasks
rake db2fog:restore  # You should be testing this regularly
rake db2fog:clean    # Clean up old backups - cron this


If you want to trigger backups from ruby (say, from a delayed job) you can do this:


This is pure so ruby should run on most ruby VMs. I develop on MRI 1.9.2.

This will only work with rails 3. Supporting earlier versions is more complication than I feel like handling at the moment.


Specs are a little weak and mysql based. This code is bit hackish but is being used by quite a few people.


This is a fork of Xavier Shay's db2s3 gem. It worked perfectly, but only supported Amazon S3 within US-east. By switching the dependency to using fog this now supports all S3 regions and multiple storage providers

Xavier's original gem is available at

Xavier quotes the following example as inspiration:

You can’t perform that action at this time.