Class: LSync::Methods::RSync

Inherits:
LSync::Method show all
Defined in:
lib/lsync/methods/rsync.rb

Overview

0 Success 1 Syntax or usage error 2 Protocol incompatibility 3 Errors selecting input/output files, dirs 4 Requested action not supported: an attempt was made to manipulate 64-bit files on a platform

that cannot support them; or an option was specified that is supported by the client and not by the server.

5 Error starting client-server protocol 6 Daemon unable to append to log-file 10 Error in socket I/O 11 Error in file I/O 12 Error in rsync protocol data stream 13 Errors with program diagnostics 14 Error in IPC code 20 Received SIGUSR1 or SIGINT 21 Some error returned by waitpid() 22 Error allocating core memory buffers 23 Partial transfer due to error 24 Partial transfer due to vanished source files 25 The –max-delete limit stopped deletions 30 Timeout in data send/receive 35 Timeout waiting for daemon connection

Direct Known Subclasses

RSyncSnapshot

Instance Method Summary collapse

Methods included from EventHandler

#abort!, #fire, #on, #try

Constructor Details

#initialize(direction, options = {}) ⇒ RSync

Returns a new instance of RSync.


51
52
53
54
55
56
57
58
59
# File 'lib/lsync/methods/rsync.rb', line 51

def initialize(direction, options = {})
	super(options)

	@direction = direction
	@command = options[:command] || "rsync"

	@options = options
	@connection = nil
end

Instance Method Details

#run(controller) ⇒ Object


101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/lsync/methods/rsync.rb', line 101

def run(controller)
	directory = controller.directory
	arguments = (@options[:arguments] || ["--archive"]) + (directory.options[:arguments] || [])

	local_server, remote_server, source, destination = configuration(controller, controller.directory, controller.directory)

	arguments += connect_arguments(local_server, remote_server)

	# Create the destination backup directory
	controller.target.exec!(["mkdir", "-p", controller.target.full_path(directory.path)])

	run_handler(controller, local_server, source, destination, arguments)
end

#run_handler(controller, local_server, source, destination, arguments) ⇒ Object


115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/lsync/methods/rsync.rb', line 115

def run_handler(controller, local_server, source, destination, arguments)
	command = [@command] + arguments + [source, destination]

	local_server.exec(command) do |task|
		LSync::log_task(task, controller.logger)

		result = task.wait

		# Exit status 24 means that some files were deleted between indexing the data and copying it.
		unless result.exitstatus == 0 || result.exitstatus == 24
			raise BackupMethodError.new("Backup from #{source} to #{destination} failed.", :method => self)
		end
	end
end

#should_run?(controller) ⇒ Boolean

Returns:

  • (Boolean)

130
131
132
133
134
135
136
137
138
# File 'lib/lsync/methods/rsync.rb', line 130

def should_run?(controller)
	if @direction == :push
		return controller.current == controller.master
	elsif @direction == :pull
		return controller.target.local?
	else
		return false
	end
end