Class: YOLOBackup::BackupRunner::Backend::Rsync
- Inherits:
-
YOLOBackup::BackupRunner::Backend
- Object
- YOLOBackup::BackupRunner::Backend
- YOLOBackup::BackupRunner::Backend::Rsync
- 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
-
#server ⇒ Object
readonly
Returns the value of attribute server.
Instance Method Summary collapse
-
#initialize(server) ⇒ Rsync
constructor
A new instance of Rsync.
- #start_backup ⇒ Object
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
#server ⇒ Object (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_backup ⇒ Object
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| = [DEFAULT_RSYNC_OPTIONS] if server.latest_backup latest_backup = File.("#{path}/../#{server.latest_backup}") << "--link-dest='#{latest_backup}'" end = [] << "-i '#{server.ssh_key}'" unless server.ssh_key.nil? << "-p '#{server.ssh_port}'" unless server.ssh_port.nil? << "-e \"ssh #{.join(' ')}\"" command = "rsync #{.join(' ')} #{server.ssh_user || 'root'}@#{server.ssh_host || server}:/ '#{path}'" puts command output = `#{command}` raise Error, "rsync command failed: #{$?}" unless $?.success? end end |