SyncoSourceSyncoScript

class Script

The main backup/synchronisation mechanism is the backup script. It specifies all servers and directories, and these are then combined specifically to produce the desired data replication behaviour.

Definitions

def find_named_server(name)

Given a name, find out which server config matches it.

Implementation

def find_named_server(name)
	if @servers.key? name
		@servers[name]
	else
		host = resolve_name(name)
		@servers.values.find{|server| server.host == host}
	end
end

def master_server

The master server based on the name #master= specified

Implementation

def master_server
	@master_server ||= find_named_server(@master)
end

def find_current_server

Find the server that matches the current machine

Implementation

def find_current_server
	# There might be the case that the the local machine is both the master server and the backup server..
	# thus we check first if the master server is the local machine:
	if master_server and localhost?(master_server.host)
		@master_server
	else
		# Find a server config that specifies the local host
		@servers.values.find{|server| localhost?(server.host)}
	end || Server.new("localhost")
end

def server(*arguments, **options, &block)

Register a server with the backup script.

Implementation

def server(*arguments, **options, &block)
	server = Server.build(*arguments, **options, &block)
	@servers[server.name] = server
end

def directories(*paths, **options, &block)

Backup a particular path (or paths).

Implementation

def directories(*paths, **options, &block)
	paths.each do |path|
		@directories << Directory.build(path, **options, &block)
	end
end

attr_accessor :directories

All directories which may be synchronised.

attr_accessor :master

The master server name (e.g. symbolic or host name)

attr_accessor :method

A specific method which will perform the backup (e.g. an instance of Synco::Method)

attr_accessor :servers

All servers which are participating in the backup process.