class Snapsync::SyncAll

Synchronizes all snapshots to a directory

A snapshot will be synchronized if (1) the target directory has a subdirectory of the config's name and (2) this directory is not disabled through its config file

Attributes

config_dir[R]

The path to the directory containing snapper configuration files

target_dir[R]

The path to the root directory to which we should sync

Public Class Methods

new(target_dir, config_dir: Pathname.new('/etc/snapper/configs'), autoclean: nil) click to toggle source

Creates a sync-all operation for the given target directory

@param [Pathname] target_dir the target directory @param [Boolean,nil] autoclean if true or false, will control

whether the targets should be cleaned of obsolete snapshots
after synchronization. If nil (the default), the target's own
autoclean flag will be used to determine this
# File lib/snapsync/sync_all.rb, line 20
def initialize(target_dir, config_dir: Pathname.new('/etc/snapper/configs'), autoclean: nil)
    @config_dir = config_dir
    @target_dir = target_dir
    @autoclean  = autoclean
end

Public Instance Methods

autoclean?() click to toggle source

Whether the target should be forced to autoclean(true), force to not run cleanup (false) or use their own config file to decide (nil)

The default is nil

@return [Boolean,nil]

# File lib/snapsync/sync_all.rb, line 32
def autoclean?
    @autoclean
end
each_target() { |config, local_target| ... } click to toggle source

Enumerate the targets available under {#target_dir}

# File lib/snapsync/sync_all.rb, line 37
def each_target
    SnapperConfig.each_in_dir(config_dir) do |config|
        dir = target_dir + config.name
        if !dir.exist?
            Snapsync.warn "no directory for configuration #{config.name} in #{target_dir}"
        else
            yield(config, LocalTarget.new(dir))
        end
    end
end
run() click to toggle source
# File lib/snapsync/sync_all.rb, line 48
def run
    each_target do |config, target|
        if !target.enabled?
            Snapsync.warn "not synchronizing to #{target.dir}, it is disabled"
            next
        end
        begin
            Sync.new(config, target, autoclean: autoclean?).run
        rescue Interrupt
            raise
        rescue Exception => e
            Snapsync.warn "failed to synchronize #{config.name} on #{target.dir}"
            PP.pp(e, buffer = String.new)
            buffer.each_line do |line|
                Snapsync.warn "  #{line.chomp}"
            end
            e.backtrace.each do |line|
                Snapsync.debug "  #{line}"
            end
        end
    end
end