Class: Backsum::Server
- Inherits:
-
Object
- Object
- Backsum::Server
- Defined in:
- lib/backsum/server.rb
Defined Under Namespace
Classes: Dsl
Instance Method Summary collapse
- #connect ⇒ Object
- #execute_rsync(backup_path, linkdest_path, connect, source, options) ⇒ Object
- #shell_param_escape(str) ⇒ Object
- #sync(backup_path, linkdest_path) ⇒ Object
Instance Method Details
#connect ⇒ Object
17 18 19 20 |
# File 'lib/backsum/server.rb', line 17 def connect return nil if local username ? "#{username}@#{host}" : host if host end |
#execute_rsync(backup_path, linkdest_path, connect, source, options) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/backsum/server.rb', line 28 def execute_rsync(backup_path, linkdest_path, connect, source, ) arguments = [ "--archive", "--delete" ] target_path = File.join(backup_path, self.host) arguments << "--verbose" if Backsum.verbose if linkdest_path linkdest_abosulte_path = File.absolute_path(linkdest_path) # rsync link dest must be abosulte path. linkdest_dir = File.join([linkdest_abosulte_path, self.host, [:as], "/"].compact) arguments << "--link-dest=#{linkdest_dir}" if File.exists?(linkdest_dir) end if [:as] target_path = File.join(target_path, [:as]) else arguments << "--relative" end FileUtils.mkdir_p target_path ([:excluded] || []).each do |pattern| arguments << "--exclude=#{pattern}" end source = File.join(source, "/") if File.directory?(source) if connect arguments << "#{connect}:#{source}" else arguments << source end arguments << target_path copy_command = Shell.new("rsync", arguments.map {|arg| shell_param_escape(arg) }.join(' ')) copy_command.run end |
#shell_param_escape(str) ⇒ Object
64 65 66 67 68 69 70 |
# File 'lib/backsum/server.rb', line 64 def shell_param_escape(str) if str.include? " " "'" + str.gsub("'", "\\'") + "'" else str end end |
#sync(backup_path, linkdest_path) ⇒ Object
22 23 24 25 26 |
# File 'lib/backsum/server.rb', line 22 def sync(backup_path, linkdest_path) self.folders.each_pair do |folder, | execute_rsync(backup_path, linkdest_path, connect, folder, ) end end |