Class: Restic::Service::Targets::Rsync

Inherits:
Base
  • Object
show all
Includes:
SSHTarget
Defined in:
lib/restic/service/targets/rsync.rb

Instance Attribute Summary

Attributes inherited from Base

#name

Class Method Summary collapse

Instance Method Summary collapse

Methods included from SSHTarget

#available?, #initialize, #valid?, #with_ssh_config

Methods inherited from Base

#available?, #initialize, #nice_commands

Class Method Details

.normalize_yaml(yaml) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/restic/service/targets/rsync.rb', line 7

def self.normalize_yaml(yaml)
    yaml = super
    if !yaml['host']
        raise Conf::InvalidConfigurationFile, "no host given"
    elsif !yaml['source']
        raise Conf::InvalidConfigurationFile, "no source given"
    elsif !yaml['target']
        raise Conf::InvalidConfigurationFile, "no target given"
    end
    yaml
end

Instance Method Details

#run(*args, **options) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/restic/service/targets/rsync.rb', line 27

def run(*args, **options)
    extra_args = []
    if @one_file_system
        extra_args << "--one-file-system"
    end
    if @bandwidth_limit
        limit_KiB = @bandwidth_limit / 1000 
        extra_args << "--bwlimit=#{limit_KiB}"
    end

    home = ENV['HOME'] || '/root'

    with_ssh_config do |ssh_config_name|
        system(Hash['HOME' => home], *nice_commands,
               'rsync', '-a', '--delete-during', '--delete-excluded',
               *@filters.map { |arg| "--filter=#{arg}" },
               *extra_args, @source, "#{ssh_config_name}:#{@target}")
    end
end

#setup_from_conf(conf, yaml) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/restic/service/targets/rsync.rb', line 19

def setup_from_conf(conf, yaml)
    super
    @source = yaml.fetch('source')
    @target = yaml.fetch('target')
    @one_file_system = yaml.fetch('one_file_system', false)
    @filters = yaml.fetch('filters', [])
end