Class: Restic::Service::Targets::RcloneB2

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

Instance Attribute Summary

Attributes inherited from Base

#name

Class Method Summary collapse

Instance Method Summary collapse

Methods included from B2

#available?, #initialize

Methods inherited from Base

#initialize

Class Method Details

.normalize_yaml(yaml) ⇒ Object



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

def self.normalize_yaml(yaml)
    yaml = B2.normalize_yaml(yaml)
    if !yaml['src']
        raise Conf::InvalidConfigurationFile, "no src field provided for rclone-b2"
    elsif !File.directory?(yaml['src'])
        raise Conf::InvalidConfigurationFile, "provided rclone-b2 source #{yaml['src']} does not exist"
    end
    yaml
end

Instance Method Details

#runObject



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

def run
    extra_args = []
    if @bandwidth_limit
        extra_args << '--bwlimit' << @bandwidth_limit.to_s
    end

    Tempfile.create "rclone-#{@name}", @conf_path.to_path, perm: 0600 do |io|
        io.puts "[restic-service]\ntype = b2\naccount = \#{@id}\nkey = \#{@key}\nendpoint =\n"
        io.flush
        system(@rclone_path.to_path,
            '--transfers', '16',
            '--config', io.path,
            *extra_args,
            'sync', @src, "restic-service:#{@bucket}/#{@path}", in: :close)
    end
end

#setup_from_conf(conf, yaml) ⇒ Object



17
18
19
20
21
22
# File 'lib/restic/service/targets/rclone_b2.rb', line 17

def setup_from_conf(conf, yaml)
    super
    @rclone_path = conf.tool_path('rclone')
    @src = yaml['src']
    @conf_path = conf.conf_path
end