snapsync 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 75228e89d473612d045f56e995ddc5492506a119
4
- data.tar.gz: 476af2e900213d61aa7fd9c5d606f33ca33df4d8
3
+ metadata.gz: dba428d67c91dbc087576e7127910fe46aec8304
4
+ data.tar.gz: d530b254f9cdd7ca46c9d8e2d43ce6c64133afac
5
5
  SHA512:
6
- metadata.gz: 2aafcd762a596944cf0d1997b92e2e3a74ff9daa19e706529ce6f26e4d697202c7223b0e80075cc1653a8ed0322173321bee62abf29fd573bf251cf579071eca
7
- data.tar.gz: e3e0b871f358c5a76cfcaa09a5d3d88b8614dbcb623fbc91fa04f4d8232ce4fd8bf76539153c4ce3b319d699184f690efaddfc4dfa160220615b488676601975
6
+ metadata.gz: f41595ef065834ee02890fde9fbdd7b94fa8c3197ed3808435e5d7f769e1be62201b41201772ae4651ececbadfcb38b3ac3809dc8be2425944250fc9205d4bba
7
+ data.tar.gz: 33cabe605c668f31b3d05ae704284f22ed312a108ced80741903c407a7d15f6b4ac87af17486664b3c82d4e287b9b4dddb7fd4003bf6c08415dc2fa7a405d5ee
@@ -146,7 +146,7 @@ module Snapsync
146
146
  end
147
147
  end
148
148
 
149
- def run(period: 60)
149
+ def run(period: 600)
150
150
  while true
151
151
  each_available_autosync_target do |path, t|
152
152
  Snapsync.info "sync-all on #{path} (partition #{t.partition_uuid})"
@@ -19,15 +19,26 @@ module Snapsync
19
19
 
20
20
  def self.popen(*args, mode: 'r', raise_on_error: true, **options)
21
21
  err_r, err_w = IO.pipe
22
- result = IO.popen(['btrfs', *args, err: err_w, **options], mode) do |io|
22
+
23
+ block_error, block_result = nil
24
+ IO.popen(['btrfs', *args, err: err_w, **options], mode) do |io|
23
25
  err_w.close
24
- yield(io)
26
+ begin
27
+ block_result = yield(io)
28
+ rescue Error
29
+ raise
30
+ rescue Exception => block_error
31
+ end
25
32
  end
26
33
 
27
- if $?.success?
28
- result
34
+ if $?.success? && !block_error
35
+ block_result
29
36
  elsif raise_on_error
30
- raise Error.new, "btrfs failed"
37
+ if block_error
38
+ raise Error.new, block_error.message
39
+ else
40
+ raise Error.new, "btrfs failed"
41
+ end
31
42
  end
32
43
 
33
44
  rescue Error => e
@@ -36,7 +36,10 @@ module Snapsync
36
36
  if !deleted_snapshots.empty?
37
37
  Snapsync.info "Waiting for subvolumes to be deleted"
38
38
  deleted_snapshots.each do |s|
39
- IO.popen(["btrfs", "subvolume", "sync", s.subvolume_dir.to_s, err: '/dev/null']).read
39
+ begin
40
+ Btrfs.popen("subvolume", "sync", s.subvolume_dir.to_s)
41
+ rescue Btrfs::Error
42
+ end
40
43
  end
41
44
  end
42
45
  end
@@ -231,7 +231,9 @@ While it can easily be done manually, this command makes sure that the snapshots
231
231
  desc 'list [DIR]', 'list the snapshots present on DIR. If DIR is omitted, tries to access all targets defined as auto-sync targets'
232
232
  def list(dir = nil)
233
233
  handle_class_options
234
+ matched_uuids = Set.new
234
235
  each_target(dir) do |_, target|
236
+ matched_uuids << target.uuid
235
237
  puts "== #{target.dir}"
236
238
  puts "UUID: #{target.uuid}"
237
239
  puts "Enabled: #{target.enabled?}"
@@ -84,7 +84,7 @@ module Snapsync
84
84
 
85
85
  if copy_snapshot(target_snapshot_dir, src, parent: parent)
86
86
  partial_marker_path.unlink
87
- IO.popen(["btrfs", "filesystem", "sync", target_snapshot_dir.to_s, err: '/dev/null']).read
87
+ Btrfs.popen("filesystem", "sync", target_snapshot_dir.to_s)
88
88
  Snapsync.info "Successfully synchronized #{src.snapshot_dir}"
89
89
  true
90
90
  end
@@ -136,15 +136,18 @@ module Snapsync
136
136
  Snapsync.info "Removing snapshot #{s.num} #{s.date.to_time} at #{s.subvolume_dir}"
137
137
  return if dry_run
138
138
 
139
- IO.popen(["btrfs", "subvolume", "delete", s.subvolume_dir.to_s, err: '/dev/null']) do |io|
140
- io.read
141
- end
142
- if $?.success?
143
- s.snapshot_dir.rmtree
144
- Snapsync.info "Flushing data to disk"
145
- IO.popen(["btrfs", "filesystem", "sync", s.snapshot_dir.to_s, err: '/dev/null']).read
146
- else
139
+ begin
140
+ Btrfs.popen("subvolume", "delete", s.subvolume_dir.to_s)
141
+ rescue Btrfs::Error
147
142
  Snapsync.warn "failed to remove snapshot at #{s.subvolume_dir}, keeping the rest of the snapshot"
143
+ return
144
+ end
145
+
146
+ s.snapshot_dir.rmtree
147
+ Snapsync.info "Flushing data to disk"
148
+ begin
149
+ Btrfs.popen("subvolume", "sync", s.subvolume_dir.to_s)
150
+ rescue Btrfs::Error
148
151
  end
149
152
  end
150
153
  end
@@ -134,7 +134,9 @@ module Snapsync
134
134
  end
135
135
 
136
136
  xml = REXML::Document.new(info_xml.read)
137
- if xml.root.name != 'snapshot'
137
+ if !xml.root
138
+ raise InvalidInfoFile, "#{snapshot_dir}/info.xml does not look like a snapper info file (not an XML file ?)"
139
+ elsif xml.root.name != 'snapshot'
138
140
  raise InvalidInfoFile, "#{snapshot_dir}/info.xml does not look like a snapper info file (root is not 'snapshot')"
139
141
  end
140
142
 
@@ -56,10 +56,10 @@ module Snapsync
56
56
  rescue Interrupt
57
57
  raise
58
58
  rescue Exception => e
59
- Snapsync.warn "failed to synchronization #{config.name} on #{target.dir}"
59
+ Snapsync.warn "failed to synchronize #{config.name} on #{target.dir}"
60
60
  PP.pp(e, buffer = String.new)
61
61
  buffer.each_line do |line|
62
- Snapsync.warn " #{line}"
62
+ Snapsync.warn " #{line.chomp}"
63
63
  end
64
64
  e.backtrace.each do |line|
65
65
  Snapsync.debug " #{line}"
@@ -1,3 +1,3 @@
1
1
  module Snapsync
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: snapsync
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sylvain Joyeux
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-07 00:00:00.000000000 Z
11
+ date: 2015-08-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: logging