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
Returns Rsync syntax for setting a password (via a file).
-
#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
#mkdir, #raise_if_command_not_found!, #rm, #run, #utility
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
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/backup/syncer/rsync.rb', line 48 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? write_password_file! @path = path.sub(/^\~\//, '') end |
Instance Attribute Details
#additional_options ⇒ Object
Additional options for the rsync cli
41 42 43 |
# File 'lib/backup/syncer/rsync.rb', line 41 def @additional_options end |
#compress ⇒ Object
Returns Rsync syntax for compressing the file transfers
90 91 92 |
# File 'lib/backup/syncer/rsync.rb', line 90 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
115 116 117 118 119 120 121 122 |
# File 'lib/backup/syncer/rsync.rb', line 115 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
17 18 19 |
# File 'lib/backup/syncer/rsync.rb', line 17 def ip @ip end |
#mirror ⇒ Object
Returns Rsync syntax for enabling mirroring
84 85 86 |
# File 'lib/backup/syncer/rsync.rb', line 84 def mirror '--delete' if @mirror end |
#password ⇒ Object
Returns Rsync syntax for setting a password (via a file)
13 14 15 |
# File 'lib/backup/syncer/rsync.rb', line 13 def password @password end |
#path ⇒ Object
Path to store the synced files/directories to
29 30 31 |
# File 'lib/backup/syncer/rsync.rb', line 29 def path @path end |
#port ⇒ Object
Returns Rsync syntax for defining a port to connect to
102 103 104 |
# File 'lib/backup/syncer/rsync.rb', line 102 def port "--port='#{@port}'" end |
#username ⇒ Object
Server credentials
13 14 15 |
# File 'lib/backup/syncer/rsync.rb', line 13 def username @username end |
Instance Method Details
#add(path) ⇒ Object
Adds a path to the @directories array
126 127 128 |
# File 'lib/backup/syncer/rsync.rb', line 126 def add(path) @directories << path end |
#archive ⇒ Object
Returns Rsync syntax for invoking “archive” mode
96 97 98 |
# File 'lib/backup/syncer/rsync.rb', line 96 def archive '--archive' end |
#options ⇒ Object
Returns all the specified Rsync options, concatenated, ready for the CLI
78 79 80 |
# File 'lib/backup/syncer/rsync.rb', line 78 def ([archive, mirror, compress, port, password] + ).compact.join("\s") end |
#perform! ⇒ Object
Performs the RSync operation debug options: -vhP
67 68 69 70 71 72 73 74 |
# File 'lib/backup/syncer/rsync.rb', line 67 def perform! Logger.("#{ self.class } started syncing #{ directories }.") Logger.silent( run("#{ utility(:rsync) } -vhP #{ } #{ directories } '#{ username }@#{ ip }:#{ path }'") ) remove_password_file! end |