class Object
Public Instance Methods
auto_backup?()
click to toggle source
# File lib/dump/capistrano/v2.rb, line 157 def auto_backup? !Dump::Env.no?(:backup) end
do_transfer(direction, from, to)
click to toggle source
# File lib/dump/capistrano/v2.rb, line 90 def do_transfer(direction, from, to) via = Dump::Env[:transfer_via] case via && via.downcase when nil if got_rsync? do_transfer_via(:rsync, direction, from, to) else $stderr.puts 'To transfer using rsync — make rsync binary accessible and verify that remote host can work with rsync through ssh' begin do_transfer_via(:sftp, direction, from, to) rescue => e $stderr.puts e do_transfer_via(:scp, direction, from, to) end end when 'rsync' do_transfer_via(:rsync, direction, from, to) when 'sftp' do_transfer_via(:sftp, direction, from, to) when 'scp' do_transfer_via(:scp, direction, from, to) else fail "Unknown transfer method #{via}" end end
do_transfer_via(via, direction, from, to)
click to toggle source
# File lib/dump/capistrano/v2.rb, line 38 def do_transfer_via(via, direction, from, to) case via when :rsync if run_local('which rsync').present? && $CHILD_STATUS.success? execute_on_servers do |servers| commands = servers.map do |server| target = sessions[server] user = target.options[:user] || fetch(:user, nil) host = target.host port = target.options[:port] full_host = "#{"#{user}@" if user.present?}#{host}" ssh = port.present? ? "ssh -p #{port}" : 'ssh' cmd = %W[rsync -P -e #{ssh} --timeout=15] case direction when :up cmd << from << "#{full_host}:#{to}" when :down cmd << "#{full_host}:#{from}" << to else fail "Don't know how to transfer in direction #{direction}" end cmd.shelljoin end commands.each do |cmd| logger.info cmd if logger 3.times do break if system(cmd) break unless [10, 11, 12, 23, 30, 35].include?($CHILD_STATUS.exitstatus) end fail "rsync returned #{$CHILD_STATUS.exitstatus}" unless $CHILD_STATUS.success? end end end when :sftp, :scp 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 '100%' end $stderr << "\rTransfering: #{progress}" end end else fail "Unknown transfer method #{via}" end end
dump_command(command, env = {})
click to toggle source
# File lib/dump/capistrano/v2.rb, line 16 def dump_command(command, env = {}) rake = env.delete(:rake) || 'rake' # stringify_keys! from activesupport Dump::Env.stringify!(env) 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
fetch_rails_env()
click to toggle source
# File lib/dump/capistrano/v2.rb, line 29 def fetch_rails_env fetch(:rails_env, 'production') end
fetch_rake()
click to toggle source
# File lib/dump/capistrano/v2.rb, line 153 def fetch_rake fetch(:rake, nil) end
getbyte()
click to toggle source
# File lib/dump/archive_tar_minitar.rb, line 6 def getbyte return nil if @read >= @size ret = @io.getbyte @read += 1 if ret ret end
got_rsync?()
click to toggle source
# File lib/dump/capistrano/v2.rb, line 33 def got_rsync? `which rsync` $CHILD_STATUS.success? end
last_part_of_last_line(out)
click to toggle source
# File lib/dump/capistrano/v2.rb, line 148 def last_part_of_last_line(out) line = out.strip.split(/\s*[\n\r]\s*/).last line.split("\t").last if line end
print_and_return_or_fail() { || ... }
click to toggle source
# File lib/dump/capistrano/v2.rb, line 123 def print_and_return_or_fail out = yield fail 'Failed creating dump' if out.blank? print out out.strip end
run_local(cmd)
click to toggle source
# File lib/dump/capistrano/v2.rb, line 131 def run_local(cmd) `#{cmd}` end
run_remote(cmd)
click to toggle source
# File lib/dump/capistrano/v2.rb, line 135 def run_remote(cmd) output = '' run(cmd) do |_channel, io, data| case io when :out output << data when :err $stderr << data end end output end