class Restic::Service::CLI

Public Instance Methods

auto(*targets) click to toggle source
# File lib/restic/service/cli.rb, line 160
def auto(*targets)
    STDOUT.sync = true
    conf = load_conf
    loop do
        puts "#{Time.now} Starting automatic synchronization pass"
        puts ""

        run_sync(conf, *targets)
        run_forget(conf, *targets)

        puts ""
        puts "#{Time.now} Finished automatic synchronization pass"

        sleep conf.period
    end
end
auto_update() click to toggle source
# File lib/restic/service/cli.rb, line 114
def auto_update
    conf = load_conf
    STDOUT.sync = true

    updater = AutoUpdate.new($0)
    if conf.auto_update_restic_service?
        puts "attempting to auto-update restic-service"
        old_version, new_version = updater.update_restic_service
        if old_version != new_version
            puts "updated restic-service from #{old_version} to #{new_version}, restarting"
            exec "bundle", "exec", Gem.ruby, $0, "auto-update"
        else
            puts "restic-service was already up-to-date: #{new_version}"
        end
    else
        puts "updating restic-service disabled in configuration"
    end

    if conf.auto_update_restic?
        auto_update_tool(conf, updater, 'restic', AutoUpdate::RESTIC_RELEASE_VERSION)
    else
        puts "updating restic disabled in configuration"
    end

    if conf.auto_update_rclone?
        auto_update_tool(conf, updater, 'rclone', AutoUpdate::RCLONE_RELEASE_VERSION)
    else
        puts "updating rclone disabled in configuration"
    end
end
auto_update_tool(conf, updater, name, version) click to toggle source
# File lib/restic/service/cli.rb, line 80
def auto_update_tool(conf, updater, name, version)
    begin
        path = conf.tool_path(name, only_if_present: false)
    rescue ArgumentError
        puts "cannot auto-update #{name}, provide an explicit path in the 'tools' section of the configuration first"
        return
    end

    puts "attempting to auto-update #{name}"
    if updater.send("update_#{name}", conf.send("#{name}_platform"), path)
        puts "updated #{name} to version #{version}"
    else
        puts "restic was already up-to-date"
    end
end
conf_dir_path() click to toggle source
# File lib/restic/service/cli.rb, line 13
def conf_dir_path
    @conf_dir_path ||= Pathname.new(options[:conf])
end
conf_file_path() click to toggle source
# File lib/restic/service/cli.rb, line 17
def conf_file_path
    @conf_file_path ||= (conf_dir_path + "conf.yml")
end
conf_keys_path() click to toggle source
# File lib/restic/service/cli.rb, line 21
def conf_keys_path
    @conf_keys_path ||= (conf_dir_path + "keys")
end
each_selected_and_available_target(conf, *targets) { |target| ... } click to toggle source
# File lib/restic/service/cli.rb, line 29
def each_selected_and_available_target(conf, *targets)
    has_target = false
    conf.each_target do |target|
        has_target = true
        if !targets.empty? && !targets.include?(target.name)
            next
        elsif !target.available?
            puts "#{target.name} is not available"
            next
        end

        yield(target)
    end

    if !has_target
        STDERR.puts "WARNING: no targets in #{options[:conf]}"
    end
end
forget(*targets) click to toggle source
# File lib/restic/service/cli.rb, line 153
def forget(*targets)
    STDOUT.sync = true
    conf = load_conf
    run_forget(conf, *targets)
end
install_restic(path, platform) click to toggle source
# File lib/restic/service/cli.rb, line 108
def install_restic(path, platform)
    updater = AutoUpdate.new($0)
    updater.update_restic(platform, path)
end
load_conf() click to toggle source
# File lib/restic/service/cli.rb, line 25
def load_conf
    Conf.load(conf_file_path)
end
restic(*args) click to toggle source
# File lib/restic/service/cli.rb, line 179
def restic(*args)
    conf = load_conf
    run_restic(conf, options[:targets], *args)
end
run_forget(conf, *targets) click to toggle source
# File lib/restic/service/cli.rb, line 57
def run_forget(conf, *targets)
    each_selected_and_available_target(conf, *targets) do |target|
        unless target.respond_to?(:forget)
            puts "#{target.name} does not supports forget"
            next
        end

        puts
        puts "-----"
        puts "#{Time.now} - Running forget pass on #{target.name}"
        target.forget
    end
end
run_restic(conf, targets, *args) click to toggle source
# File lib/restic/service/cli.rb, line 71
def run_restic(conf, targets, *args)
    each_selected_and_available_target(conf, *targets) do |target|
        if target.respond_to?(:run_restic)
            puts "Running command for #{target.name}"
            target.restic(*args)
        end
    end
end
run_sync(conf, *targets) click to toggle source
# File lib/restic/service/cli.rb, line 48
def run_sync(conf, *targets)
    each_selected_and_available_target(conf, *targets) do |target|
        puts
        puts "-----"
        puts "#{Time.now} - Synchronizing #{target.name}"
        target.run
    end
end
sync(*targets) click to toggle source
# File lib/restic/service/cli.rb, line 146
def sync(*targets)
    STDOUT.sync = true
    conf = load_conf
    run_sync(conf, *targets)
end
whereami() click to toggle source
# File lib/restic/service/cli.rb, line 98
def whereami
    STDOUT.sync = true
    conf = load_conf
    conf.each_target do |target|
        print "#{target.name}: "
        puts(target.available? ? 'yes' : 'no')
    end
end