Class: Backup::Storage::RSync

Inherits:
Base
  • Object
show all
Includes:
Utilities::Helpers
Defined in:
lib/backup/storage/rsync.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#keep, #model, #package, #storage_id

Instance Method Summary collapse

Methods inherited from Base

#perform!

Methods included from Config::Helpers

included

Constructor Details

#initialize(model, storage_id = nil) ⇒ RSync

Returns a new instance of RSync.



130
131
132
133
134
135
136
137
# File 'lib/backup/storage/rsync.rb', line 130

def initialize(model, storage_id = nil)
  super

  @mode ||= :ssh
  @port ||= mode == :rsync_daemon ? 873 : 22
  @compress ||= false
  @path ||= '~/backups'
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Backup::Config::Helpers

Instance Attribute Details

#additional_rsync_optionsObject

Additional String or Array of options for the rsync cli



104
105
106
# File 'lib/backup/storage/rsync.rb', line 104

def additional_rsync_options
  @additional_rsync_options
end

#additional_ssh_optionsObject

Additional SSH Options

Used to supply a String or Array of options to be passed to the SSH command in ‘:ssh` and `:ssh_daemon` modes.

For example, if you need to supply a specific SSH key for the ‘ssh_user`, you would set this to: “-i ’/path/to/id_rsa’”. Which would produce:

rsync -e "ssh -p 22 -i '/path/to/id_rsa'"

Arguments may be single-quoted, but should not contain any double-quotes.

Used only for ‘:ssh` and `:ssh_daemon` modes.



71
72
73
# File 'lib/backup/storage/rsync.rb', line 71

def additional_ssh_options
  @additional_ssh_options
end

#compressObject

Flag for compressing (only compresses for the transfer)



108
109
110
# File 'lib/backup/storage/rsync.rb', line 108

def compress
  @compress
end

#hostObject

Server Address

If not specified, the storage operation will be local.



30
31
32
# File 'lib/backup/storage/rsync.rb', line 30

def host
  @host
end

#modeObject

Mode of operation

:ssh (default)

Connects to the remote via SSH. Does not use an rsync daemon on the remote.

:ssh_daemon

Connects to the remote via SSH. Spawns a single-use daemon on the remote, which allows certain daemon features (like modules) to be used.

:rsync_daemon

Connects directly to an rsync daemon via TCP. Data transferred is not encrypted.



24
25
26
# File 'lib/backup/storage/rsync.rb', line 24

def mode
  @mode
end

#pathObject

Path to store the synced backup package file(s) to.

If no host is specified, then path will be local, and the only other used option would be additional_rsync_options. path will be expanded, so ‘~/my_path’ will expand to ‘$HOME/my_path’.

If a host is specified, this will be a path on the host. If mode is ‘:ssh` (default), then any relative path, or path starting with ’~/‘ will be relative to the directory the ssh_user is logged into. For `:ssh_daemon` or `:rsync_daemon` modes, this would reference an rsync module/path.

In :ssh_daemon and :rsync_daemon modes, path (or path defined by your rsync module) must already exist.

In :ssh mode or local operation (no host specified), path will be created if needed - either locally, or on the remote for :ssh mode.



128
129
130
# File 'lib/backup/storage/rsync.rb', line 128

def path
  @path
end

#portObject

SSH or RSync port

For ‘:ssh` or `:ssh_daemon` mode, this specifies the SSH port to use and defaults to 22.

For ‘:rsync_daemon` mode, this specifies the TCP port to use and defaults to 873.



40
41
42
# File 'lib/backup/storage/rsync.rb', line 40

def port
  @port
end

#rsync_passwordObject

RSync Password

If specified, Backup will write the password to a temporary file and use it with rsync’s ‘–password-file` option for daemon authentication.

Note that setting this will override ‘rsync_password_file`.

Used only for ‘:ssh_daemon` and `:rsync_daemon` modes.



91
92
93
# File 'lib/backup/storage/rsync.rb', line 91

def rsync_password
  @rsync_password
end

#rsync_password_fileObject

RSync Password File

If specified, this path will be passed to rsync’s ‘–password-file` option for daemon authentication.

Used only for ‘:ssh_daemon` and `:rsync_daemon` modes.



100
101
102
# File 'lib/backup/storage/rsync.rb', line 100

def rsync_password_file
  @rsync_password_file
end

#rsync_userObject

RSync User

If the user running the backup is not the same user that needs to authenticate with the rsync daemon, specify the user here.

Used only for ‘:ssh_daemon` and `:rsync_daemon` modes.



80
81
82
# File 'lib/backup/storage/rsync.rb', line 80

def rsync_user
  @rsync_user
end

#ssh_userObject

SSH User

If the user running the backup is not the same user that needs to authenticate with the remote server, specify the user here.

The user must have SSH keys setup for passphrase-less access to the remote. If the SSH User does not have passphrase-less keys, or no default keys in their ‘~/.ssh` directory, you will need to use the `-i` option in `:additional_ssh_options` to specify the passphrase-less key to use.

Used only for ‘:ssh` and `:ssh_daemon` modes.



55
56
57
# File 'lib/backup/storage/rsync.rb', line 55

def ssh_user
  @ssh_user
end