Class: YOLOBackup::BackupRunner::Backend::Rsync

Inherits:
YOLOBackup::BackupRunner::Backend show all
Defined in:
lib/yolo_backup/backup_runner/backend/rsync.rb

Defined Under Namespace

Classes: Error

Constant Summary collapse

DEFAULT_RSYNC_OPTIONS =
'-aAX --numeric-ids'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(server) ⇒ Rsync

Returns a new instance of Rsync.



10
11
12
# File 'lib/yolo_backup/backup_runner/backend/rsync.rb', line 10

def initialize(server)
  @server = server
end

Instance Attribute Details

#serverObject (readonly)

Returns the value of attribute server.



8
9
10
# File 'lib/yolo_backup/backup_runner/backend/rsync.rb', line 8

def server
  @server
end

Instance Method Details

#start_backupObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/yolo_backup/backup_runner/backend/rsync.rb', line 14

def start_backup
  server.storage.initiate_backup(server) do |path|
    options = [DEFAULT_RSYNC_OPTIONS]
    if server.latest_backup
      latest_backup = File.expand_path("#{path}/../#{server.latest_backup}")
      options << "--link-dest='#{latest_backup}'"
    end
    ssh_options = []
    ssh_options << "-i '#{server.ssh_key}'" unless server.ssh_key.nil?
    ssh_options << "-p '#{server.ssh_port}'" unless server.ssh_port.nil?
    options << "-e \"ssh #{ssh_options.join(' ')}\""
    command = "rsync #{options.join(' ')} #{server.ssh_user || 'root'}@#{server.ssh_host || server}:/ '#{path}'"
    puts command
    output = `#{command}`
    raise Error, "rsync command failed: #{$?}" unless $?.success?
  end
end