Class: LSync::Methods::RSync
Instance Method Summary
collapse
#abort!, #fire, #on, #try
Constructor Details
#initialize(direction, options = {}) ⇒ RSync
Returns a new instance of RSync.
44
45
46
47
48
49
50
51
52
|
# File 'lib/lsync/methods/rsync.rb', line 44
def initialize(direction, options = {})
super(options)
@direction = direction
@command = options[:command] || "rsync"
@options = options
@connection = nil
end
|
Instance Method Details
#run(controller) ⇒ Object
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
# File 'lib/lsync/methods/rsync.rb', line 54
def run(controller)
directory = controller.directory
arguments = (@options[:arguments] || ["--archive"]) + (directory.options[:arguments] || [])
local_server = nil
remote_server = nil
if @direction == :push
local_server = controller.master
remote_server = controller.target
destination = remote_server.connection_string(directory)
source = local_server.full_path(directory)
else
local_server = controller.target
remote_server = controller.master
source = remote_server.connection_string(directory)
destination = local_server.full_path(directory)
end
arguments += connect_arguments(local_server, remote_server)
controller.target.exec!(["mkdir", "-p", controller.target.full_path(directory.path)])
controller.logger.info "In directory #{Dir.getwd}..."
Dir.chdir(local_server.root) do
if run_handler(controller, source, destination, arguments) == false
raise BackupMethodError.new("Backup from #{source} to #{destination} failed.", :method => self)
end
end
end
|
#run_command(controller, command) ⇒ Object
102
103
104
|
# File 'lib/lsync/methods/rsync.rb', line 102
def run_command(controller, command)
return LSync.run_command("/", command, controller.logger) == 0
end
|
#run_handler(controller, source, destination, arguments) ⇒ Object
88
89
90
|
# File 'lib/lsync/methods/rsync.rb', line 88
def run_handler(controller, source, destination, arguments)
run_command(controller, [@command] + arguments + [source, destination])
end
|
#should_run?(controller) ⇒ Boolean
92
93
94
95
96
97
98
99
100
|
# File 'lib/lsync/methods/rsync.rb', line 92
def should_run?(controller)
if @direction == :push
return controller.current == controller.master
elsif @direction == :pull
return controller.target.local?
else
return false
end
end
|