class RsyncCommand
Converts capistrano-style ssh configuration (which uses Net::SSH) into a OpenSSH command line flags suitable for rsync.
For a list of the options normally support by Net::SSH (and thus Capistrano), see net-ssh.github.com/net-ssh/classes/Net/SSH.html#method-c-start
Also, to see how Net::SSH does the opposite of the conversion we are doing here, check out: github.com/net-ssh/net-ssh/blob/master/lib/net/ssh/config.rb
API mismatch:
-
many OpenSSH options not supported
-
some options only make sense for Net::SSH
-
compression: for Net::SSH, this option is supposed to accept true, false, or algorithm. OpenSSH accepts 'yes' or 'no'
Constants
- VERSION
Attributes
Public Class Methods
# File vendor/rsync_command/lib/rsync_command.rb, line 48 def initialize(options={}) @options = options.dup @logger = @options.delete(:logger) @flags = @options.delete(:flags) @failures = [] @failures.extend(MonitorMixin) end
Public Instance Methods
takes an Enumerable and iterates each item in the list in parallel.
# File vendor/rsync_command/lib/rsync_command.rb, line 59 def asynchronously(array, &block) pool = ThreadPool.new array.each do |item| pool.schedule(RsyncRunner.new(self), item, &block) end pool.shutdown end
build rsync command
# File vendor/rsync_command/lib/rsync_command.rb, line 98 def command(src, dest, options={}) src = remote_address(src) dest = remote_address(dest) options = @options.merge(options) flags = [] flags << @flags if @flags flags << options[:flags] if options.has_key?(:flags) flags << '--delete' if options[:delete] flags << includes(options[:includes]) if options.has_key?(:includes) flags << excludes(options[:excludes]) if options.has_key?(:excludes) flags << SshOptions.new(options[:ssh]).to_flags if options.has_key?(:ssh) "rsync #{flags.compact.join(' ')} #{src} #{dest}" end
# File vendor/rsync_command/lib/rsync_command.rb, line 124 def excludes(patterns) [patterns].flatten.compact.map { |p| "--exclude='#{p}'" } end
runs rsync, recording failures
# File vendor/rsync_command/lib/rsync_command.rb, line 77 def exec_rsync(src, dest, options={}) logger = options[:logger] || @logger @failures.synchronize do @failures.clear end rsync_cmd = command(src, dest, options) if options[:chdir] rsync_cmd = "cd '#{options[:chdir]}'; #{rsync_cmd}" end logger.debug rsync_cmd if logger ok = system(rsync_cmd) unless ok @failures.synchronize do @failures << {:source => src, :dest => dest, :options => options.dup} end end end
returns true if last exec returned a failure
# File vendor/rsync_command/lib/rsync_command.rb, line 70 def failed? @failures && @failures.any? end
# File vendor/rsync_command/lib/rsync_command.rb, line 128 def includes(patterns) [patterns].flatten.compact.map { |p| "--include='#{p}'" } end
Creates an rsync location if the address
is a hash with keys :user, :host, and :path (each component is optional). If address
is a string, we just pass it through.
# File vendor/rsync_command/lib/rsync_command.rb, line 116 def remote_address(address) if address.is_a? String address # assume it is already formatted. elsif address.is_a? Hash [[address[:user], address[:host]].compact.join('@'), address[:path]].compact.join(':') end end