Class: LSync::Methods::RSyncSnapshot

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

Instance Method Summary collapse

Methods inherited from RSync

#initialize, #run_command, #run_handler, #should_run?

Methods inherited from LSync::Method

#initialize, #should_run?

Methods included from EventHandler

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

Constructor Details

This class inherits a constructor from LSync::Methods::RSync

Instance Method Details

#inprogress_pathObject



108
109
110
# File 'lib/lsync/methods/rsync.rb', line 108

def inprogress_path
	@options[:inprogress_path] || "backup.inprogress"
end

#run(controller) ⇒ Object



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/lsync/methods/rsync.rb', line 112

def run(controller)
	directory = controller.directory
	arguments = (@options[:arguments] || []) + (directory.options[:arguments] || [])
	
	link_dest = Pathname.new("../" * (directory.path.depth + 1)) + "latest" + directory.path
	arguments += ['--archive', '--link-dest', link_dest.to_s]

	destination_directory = File.join(inprogress_path, directory.path)

	local_server = nil
	remote_server = nil

	if @direction == :push
		local_server = controller.master
		remote_server = controller.target

		destination = remote_server.connection_string(destination_directory)
		source = local_server.full_path(directory)
	else
		local_server = controller.target
		remote_server = controller.master

		destination = local_server.full_path(destination_directory)
		source = remote_server.connection_string(directory)
	end

	arguments += connect_arguments(local_server, remote_server)

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

	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