Class: BigBackup::Uploader::Ftp

Inherits:
Base
  • Object
show all
Defined in:
lib/big_backup/uploader/ftp.rb

Instance Method Summary collapse

Methods inherited from Base

#archive_databases, #archive_directories, #backup_config, #backup_databases, #error_message, #exec_cmd, #ok_message, #start, #start_message, #upload_databases, #upload_directories

Constructor Details

#initialize(config) ⇒ Ftp

Returns a new instance of Ftp.



5
6
7
8
# File 'lib/big_backup/uploader/ftp.rb', line 5

def initialize(config)
  super(config)
  @ftp_config = self.uploader_config['ftp']
end

Instance Method Details

#upload(backup_dir, timestamp) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/big_backup/uploader/ftp.rb', line 10

def upload(backup_dir, timestamp)
  Net::FTP.open(@ftp_config["ip"]) do |connection|
    connection.(@ftp_config["user"].to_s, @ftp_config["passwd"])

    if @config.kind_of?(Array)
      @config.each do |dir|
        connection.put("/tmp/bigbackup/#{File.basename(dir)}.tar.gz", "#{backup_dir}/#{File.basename(dir)}.tar.gz")
      end
    elsif @config.kind_of?(Hash)
      @config.each_key do |database_name|
        connection.put("/tmp/bigbackup/#{database_name}_#{timestamp}.tar.gz", "#{backup_dir}/#{database_name}_#{timestamp}.tar.gz")
      end
    end

  end
end