lib/dump/capistrano/v2.rb in dump-1.0.5 vs lib/dump/capistrano/v2.rb in dump-1.0.6
- old
+ new
@@ -1,12 +1,12 @@
# encoding: UTF-8
require 'fileutils'
require 'shellwords'
-require 'dump_rake/continious_timeout'
-require 'dump_rake/env'
+require 'dump/continious_timeout'
+require 'dump/env'
require 'active_support/core_ext/object/blank'
require 'English'
@@ -14,13 +14,13 @@
namespace :dump do
def dump_command(command, env = {})
rake = env.delete(:rake) || 'rake'
# stringify_keys! from activesupport
- DumpRake::Env.stringify!(env)
+ Dump::Env.stringify!(env)
- env.update(DumpRake::Env.for_command(command, true))
+ env.update(Dump::Env.for_command(command, true))
cmd = %W[-s dump:#{command}]
cmd += env.sort.map{ |key, value| "#{key}=#{value}" }
"#{rake} #{cmd.shelljoin}"
end
@@ -68,11 +68,11 @@
fail "rsync returned #{$CHILD_STATUS.exitstatus}" unless $CHILD_STATUS.success?
end
end
end
when :sftp, :scp
- DumpRake::ContiniousTimeout.timeout 15 do |thread|
+ Dump::ContiniousTimeout.timeout 15 do |thread|
transfer(direction, from, to, :via => via) do |_channel, _path, transfered, total|
thread.defer
progress = if transfered < total
format("\e[1m%5.1f%%\e[0m", transfered * 100.0 / total)
else
@@ -85,11 +85,11 @@
fail "Unknown transfer method #{via}"
end
end
def do_transfer(direction, from, to)
- via = DumpRake::Env[:transfer_via]
+ via = Dump::Env[:transfer_via]
case via && via.downcase
when nil
if got_rsync?
do_transfer_via(:rsync, direction, from, to)
else
@@ -111,12 +111,12 @@
fail "Unknown transfer method #{via}"
end
end
def with_additional_tags(*tags)
- tags = [tags, DumpRake::Env[:tags]].flatten.select(&:present?).join(',')
- DumpRake::Env.with_env(:tags => tags) do
+ tags = [tags, Dump::Env[:tags]].flatten.select(&:present?).join(',')
+ Dump::Env.with_env(:tags => tags) do
yield
end
end
def print_and_return_or_fail
@@ -151,108 +151,108 @@
def fetch_rake
fetch(:rake, nil)
end
def auto_backup?
- !DumpRake::Env.no?(:backup)
+ !Dump::Env.no?(:backup)
end
namespace :local do
- desc 'Shorthand for dump:local:create' << DumpRake::Env.explain_variables_for_command(:create)
+ desc 'Shorthand for dump:local:create' << Dump::Env.explain_variables_for_command(:create)
task :default, :roles => :db, :only => {:primary => true} do
local.create
end
- desc 'Create local dump' << DumpRake::Env.explain_variables_for_command(:create)
+ desc 'Create local dump' << Dump::Env.explain_variables_for_command(:create)
task :create, :roles => :db, :only => {:primary => true} do
print_and_return_or_fail do
with_additional_tags('local') do
run_local(dump_command(:create))
end
end
end
- desc 'Restore local dump' << DumpRake::Env.explain_variables_for_command(:restore)
+ desc 'Restore local dump' << Dump::Env.explain_variables_for_command(:restore)
task :restore, :roles => :db, :only => {:primary => true} do
run_local(dump_command(:restore))
end
- desc 'Versions of local dumps' << DumpRake::Env.explain_variables_for_command(:versions)
+ desc 'Versions of local dumps' << Dump::Env.explain_variables_for_command(:versions)
task :versions, :roles => :db, :only => {:primary => true} do
print run_local(dump_command(:versions, :show_size => true))
end
- desc 'Cleanup local dumps' << DumpRake::Env.explain_variables_for_command(:cleanup)
+ desc 'Cleanup local dumps' << Dump::Env.explain_variables_for_command(:cleanup)
task :cleanup, :roles => :db, :only => {:primary => true} do
print run_local(dump_command(:cleanup))
end
- desc 'Upload dump' << DumpRake::Env.explain_variables_for_command(:transfer)
+ desc 'Upload dump' << Dump::Env.explain_variables_for_command(:transfer)
task :upload, :roles => :db, :only => {:primary => true} do
- file = DumpRake::Env.with_env(:summary => nil) do
+ file = Dump::Env.with_env(:summary => nil) do
last_part_of_last_line(run_local(dump_command(:versions)))
end
if file
do_transfer :up, "dump/#{file}", "#{current_path}/dump/#{file}"
end
end
end
namespace :remote do
- desc 'Shorthand for dump:remote:create' << DumpRake::Env.explain_variables_for_command(:create)
+ desc 'Shorthand for dump:remote:create' << Dump::Env.explain_variables_for_command(:create)
task :default, :roles => :db, :only => {:primary => true} do
remote.create
end
- desc 'Create remote dump' << DumpRake::Env.explain_variables_for_command(:create)
+ desc 'Create remote dump' << Dump::Env.explain_variables_for_command(:create)
task :create, :roles => :db, :only => {:primary => true} do
print_and_return_or_fail do
with_additional_tags('remote') do
run_remote("cd #{current_path}; #{dump_command(:create, :rake => fetch_rake, :RAILS_ENV => fetch_rails_env, :PROGRESS_TTY => '+')}")
end
end
end
- desc 'Restore remote dump' << DumpRake::Env.explain_variables_for_command(:restore)
+ desc 'Restore remote dump' << Dump::Env.explain_variables_for_command(:restore)
task :restore, :roles => :db, :only => {:primary => true} do
run_remote("cd #{current_path}; #{dump_command(:restore, :rake => fetch_rake, :RAILS_ENV => fetch_rails_env, :PROGRESS_TTY => '+')}")
end
- desc 'Versions of remote dumps' << DumpRake::Env.explain_variables_for_command(:versions)
+ desc 'Versions of remote dumps' << Dump::Env.explain_variables_for_command(:versions)
task :versions, :roles => :db, :only => {:primary => true} do
print run_remote("cd #{current_path}; #{dump_command(:versions, :rake => fetch_rake, :RAILS_ENV => fetch_rails_env, :PROGRESS_TTY => '+', :show_size => true)}")
end
- desc 'Cleanup of remote dumps' << DumpRake::Env.explain_variables_for_command(:cleanup)
+ desc 'Cleanup of remote dumps' << Dump::Env.explain_variables_for_command(:cleanup)
task :cleanup, :roles => :db, :only => {:primary => true} do
print run_remote("cd #{current_path}; #{dump_command(:cleanup, :rake => fetch_rake, :RAILS_ENV => fetch_rails_env, :PROGRESS_TTY => '+')}")
end
- desc 'Download dump' << DumpRake::Env.explain_variables_for_command(:transfer)
+ desc 'Download dump' << Dump::Env.explain_variables_for_command(:transfer)
task :download, :roles => :db, :only => {:primary => true} do
- file = DumpRake::Env.with_env(:summary => nil) do
+ file = Dump::Env.with_env(:summary => nil) do
last_part_of_last_line(run_remote("cd #{current_path}; #{dump_command(:versions, :rake => fetch_rake, :RAILS_ENV => fetch_rails_env, :PROGRESS_TTY => '+')}"))
end
if file
FileUtils.mkpath('dump')
do_transfer :down, "#{current_path}/dump/#{file}", "dump/#{file}"
end
end
end
- desc 'Shorthand for dump:local:upload' << DumpRake::Env.explain_variables_for_command(:transfer)
+ desc 'Shorthand for dump:local:upload' << Dump::Env.explain_variables_for_command(:transfer)
task :upload, :roles => :db, :only => {:primary => true} do
local.upload
end
- desc 'Shorthand for dump:remote:download' << DumpRake::Env.explain_variables_for_command(:transfer)
+ desc 'Shorthand for dump:remote:download' << Dump::Env.explain_variables_for_command(:transfer)
task :download, :roles => :db, :only => {:primary => true} do
remote.download
end
namespace :mirror do
- desc 'Creates local dump, uploads and restores on remote' << DumpRake::Env.explain_variables_for_command(:mirror)
+ desc 'Creates local dump, uploads and restores on remote' << Dump::Env.explain_variables_for_command(:mirror)
task :up, :roles => :db, :only => {:primary => true} do
auto_backup = if auto_backup?
with_additional_tags('auto-backup') do
remote.create
end
@@ -260,19 +260,19 @@
if !auto_backup? || auto_backup.present?
file = with_additional_tags('mirror') do
local.create
end
if file.present?
- DumpRake::Env.with_clean_env(:like => file) do
+ Dump::Env.with_clean_env(:like => file) do
local.upload
remote.restore
end
end
end
end
- desc 'Creates remote dump, downloads and restores on local' << DumpRake::Env.explain_variables_for_command(:mirror)
+ desc 'Creates remote dump, downloads and restores on local' << Dump::Env.explain_variables_for_command(:mirror)
task :down, :roles => :db, :only => {:primary => true} do
auto_backup = if auto_backup?
with_additional_tags('auto-backup') do
local.create
end
@@ -280,43 +280,43 @@
if !auto_backup? || auto_backup.present?
file = with_additional_tags('mirror') do
remote.create
end
if file.present?
- DumpRake::Env.with_clean_env(:like => file) do
+ Dump::Env.with_clean_env(:like => file) do
remote.download
local.restore
end
end
end
end
end
namespace :backup do
- desc 'Shorthand for dump:backup:create' << DumpRake::Env.explain_variables_for_command(:backup)
+ desc 'Shorthand for dump:backup:create' << Dump::Env.explain_variables_for_command(:backup)
task :default, :roles => :db, :only => {:primary => true} do
backup.create
end
- desc "Creates remote dump and downloads to local (desc defaults to 'backup')" << DumpRake::Env.explain_variables_for_command(:backup)
+ desc "Creates remote dump and downloads to local (desc defaults to 'backup')" << Dump::Env.explain_variables_for_command(:backup)
task :create, :roles => :db, :only => {:primary => true} do
file = with_additional_tags('backup') do
remote.create
end
if file.present?
- DumpRake::Env.with_clean_env(:like => file) do
+ Dump::Env.with_clean_env(:like => file) do
remote.download
end
end
end
- desc 'Uploads dump with backup tag and restores it on remote' << DumpRake::Env.explain_variables_for_command(:backup_restore)
+ desc 'Uploads dump with backup tag and restores it on remote' << Dump::Env.explain_variables_for_command(:backup_restore)
task :restore, :roles => :db, :only => {:primary => true} do
file = with_additional_tags('backup') do
last_part_of_last_line(run_local(dump_command(:versions)))
end
if file.present?
- DumpRake::Env.with_clean_env(:like => file) do
+ Dump::Env.with_clean_env(:like => file) do
local.upload
remote.restore
end
end
end