Sha256: 172dea82d1e45db916d6c2092df7aab7cacf7272554ca0afe9f0b40382afe56f

Contents?: true

Size: 901 Bytes

Versions: 11

Compression:

Stored size: 901 Bytes

Contents

require 'net/scp'

module Backup
  module Storage
    class SCP < Base
      
      attr_accessor :user, :password, :ip, :path, :tmp_path, :final_file
      
      # Stores the backup file on the remote server using SCP
      def initialize(adapter)
        %w(ip user password path).each do |method|
          send("#{method}=", adapter.procedure.get_storage_configuration.attributes[method])
        end
        
        final_file = adapter.final_file
        tmp_path   = adapter.tmp_path
        
        Net::SSH.start(ip, user, :password => password) do |ssh|
          ssh.exec "mkdir -p #{path}"
        end
        
        puts "Storing \"#{final_file}\" to path \"#{path}\" on remote server (#{ip})."
        Net::SCP.start(ip, user, :password => password) do |scp|
          scp.upload! File.join(tmp_path, final_file).gsub('\ ', ' '), path
        end
      end
      
    end
  end
end

Version data entries

11 entries across 11 versions & 3 rubygems

Version Path
backup-2.4.5.1 lib/backup/storage/scp.rb
backup-2.4.5 lib/backup/storage/scp.rb
namxam-backup-2.4.5 lib/backup/storage/scp.rb
backup-2.4.4 lib/backup/storage/scp.rb
backup-2.4.3 lib/backup/storage/scp.rb
backup-2.4.1 lib/backup/storage/scp.rb
dmitryv-backup-2.4.0 lib/backup/storage/scp.rb
backup-2.4.0 lib/backup/storage/scp.rb
backup-2.3.3.1 lib/backup/storage/scp.rb
backup-2.3.3 lib/backup/storage/scp.rb
backup-2.3.2 lib/backup/storage/scp.rb