Class: Backup::Syncer::RSync
Instance Attribute Summary collapse
-
#additional_options ⇒ Object
Additional options for the rsync cli.
-
#compress ⇒ Object
Returns Rsync syntax for compressing the file transfers.
-
#directories(&block) ⇒ Object
If no block has been provided, it’ll return the array of @directories.
-
#ip ⇒ Object
Server IP Address and SSH port.
-
#mirror ⇒ Object
Returns Rsync syntax for enabling mirroring.
-
#password ⇒ Object
Server credentials.
-
#path ⇒ Object
Path to store the synced files/directories to.
-
#port ⇒ Object
Returns Rsync syntax for defining a port to connect to.
-
#username ⇒ Object
Server credentials.
Instance Method Summary collapse
-
#add(path) ⇒ Object
Adds a path to the @directories array.
-
#archive ⇒ Object
Returns Rsync syntax for invoking “archive” mode.
-
#initialize(&block) ⇒ RSync
constructor
Instantiates a new RSync Syncer object and sets the default configuration specified in the Backup::Configuration::Syncer::RSync.
-
#options ⇒ Object
Returns all the specified Rsync options, concatenated, ready for the CLI.
-
#perform! ⇒ Object
Performs the RSync operation debug options: -vhP.
Methods included from Configuration::Helpers
#clear_defaults!, #getter_methods, #load_defaults!, #setter_methods
Methods included from CLI
Constructor Details
#initialize(&block) ⇒ RSync
Instantiates a new RSync Syncer object and sets the default configuration specified in the Backup::Configuration::Syncer::RSync. Then it sets the object defaults if particular properties weren’t set. Finally it’ll evaluate the users configuration file and overwrite anything that’s been defined
44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/backup/syncer/rsync.rb', line 44 def initialize(&block) load_defaults! @directories = Array.new @additional_options ||= Array.new @path ||= 'backups' @port ||= 22 @mirror ||= false @compress ||= false instance_eval(&block) if block_given? @path = path.sub(/^\~\//, '') end |
Instance Attribute Details
#additional_options ⇒ Object
Additional options for the rsync cli
37 38 39 |
# File 'lib/backup/syncer/rsync.rb', line 37 def @additional_options end |
#compress ⇒ Object
Returns Rsync syntax for compressing the file transfers
81 82 83 |
# File 'lib/backup/syncer/rsync.rb', line 81 def compress '--compress' if @compress end |
#directories(&block) ⇒ Object
If no block has been provided, it’ll return the array of @directories. If a block has been provided, it’ll evaluate it and add the defined paths to the @directories
100 101 102 103 104 105 106 107 |
# File 'lib/backup/syncer/rsync.rb', line 100 def directories(&block) unless block_given? return @directories.map do |directory| "'#{directory}'" end.join("\s") end instance_eval(&block) end |
#ip ⇒ Object
Server IP Address and SSH port
13 14 15 |
# File 'lib/backup/syncer/rsync.rb', line 13 def ip @ip end |
#mirror ⇒ Object
Returns Rsync syntax for enabling mirroring
75 76 77 |
# File 'lib/backup/syncer/rsync.rb', line 75 def mirror '--delete' if @mirror end |
#password ⇒ Object
Server credentials
9 10 11 |
# File 'lib/backup/syncer/rsync.rb', line 9 def password @password end |
#path ⇒ Object
Path to store the synced files/directories to
25 26 27 |
# File 'lib/backup/syncer/rsync.rb', line 25 def path @path end |
#port ⇒ Object
Returns Rsync syntax for defining a port to connect to
93 94 95 |
# File 'lib/backup/syncer/rsync.rb', line 93 def port "--port='#{@port}'" end |
#username ⇒ Object
Server credentials
9 10 11 |
# File 'lib/backup/syncer/rsync.rb', line 9 def username @username end |
Instance Method Details
#add(path) ⇒ Object
Adds a path to the @directories array
111 112 113 |
# File 'lib/backup/syncer/rsync.rb', line 111 def add(path) @directories << path end |
#archive ⇒ Object
Returns Rsync syntax for invoking “archive” mode
87 88 89 |
# File 'lib/backup/syncer/rsync.rb', line 87 def archive '--archive' end |
#options ⇒ Object
Returns all the specified Rsync options, concatenated, ready for the CLI
69 70 71 |
# File 'lib/backup/syncer/rsync.rb', line 69 def ([archive, mirror, compress, port] + ).compact.join("\s") end |
#perform! ⇒ Object
Performs the RSync operation debug options: -vhP
62 63 64 65 |
# File 'lib/backup/syncer/rsync.rb', line 62 def perform! Logger.("#{ self.class } started syncing #{ directories }.") Logger.silent( run("#{ utility(:rsync) } -vhP #{ } #{ directories } '#{ username }@#{ ip }:#{ path }'") ) end |