Skip to content

Instantly share code, notes, and snippets.

Created February 19, 2013 10:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/4984592 to your computer and use it in GitHub Desktop.
Save anonymous/4984592 to your computer and use it in GitHub Desktop.
# encoding: utf-8
require 'backup'
RAILS_ENV = ENV['RAILS_ENV'] || 'development'
config = YAML.load_file File.expand_path('../database.yml', __FILE__)
Backup::Storage::S3.defaults do |s3|
s3.access_key_id = '...'
s3.secret_access_key = '...'
s3.region = '...'
s3.bucket = '...'
s3.keep = 25
end
Backup::Model.new(:postgres, 'Backup PostgreSQL database to S3') do
database PostgreSQL do |db|
db.name = config[RAILS_ENV]["database"]
db.username = config[RAILS_ENV]["username"]
db.password = config[RAILS_ENV]["password"]
db.host = config[RAILS_ENV]["host"]
db.port = config[RAILS_ENV]["port"]
db.skip_tables = []
end
store_with S3 do |s3|
s3.path = config[RAILS_ENV]["database"]
end
compress_with Bzip2
split_into_chunks_of 250
end
Backup::Model.new(:redis, 'Backup Redis database to S3') do
database Redis do |db|
db.path = "..."
db.invoke_save = true
end
store_with S3 do |s3|
s3.path = "myapp_#{RAILS_ENV}"
end
compress_with Bzip2
split_into_chunks_of 250
end
#...
require 'whenever/capistrano'
#...
set :whenever_command, "bundle exec whenever"
set :bundle_flags, "--deployment --quiet --binstubs"
set :default_environment, {
'PATH' => "$HOME/.rbenv/shims:$HOME/.rbenv/bin:$PATH"
}
#...
namespace :rbenv do
task :rehash do
run 'rbenv rehash'
end
end
task :backup do
run "cd #{current_path} && bundle exec rake backup RAILS_ENV=#{rails_env}"
end
#...
after "bundle:install", "rbenv:rehash"
# encoding: utf-8
set :output, "log/cron.log"
every 1.day, at: '04:00' do
rake 'backup'
end
#...
gem 'backup', require: false,
github: 'kavu/backup',
branch: 'bump_fog_version',
ref: 'c3fd8e6eb4f464de1c8'
gem 'whenever', require: false
#...
desc "Back Postgres and Redis"
task :backup do
# Yeah, it's an ugly looking command
sh "bundle exec backup perform -q -t postgres,redis --config-file config/backup.rb --root-path . --tmp-path public/system/backup/tmp --cache-path public/system/backup/cache --data-path public/system/backup/data"
end

How to make Rails + Backup + Whenever + Capistrano (and rbenv) work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment