Skip to content

Instantly share code, notes, and snippets.

@jch
Created May 19, 2011 21:02
Show Gist options
  • Save jch/981733 to your computer and use it in GitHub Desktop.
Save jch/981733 to your computer and use it in GitHub Desktop.
Rails Backup

Rails Backup

Add backup support to a Rails project with the 'backup' gem

Gemfile

gem 'backup', '3.0.15'
gem 'fog', '0.7.0'  # used by backup for s3 uploads, but not a dependency

Generate and Edit Config

backup generate --databases='mysql|postgresql' --storages='s3' --compressors='gzip' --path=.
mv config.rb config/backup.rb

Create s3 bucket listed in backup.rb

lib/tasks/backup.rake

namespace :backup do
  desc "Run a backup and save to s3"
  task :default do
    system("backup perform -t cer_portal -c config/backup.rb")
  end
end

config/deploy.rb

before 'deploy', 'db:backup'

namespace :db do
  desc 'Backup the database to s3'
  task :backup do
    run "cd #{current_path} && RAILS_ENV=#{rails_env} rake backup"
  end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment