Sha256: cc8b47f7421a2fccf017dcd6c4caf027e40166dc9824bf79b1a811193fd77790
Contents?: true
Size: 1.6 KB
Versions: 2
Compression:
Stored size: 1.6 KB
Contents
# frozen_string_literal: true require "net/scp" module Backup module Storage class SCP < Base include Storage::Cycler class Error < Backup::Error; end ## # Server credentials attr_accessor :username, :password, :ssh_options ## # Server IP Address and SCP port attr_accessor :ip, :port def initialize(model, storage_id = nil) super @port ||= 22 @path ||= "backups".dup @ssh_options ||= {} path.sub!(%r{^~/}, "") end private def connection Net::SSH.start( ip, username, { password: password, port: port }.merge(ssh_options) ) { |ssh| yield ssh } end 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 # Called by the Cycler. # Any error raised will be logged as a warning. def remove!(package) Logger.info "Removing backup package dated #{package.time}..." errors = [] connection do |ssh| ssh.exec!("rm -r '#{remote_path_for(package)}'") do |_, 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 end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
backupii-0.1.0.pre.alpha.2 | lib/backup/storage/scp.rb |
backupii-0.1.0.pre.alpha.1 | lib/backup/storage/scp.rb |