Class: Publisher::Rsync
- Inherits:
-
Object
- Object
- Publisher::Rsync
- Defined in:
- lib/depengine/publisher/rsync.rb
Instance Attribute Summary collapse
-
#remote_host ⇒ Object
Returns the value of attribute remote_host.
-
#remote_user ⇒ Object
Returns the value of attribute remote_user.
-
#ssh_key_file ⇒ Object
Returns the value of attribute ssh_key_file.
Instance Method Summary collapse
Instance Attribute Details
#remote_host ⇒ Object
Returns the value of attribute remote_host.
3 4 5 |
# File 'lib/depengine/publisher/rsync.rb', line 3 def remote_host @remote_host end |
#remote_user ⇒ Object
Returns the value of attribute remote_user.
4 5 6 |
# File 'lib/depengine/publisher/rsync.rb', line 4 def remote_user @remote_user end |
#ssh_key_file ⇒ Object
Returns the value of attribute ssh_key_file.
5 6 7 |
# File 'lib/depengine/publisher/rsync.rb', line 5 def ssh_key_file @ssh_key_file end |
Instance Method Details
#sync(source, target, options = {}) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/depengine/publisher/rsync.rb', line 7 def sync(source, target, = {}) # default options = ['-a'] if [:local].nil? or [:local] == false Helper.validates_presence_of remote_host, 'Remote Host not set' Helper.validates_presence_of remote_user, 'Remote User not set' Helper.validates_presence_of ssh_key_file, 'SSH-Keyfile not set' target = "#{remote_user}@#{remote_host}:" + target << "-e \'ssh -c arcfour -o StrictHostKeyChecking=no -i #{ssh_key_file}\'" end rsync = [:rsync_bin] || 'rsync' if not [:delete].nil? and [:delete] == true << '--delete' end if not [:whole_file].nil? and [:whole_file] == true << '-W' end unless [:rsync_path].nil? << "--rsync-path=#{[:rsync_path]}" end if [:one_filesystem].nil? or [:one_filesystem] == true << '-x' end if [:compression].nil? or [:compression] == true << '-z' end unless [:exclude].nil? [[:exclude]].flatten.each do |current_exclude| next unless current_exclude > '' << "--exclude #{current_exclude}" end end # sync options # options[:delete] default false # options[:whole_file] default false # options[:one_filesystem] default true # options[:compression] default true # TODO: ssh-agent preload key with passphrase begin $log.writer.debug "#{rsync} #{.join(' ')} #{source} #{target}" stdout = `#{rsync} #{.join(' ')} \"#{source}\" \"#{target}\"` $log.writer.debug stdout unless RUBY_VERSION < '1.9' fail 'rsync execution error' if $CHILD_STATUS.exitstatus != 0 end rescue => e $log.writer.error "Can not sync directory #{source} with #{target}" $log.writer.error e. $log.writer.error e.backtrace.join("\n") exit 1 end end |