snapsync 0.1.8 → 0.2.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/Gemfile +0 -3
- data/bin/snapsync +5 -1
- data/lib/snapsync.rb +1 -0
- data/lib/snapsync/btrfs.rb +49 -0
- data/lib/snapsync/local_sync.rb +23 -44
- data/lib/snapsync/snapshot.rb +2 -2
- data/lib/snapsync/sync_all.rb +9 -0
- data/lib/snapsync/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 75228e89d473612d045f56e995ddc5492506a119
|
4
|
+
data.tar.gz: 476af2e900213d61aa7fd9c5d606f33ca33df4d8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2aafcd762a596944cf0d1997b92e2e3a74ff9daa19e706529ce6f26e4d697202c7223b0e80075cc1653a8ed0322173321bee62abf29fd573bf251cf579071eca
|
7
|
+
data.tar.gz: e3e0b871f358c5a76cfcaa09a5d3d88b8614dbcb623fbc91fa04f4d8232ce4fd8bf76539153c4ce3b319d699184f690efaddfc4dfa160220615b488676601975
|
data/Gemfile
CHANGED
data/bin/snapsync
CHANGED
data/lib/snapsync.rb
CHANGED
@@ -0,0 +1,49 @@
|
|
1
|
+
module Snapsync
|
2
|
+
module Btrfs
|
3
|
+
class Error < RuntimeError
|
4
|
+
attr_reader :error_lines
|
5
|
+
def initialize(error_lines = Array.new)
|
6
|
+
@error_lines = error_lines
|
7
|
+
end
|
8
|
+
|
9
|
+
def pretty_print(pp)
|
10
|
+
pp.text message
|
11
|
+
pp.nest(2) do
|
12
|
+
error_lines.each do |l|
|
13
|
+
pp.breakable
|
14
|
+
pp.text l.chomp
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.popen(*args, mode: 'r', raise_on_error: true, **options)
|
21
|
+
err_r, err_w = IO.pipe
|
22
|
+
result = IO.popen(['btrfs', *args, err: err_w, **options], mode) do |io|
|
23
|
+
err_w.close
|
24
|
+
yield(io)
|
25
|
+
end
|
26
|
+
|
27
|
+
if $?.success?
|
28
|
+
result
|
29
|
+
elsif raise_on_error
|
30
|
+
raise Error.new, "btrfs failed"
|
31
|
+
end
|
32
|
+
|
33
|
+
rescue Error => e
|
34
|
+
prefix = args.join(" ")
|
35
|
+
lines = err_r.readlines.map do |line|
|
36
|
+
"#{prefix}: #{line.chomp}"
|
37
|
+
end
|
38
|
+
raise Error.new(e.error_lines + lines), e.message, e.backtrace
|
39
|
+
|
40
|
+
ensure err_r.close
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.run(*args, **options)
|
44
|
+
popen(*args, **options) do |io|
|
45
|
+
io.read
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
data/lib/snapsync/local_sync.rb
CHANGED
@@ -111,54 +111,33 @@ module Snapsync
|
|
111
111
|
|
112
112
|
start = Time.now
|
113
113
|
bytes_transferred = nil
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
err_receive_pipe_w.close
|
121
|
-
receive_io.sync = true
|
122
|
-
bytes_transferred = copy_stream(send_io, receive_io, estimated_size: estimated_size)
|
123
|
-
end
|
124
|
-
receive_status = $?
|
125
|
-
end
|
126
|
-
send_status = $?
|
127
|
-
|
128
|
-
success = (receive_status.success? && send_status.success?)
|
129
|
-
if !send_status.success?
|
130
|
-
Snapsync.warn "btrfs send reported an error"
|
131
|
-
err_send_pipe_w.readlines.each do |line|
|
132
|
-
Snapsync.warn " #{line.chomp}"
|
133
|
-
end
|
134
|
-
end
|
135
|
-
|
136
|
-
if !receive_status.success?
|
137
|
-
Snapsync.warn "btrfs receive reported an error"
|
138
|
-
err_receive_pipe_w.readlines.each do |line|
|
139
|
-
Snapsync.warn " #{line.chomp}"
|
114
|
+
bytes_transferred =
|
115
|
+
Btrfs.popen('send', *parent_opt, src.subvolume_dir.to_s) do |send_io|
|
116
|
+
Btrfs.popen('receive', target_snapshot_dir.to_s, mode: 'w', out: '/dev/null') do |receive_io|
|
117
|
+
receive_io.sync = true
|
118
|
+
copy_stream(send_io, receive_io, estimated_size: estimated_size)
|
119
|
+
end
|
140
120
|
end
|
141
|
-
end
|
142
121
|
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
if
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
IO.popen(["btrfs", "subvolume", "delete", subvolume_dir.to_s, err: '/dev/null']).read
|
159
|
-
end
|
122
|
+
Snapsync.info "Flushing data to disk"
|
123
|
+
Btrfs.run("filesystem", "sync", target_snapshot_dir.to_s)
|
124
|
+
duration = Time.now - start
|
125
|
+
rate = bytes_transferred / duration
|
126
|
+
Snapsync.info "Transferred #{human_readable_size(bytes_transferred)} in #{human_readable_time(duration)} (#{human_readable_size(rate)}/s)"
|
127
|
+
Snapsync.info "Successfully synchronized #{src.snapshot_dir}"
|
128
|
+
true
|
129
|
+
|
130
|
+
rescue Exception => e
|
131
|
+
Snapsync.warn "Failed to synchronize #{src.snapshot_dir}, deleting target directory"
|
132
|
+
subvolume_dir = target_snapshot_dir + "snapshot"
|
133
|
+
if subvolume_dir.directory?
|
134
|
+
Btrfs.run("subvolume", "delete", subvolume_dir.to_s)
|
135
|
+
end
|
136
|
+
if target_snapshot_dir.directory?
|
160
137
|
target_snapshot_dir.rmtree
|
161
138
|
end
|
139
|
+
|
140
|
+
raise
|
162
141
|
end
|
163
142
|
|
164
143
|
def sync
|
data/lib/snapsync/snapshot.rb
CHANGED
@@ -78,7 +78,7 @@ module Snapsync
|
|
78
78
|
# This is an estimate of the size required to send this snapshot using
|
79
79
|
# the given snapshot as parent
|
80
80
|
def size_diff_from(snapshot)
|
81
|
-
info =
|
81
|
+
info = Btrfs.run('subvolume', 'show', snapshot.subvolume_dir.to_s)
|
82
82
|
info =~ /Generation[^:]*:\s+(\d+)/
|
83
83
|
size_diff_from_gen(Integer($1))
|
84
84
|
end
|
@@ -89,7 +89,7 @@ module Snapsync
|
|
89
89
|
end
|
90
90
|
|
91
91
|
def size_diff_from_gen(gen)
|
92
|
-
new =
|
92
|
+
new = Btrfs.run('subvolume', 'find-new', subvolume_dir.to_s, gen.to_s)
|
93
93
|
new.split("\n").inject(0) do |size, line|
|
94
94
|
if line.strip =~ /len (\d+)/
|
95
95
|
size + Integer($1)
|
data/lib/snapsync/sync_all.rb
CHANGED
@@ -53,8 +53,17 @@ module Snapsync
|
|
53
53
|
end
|
54
54
|
begin
|
55
55
|
Sync.new(config, target, autoclean: autoclean?).run
|
56
|
+
rescue Interrupt
|
57
|
+
raise
|
56
58
|
rescue Exception => e
|
57
59
|
Snapsync.warn "failed to synchronization #{config.name} on #{target.dir}"
|
60
|
+
PP.pp(e, buffer = String.new)
|
61
|
+
buffer.each_line do |line|
|
62
|
+
Snapsync.warn " #{line}"
|
63
|
+
end
|
64
|
+
e.backtrace.each do |line|
|
65
|
+
Snapsync.debug " #{line}"
|
66
|
+
end
|
58
67
|
end
|
59
68
|
end
|
60
69
|
end
|
data/lib/snapsync/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: snapsync
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sylvain Joyeux
|
@@ -177,6 +177,7 @@ files:
|
|
177
177
|
- install.sh
|
178
178
|
- lib/snapsync.rb
|
179
179
|
- lib/snapsync/auto_sync.rb
|
180
|
+
- lib/snapsync/btrfs.rb
|
180
181
|
- lib/snapsync/cleanup.rb
|
181
182
|
- lib/snapsync/cli.rb
|
182
183
|
- lib/snapsync/default_sync_policy.rb
|