class Synco::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.
Attributes
directories[RW]
All directories which may be synchronised.
master[RW]
The master server name (e.g. symbolic or host name)
method[RW]
A specific method which will perform the backup (e.g. an instance of Synco::Method
)
servers[RW]
All servers which are participating in the backup process.
Public Class Methods
new(method: nil, servers: {}, directories: [], master: :master, logger: nil)
click to toggle source
Calls superclass method
Synco::Controller::new
# File lib/synco/script.rb, line 33 def initialize(method: nil, servers: {}, directories: [], master: :master, logger: nil) super() @method = method @servers = servers @directories = directories @master = master end
Public Instance Methods
current_server()
click to toggle source
# File lib/synco/script.rb, line 93 def current_server @current_server ||= find_current_server end
directories(*paths, **options, &block)
click to toggle source
Backup a particular path (or paths).
# File lib/synco/script.rb, line 104 def directories(*paths, **options, &block) paths.each do |path| @directories << Directory.build(path, **options, &block) end end
find_current_server()
click to toggle source
Find the server that matches the current machine
# File lib/synco/script.rb, line 82 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
find_named_server(name)
click to toggle source
Given a name, find out which server config matches it.
# File lib/synco/script.rb, line 65 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
Also aliased as: []
freeze()
click to toggle source
Calls superclass method
Synco::Controller#freeze
# File lib/synco/script.rb, line 42 def freeze current_server; master_server super end
localhost?(name)
click to toggle source
# File lib/synco/script.rb, line 56 def localhost?(name) return true if name == "localhost" host = resolve_name(Socket.gethostname) return name == host end
master_server()
click to toggle source
The master server based on the name master=
specified
# File lib/synco/script.rb, line 77 def master_server @master_server ||= find_named_server(@master) end
resolve_name(name)
click to toggle source
# File lib/synco/script.rb, line 52 def resolve_name(name) Socket.gethostbyname(name)[0] end
running_on_master?()
click to toggle source
# File lib/synco/script.rb, line 48 def running_on_master? current_server.same_host?(master_server) end
server(*arguments, **options, &block)
click to toggle source
Register a server with the backup script.
# File lib/synco/script.rb, line 98 def server(*arguments, **options, &block) server = Server.build(*arguments, **options, &block) @servers[server.name] = server end