Class: Outback::SftpTarget

Inherits:
Target show all
Defined in:
lib/outback/sftp_target.rb

Instance Attribute Summary collapse

Attributes inherited from Target

#backup_name

Instance Method Summary collapse

Methods inherited from Target

#purge!

Methods included from Logging

#logger

Methods included from Configurable

#attr_setter, included

Constructor Details

#initialize(backup_name, host) ⇒ SftpTarget

Returns a new instance of SftpTarget.



9
10
11
12
# File 'lib/outback/sftp_target.rb', line 9

def initialize(backup_name, host)
  super(backup_name)
  @host = host
end

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



6
7
8
# File 'lib/outback/sftp_target.rb', line 6

def host
  @host
end

Instance Method Details

#put(archives) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/outback/sftp_target.rb', line 22

def put(archives)
  size = count = 0
  connect do
    archives.each do |archive|
      basename = archive.filename.basename.to_s
      upload_filename = path ? File.join(path, basename) : basename
      logger.debug "SftpTarget: storing #{archive.filename} in sftp://#{user}@#{host}#{':' + port.to_s if port}:#{upload_filename}"
      connection.upload!(archive.filename.to_s, upload_filename)
      size += archive.size
      count += 1
    end
  end
  logger.info "Uploaded #{count} archives (#{size} bytes) to #{self}"
  count
end

#to_sObject



18
19
20
# File 'lib/outback/sftp_target.rb', line 18

def to_s
  "sftp:#{user}@#{host}#{':' + port.to_s if port}:#{path}"
end

#valid?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/outback/sftp_target.rb', line 14

def valid?
  host.present?
end