TBA
-
-
Save kavu/4984644 to your computer and use it in GitHub Desktop.
How to make Rails + Backup + Whenever + Capistrano (and rbenv) work.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#... | |
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" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# encoding: utf-8 | |
set :output, "log/cron.log" | |
every 1.day, at: '04:00' do | |
rake 'backup' | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#... | |
gem 'backup', require: false, | |
github: 'kavu/backup', | |
branch: 'bump_fog_version', | |
ref: 'c3fd8e6eb4f464de1c8' | |
gem 'whenever', require: false | |
#... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment