Class: Snapsync::Sync
- Inherits:
-
Object
- Object
- Snapsync::Sync
- Defined in:
- lib/snapsync/sync.rb
Overview
Single-target synchronization
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
- #target ⇒ SyncTarget readonly
Instance Method Summary collapse
-
#autoclean? ⇒ Boolean
Whether the target should be cleaned after synchronization.
-
#initialize(config, target, autoclean: nil) ⇒ Sync
constructor
A new instance of Sync.
- #remove_partially_synchronized_snapshots ⇒ Object
- #run ⇒ Object
-
#sync ⇒ Object
The method that performs synchronization.
Constructor Details
#initialize(config, target, autoclean: nil) ⇒ Sync
Returns a new instance of Sync.
9 10 11 12 13 14 15 16 |
# File 'lib/snapsync/sync.rb', line 9 def initialize(config, target, autoclean: nil) @config = config @target = target @autoclean = if autoclean.nil? then target.autoclean? else autoclean end end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
4 5 6 |
# File 'lib/snapsync/sync.rb', line 4 def config @config end |
Instance Method Details
#autoclean? ⇒ Boolean
Whether the target should be cleaned after synchronization.
This is determined either by #autoclean? if new was called with true or false, or by the target’s own autoclean flag if new was called with nil
23 24 25 |
# File 'lib/snapsync/sync.rb', line 23 def autoclean? @autoclean end |
#remove_partially_synchronized_snapshots ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/snapsync/sync.rb', line 35 def remove_partially_synchronized_snapshots btrfs_target = Btrfs.get(@target.dir) target.each_snapshot_raw do |path, snapshot, error| next if !error && !snapshot.partial? Snapsync.info "Removing partial snapshot at #{path}" begin if (path + "snapshot").exist? btrfs_target.run("subvolume", "delete", (path + "snapshot").path_part) elsif (path + "snapshot.partial").exist? btrfs_target.run("subvolume", "delete", (path + "snapshot.partial").path_part) end rescue Btrfs::Error => e Snapsync.warn "failed to remove snapshot at #{path}, keeping the rest of the snapshot" Snapsync.warn e. next end path.rmtree Snapsync.info "Flushing data to disk" begin btrfs_target.run("subvolume", "sync", path.path_part) rescue Btrfs::Error # Ignored end end end |
#run ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/snapsync/sync.rb', line 64 def run if autoclean? remove_partially_synchronized_snapshots end sync if autoclean? if target.cleanup Snapsync.info "running cleanup for #{target.dir}" target.cleanup.cleanup(target) else Snapsync.info "#{target.sync_policy.class.name} policy set, no cleanup to do for #{target.dir}" end else Snapsync.info "autoclean not set on #{target.dir}" end end |
#sync ⇒ Object
The method that performs synchronization
One usually wants to call #run, which also takes care of running cleanup if #autoclean? is true
31 32 33 |
# File 'lib/snapsync/sync.rb', line 31 def sync SnapshotTransfer.new(config, target).sync end |