Class: LSync::Methods::RSyncSnapshot

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

Instance Attribute Summary

Attributes inherited from LSync::Method

#logger

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



88
89
90
# File 'lib/lsync/methods/rsync.rb', line 88

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

#run(master_server, target_server, directory) ⇒ Object



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/lsync/methods/rsync.rb', line 92

def run(master_server, target_server, 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]

	dst_directory = File.join(inprogress_path, directory.to_s)

	local_server = nil
	remote_server = nil

	if @direction == :push
		local_server = master_server
		remote_server = target_server

		dst = remote_server.connection_string(dst_directory)
		src = local_server.full_path(directory)
	else
		local_server = target_server
		remote_server = master_server

		dst = local_server.full_path(dst_directory)
		src = remote_server.connection_string(directory)
	end

	arguments += connect_arguments(local_server, remote_server)

	# Create the destination backup directory
	@connection = target_server.connect
	@connection.send_object([:mkdir_p, target_server.full_path(dst_directory)])

	Dir.chdir(local_server.root) do
		if run_handler(src, dst, arguments) == false
			raise BackupMethodError.new("Backup from #{src.dump} to #{dst.dump} failed.", :method => self)
		end
	end
end