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.



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

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



102
103
104
# File 'lib/backup/storage/rsync.rb', line 102

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.



69
70
71
# File 'lib/backup/storage/rsync.rb', line 69

def additional_ssh_options
  @additional_ssh_options
end

#compressObject

Flag for compressing (only compresses for the transfer)



106
107
108
# File 'lib/backup/storage/rsync.rb', line 106

def compress
  @compress
end

#hostObject

Server Address

If not specified, the storage operation will be local.



28
29
30
# File 'lib/backup/storage/rsync.rb', line 28

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.



22
23
24
# File 'lib/backup/storage/rsync.rb', line 22

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.



126
127
128
# File 'lib/backup/storage/rsync.rb', line 126

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.



38
39
40
# File 'lib/backup/storage/rsync.rb', line 38

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.



89
90
91
# File 'lib/backup/storage/rsync.rb', line 89

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.



98
99
100
# File 'lib/backup/storage/rsync.rb', line 98

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.



78
79
80
# File 'lib/backup/storage/rsync.rb', line 78

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.



53
54
55
# File 'lib/backup/storage/rsync.rb', line 53

def ssh_user
  @ssh_user
end