snapsync 0.2.1 → 0.3.0

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: dba428d67c91dbc087576e7127910fe46aec8304
4
- data.tar.gz: d530b254f9cdd7ca46c9d8e2d43ce6c64133afac
3
+ metadata.gz: 4a591ba7179ca6238815f6aa99b747ce66468010
4
+ data.tar.gz: e8cdd470db1ed3e0118c8a6c4804c548f62fec96
5
5
  SHA512:
6
- metadata.gz: f41595ef065834ee02890fde9fbdd7b94fa8c3197ed3808435e5d7f769e1be62201b41201772ae4651ececbadfcb38b3ac3809dc8be2425944250fc9205d4bba
7
- data.tar.gz: 33cabe605c668f31b3d05ae704284f22ed312a108ced80741903c407a7d15f6b4ac87af17486664b3c82d4e287b9b4dddb7fd4003bf6c08415dc2fa7a405d5ee
6
+ metadata.gz: c2f58dd6c19a0cdca23cf65f6564a151ac126eee30af7e84bcfc7120be42f83460912f01ec8fcfdee627ca17f6df6d47d23e2418802450605c1be9a739d7f841
7
+ data.tar.gz: f85021d8c1b5375b50b7f4b1e4bb89706d45e6ebc19f26c4ff69177ae6fc4755f6bb71822a64ac2621126c53295948cec608bcdb43c4096f54e3f4091c84fb9d
@@ -23,11 +23,14 @@ module Snapsync
23
23
  block_error, block_result = nil
24
24
  IO.popen(['btrfs', *args, err: err_w, **options], mode) do |io|
25
25
  err_w.close
26
- begin
27
- block_result = yield(io)
28
- rescue Error
29
- raise
30
- rescue Exception => block_error
26
+ if block_given?
27
+ begin
28
+ block_result = yield(io)
29
+ rescue Error
30
+ raise
31
+ rescue Exception => block_error
32
+ end
33
+ else io.read
31
34
  end
32
35
  end
33
36
 
@@ -55,6 +55,9 @@ module Snapsync
55
55
  write_config
56
56
  end
57
57
 
58
+ def each_snapshot_raw(&block)
59
+ Snapshot.each_snapshot_raw(dir, &block)
60
+ end
58
61
  def each_snapshot(&block)
59
62
  Snapshot.each(dir, &block)
60
63
  end
@@ -98,6 +98,20 @@ module Snapsync
98
98
  end
99
99
  end
100
100
 
101
+ def self.each_snapshot_raw(snapshot_dir)
102
+ return enum_for(__method__, snapshot_dir) if !block_given?
103
+ snapshot_dir.each_child do |path|
104
+ if path.directory? && path.basename.to_s =~ /^\d+$/
105
+ begin
106
+ snapshot = Snapshot.new(path)
107
+ yield(path, snapshot, nil)
108
+ rescue InvalidSnapshot => e
109
+ yield(path, nil, e)
110
+ end
111
+ end
112
+ end
113
+ end
114
+
101
115
  # Enumerate the snapshots from the given directory
102
116
  #
103
117
  # The directory is supposed to be maintained in a snapper-compatible
@@ -105,22 +119,15 @@ module Snapsync
105
119
  # snapshot's number
106
120
  def self.each(snapshot_dir, with_partial: false)
107
121
  return enum_for(__method__, snapshot_dir, with_partial: with_partial) if !block_given?
108
- snapshot_dir.each_child do |path|
109
- if path.directory? && path.basename.to_s =~ /^\d+$/
110
- begin
111
- snapshot = Snapshot.new(path)
112
- rescue InvalidSnapshot => e
113
- Snapsync.warn "ignored #{path} in #{self}: #{e}"
114
- end
115
- if snapshot
116
- if snapshot.num != Integer(path.basename.to_s)
117
- Snapsync.warn "ignored #{path} in #{self}: the snapshot reports num=#{snapshot.num} but its directory is called #{path.basename}"
118
- elsif !with_partial && snapshot.partial?
119
- Snapsync.warn "ignored #{path} in #{self}: this is a partial snapshot"
120
- else
121
- yield snapshot
122
- end
123
- end
122
+ each_snapshot_raw(snapshot_dir) do |path, snapshot, error|
123
+ if error
124
+ Snapsync.warn "ignored #{path} in #{self}: #{error}"
125
+ elsif snapshot.num != Integer(path.basename.to_s)
126
+ Snapsync.warn "ignored #{path} in #{self}: the snapshot reports num=#{snapshot.num} but its directory is called #{path.basename}"
127
+ elsif !with_partial && snapshot.partial?
128
+ Snapsync.warn "ignored #{path} in #{self}: this is a partial snapshot"
129
+ else
130
+ yield snapshot
124
131
  end
125
132
  end
126
133
  end
data/lib/snapsync/sync.rb CHANGED
@@ -31,7 +31,37 @@ module Snapsync
31
31
  LocalSync.new(config, target).sync
32
32
  end
33
33
 
34
+ def remove_partially_synchronized_snapshots
35
+ target.each_snapshot_raw do |path, snapshot, error|
36
+ next if !error && !snapshot.partial?
37
+
38
+ Snapsync.info "Removing partial snapshot at #{path}"
39
+ begin
40
+ if (path + "snapshot").exist?
41
+ Btrfs.popen("subvolume", "delete", (path + "snapshot").to_s)
42
+ elsif (path + "snapshot.partial").exist?
43
+ Btrfs.popen("subvolume", "delete", (path + "snapshot.partial").to_s)
44
+ end
45
+ rescue Btrfs::Error => e
46
+ Snapsync.warn "failed to remove snapshot at #{path}, keeping the rest of the snapshot"
47
+ Snapsync.warn e.message
48
+ next
49
+ end
50
+
51
+ path.rmtree
52
+ Snapsync.info "Flushing data to disk"
53
+ begin
54
+ Btrfs.popen("subvolume", "sync", path.to_s)
55
+ rescue Btrfs::Error
56
+ end
57
+ end
58
+ end
59
+
34
60
  def run
61
+ if autoclean?
62
+ remove_partially_synchronized_snapshots
63
+ end
64
+
35
65
  sync
36
66
 
37
67
  if autoclean?
@@ -1,3 +1,3 @@
1
1
  module Snapsync
2
- VERSION = "0.2.1"
2
+ VERSION = "0.3.0"
3
3
  end
data/snapsync.gemspec CHANGED
@@ -12,6 +12,11 @@ Gem::Specification.new do |spec|
12
12
  spec.summary = "tool to automate backing up snapper snapshots to other medias"
13
13
  spec.homepage = "https://github.com/doudou/snapsync"
14
14
  spec.license = "MIT"
15
+ spec.description =<<-EOD
16
+ Snapsync is a tool that automates transferring snapper snapshots to
17
+ external media (USB drives ...) and managing these snapshots (e.g.
18
+ timeline cleanup)
19
+ EOD
15
20
 
16
21
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
22
  spec.bindir = "bin"
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.1
4
+ version: 0.3.0
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-28 00:00:00.000000000 Z
11
+ date: 2015-09-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: logging
@@ -158,7 +158,10 @@ dependencies:
158
158
  - - ">="
159
159
  - !ruby/object:Gem::Version
160
160
  version: 1.3.3
161
- description:
161
+ description: |
162
+ Snapsync is a tool that automates transferring snapper snapshots to
163
+ external media (USB drives ...) and managing these snapshots (e.g.
164
+ timeline cleanup)
162
165
  email:
163
166
  - sylvain.joyeux@m4x.org
164
167
  executables:
@@ -215,7 +218,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
215
218
  version: '0'
216
219
  requirements: []
217
220
  rubyforge_project:
218
- rubygems_version: 2.2.2
221
+ rubygems_version: 2.2.3
219
222
  signing_key:
220
223
  specification_version: 4
221
224
  summary: tool to automate backing up snapper snapshots to other medias