class Backup::Storage::SCP
Attributes
ip[RW]
Server IP Address and SCP port
password[RW]
Server credentials
port[RW]
Server IP Address and SCP port
ssh_options[RW]
Server credentials
username[RW]
Server credentials
Public Class Methods
new(model, storage_id = nil)
click to toggle source
Calls superclass method
Backup::Storage::Base.new
# File lib/backup/storage/scp.rb, line 17 def initialize(model, storage_id = nil) super @port ||= 22 @path ||= 'backups' @ssh_options ||= {} path.sub!(/^~\//, '') end
Private Instance Methods
connection() { |ssh| ... }
click to toggle source
# File lib/backup/storage/scp.rb, line 28 def connection Net::SSH.start( ip, username, { :password => password, :port => port }.merge(ssh_options) ) {|ssh| yield ssh } end
remove!(package)
click to toggle source
Called by the Cycler. Any error raised will be logged as a warning.
# File lib/backup/storage/scp.rb, line 49 def remove!(package) Logger.info "Removing backup package dated #{ package.time }..." errors = [] connection do |ssh| ssh.exec!("rm -r '#{ remote_path_for(package) }'") do |ch, stream, data| errors << data if stream == :stderr end end unless errors.empty? raise Error, "Net::SSH reported the following errors:\n" + errors.join("\n") end end
transfer!()
click to toggle source
# File lib/backup/storage/scp.rb, line 34 def transfer! connection do |ssh| ssh.exec!("mkdir -p '#{ remote_path }'") package.filenames.each do |filename| src = File.join(Config.tmp_path, filename) dest = File.join(remote_path, filename) Logger.info "Storing '#{ ip }:#{ dest }'..." ssh.scp.upload!(src, dest) end end end