snapsync 0.2.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/snapsync/btrfs.rb +8 -5
- data/lib/snapsync/local_target.rb +3 -0
- data/lib/snapsync/snapshot.rb +23 -16
- data/lib/snapsync/sync.rb +30 -0
- data/lib/snapsync/version.rb +1 -1
- data/snapsync.gemspec +5 -0
- metadata +7 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4a591ba7179ca6238815f6aa99b747ce66468010
|
4
|
+
data.tar.gz: e8cdd470db1ed3e0118c8a6c4804c548f62fec96
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c2f58dd6c19a0cdca23cf65f6564a151ac126eee30af7e84bcfc7120be42f83460912f01ec8fcfdee627ca17f6df6d47d23e2418802450605c1be9a739d7f841
|
7
|
+
data.tar.gz: f85021d8c1b5375b50b7f4b1e4bb89706d45e6ebc19f26c4ff69177ae6fc4755f6bb71822a64ac2621126c53295948cec608bcdb43c4096f54e3f4091c84fb9d
|
data/lib/snapsync/btrfs.rb
CHANGED
@@ -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
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
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
|
|
data/lib/snapsync/snapshot.rb
CHANGED
@@ -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
|
109
|
-
if
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
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?
|
data/lib/snapsync/version.rb
CHANGED
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.
|
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-
|
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.
|
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
|