Class: IncrementalBackup::Rsync

Inherits:
Object
  • Object
show all
Defined in:
lib/incremental_backup/rsync.rb

Class Method Summary collapse

Class Method Details

.execute(logger, local_path, remote_path, options) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/incremental_backup/rsync.rb', line 5

def self.execute(logger, local_path, remote_path, options)
  # TODO: Only use long options
  rsync_options = {
    "-azprvP" => nil,
    "--delete" => nil,
    "--delete-excluded" => nil,
    "--modify-window" => '2',
    "--force" => nil,
    "--ignore-errors" => nil,
    "--stats" => nil
  }
  rsync_options["--exclude-from"] = options[:exclude_file] if options[:exclude_file]
  rsync_options["--link-dest"] = options[:link_dest] if options[:link_dest]

  rsync_options = rsync_options.map{|key, value| "#{key}#{value ? "=#{value}" : ''}" }.join(' ')

  rsync_command = "rsync #{rsync_options} -e ssh #{local_path} #{remote_path}"
  if options[:max_download_speed] || options[:max_upload_speed]
    trickle = "trickle"
    trickle += " -d #{options[:max_download_speed]}" if options[:max_download_speed]
    trickle += " -u #{options[:max_upload_speed]}" if options[:max_upload_speed]
    rsync_command = "#{trickle} #{rsync_command}"
  end

  execute_shell logger, rsync_command

end