Sha256: 48c5035652bcff1ddd9b4ebf42ae0ebc1a4ea39858888c021abe896983b0655e

Contents?: true

Size: 946 Bytes

Versions: 5

Compression:

Stored size: 946 Bytes

Contents

module Backup
  module Storage
    class SFTP
      
      attr_accessor :user, :password, :ip, :path, :tmp_path, :final_file
      
      # Stores the backup file on the remote server using SFTP
      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::SFTP.start(ip, user, :password => password) do |sftp|
          begin
            puts "Storing \"#{final_file}\" to path \"#{path}\" on remote server (#{ip})."
            sftp.upload!(File.join(tmp_path, final_file).gsub('\ ', ' '), File.join(path, final_file))
          rescue
            puts "Could not find \"#{path}\" on \"#{ip}\", please ensure this directory exists."
            exit
          end
        end
      end
      
    end
  end
end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
backup-gundua-2.3.1.2 lib/backup/storage/sftp.rb
backup-gundua-2.3.1.1 lib/backup/storage/sftp.rb
backup-2.3.1 lib/backup/storage/sftp.rb
backup-2.3.0.3 lib/backup/storage/sftp.rb
backup-2.3.0.2 lib/backup/storage/sftp.rb