snapsync 0.1.1 → 0.1.2

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: 880db39dccd4f8a40cffc7801b2c768dd899938e
4
- data.tar.gz: ea3bb0a392ef829693c9e3145cd76f0a5500cea1
3
+ metadata.gz: 641ca51fa87cdb9f32a4395c070f8ebe2513d04e
4
+ data.tar.gz: 4ba5fe6fa7dedf496e4edb6e4b09345a4c52cab5
5
5
  SHA512:
6
- metadata.gz: fbfe69276bc9f20dcfc6f03797a8554b85783fd67de57fe31482504d8760c30812d1390b536d0049392efc351f391fdfd0a41fa7ed861488182d84a97214e6c4
7
- data.tar.gz: c4380cb4f8ebcb50e9bbbe66b520d60f227eb752cb1b9bac2010ff66d6519fb4899270618c148f740ea3acba3b5febc34a6032cad35d049291f792391170f3e0
6
+ metadata.gz: 863e89167e66a226dcc542bd9a4b11d962387244bd57fbc07667fb5223aa4ea0b4cbdb777672ef810d6a7b269fb291e891ffe3ea2e06bc425a901204a4351c64
7
+ data.tar.gz: b867d49ffb21283f8a80a05c590f7dc1f757cedd2c6a4f52a0235e0c7033ff30b00d57efaa7ac7d35aaabd79292718fc250bcc80dec27b4457b17d4827a4771a
@@ -0,0 +1,2 @@
1
+ source "https://rubygems.org"
2
+ gem 'snapsync'
data/README.md CHANGED
@@ -3,32 +3,73 @@
3
3
  A synchronization tool for snapper
4
4
 
5
5
  This gem implements snapper-based backup, by allowing you to synchronize a
6
- snapper snapshot directory to a different location. It uses btrfs send and
7
- receive to achieve it
6
+ snapper snapshot directory to a different location using btrfs send and
7
+ receive.
8
+
9
+ It can be used in two modes:
10
+ - in manual mode, you run snapsync
8
11
 
9
12
  ## Installation
10
13
 
11
- Run
14
+ You need to make sure that you've installed Ruby's bundler. On Ubuntu, run
15
+ $ apt install bundler
16
+
17
+ Then, the following will install snapsync in /opt/snapsync
18
+
19
+ $ wget https://raw.githubusercontent.com/doudou/snapsync/master/install.sh
20
+ $ sh install.sh
12
21
 
13
- $ gem install snapsync
22
+ The script will use sudo to get root rights when required. Add /opt/snapsync/bin
23
+ to your PATH if you want to use 'snapsync' as-is. Otherwise, you will have to
24
+ refer to /opt/snapsync/bin/snapsync explicitely. If it seems that you are using
25
+ systemd, the script also installs snapsync's systemd service file into the
26
+ system, enables and starts it.
14
27
 
15
28
  ## Usage
16
29
 
17
- To synchronize the snapshots of the 'home' snapper configuration to an existing
18
- directory, run
30
+ The most common usage of snapsync is to define a remote target (for instance, a
31
+ USB drive) to which the snapshots should be copied. Mount the drive manually
32
+ first and do
33
+
34
+ $ snapsync init /path/to/the/drive/snapsync
35
+
36
+ This will create snapsync targets for each of the snapper configurations
37
+ currently present on the system (i.e. if there is a 'home' and 'root'
38
+ configurations, it will create /path/to/the/drive/snapsync/root and
39
+ /path/to/the/drive/snapsync/auto). The 'default' synchronization policy is used
40
+ (see below for other options).
41
+
42
+ If you use systemd, the background systemd job will from now on synchronize the
43
+ new target whenever it is present (i.e. as soon as it is plugged in). If you
44
+ don't, or if you decided to disable the service's auto-start, run (and keep on
45
+ running)
46
+
47
+ $ snapsync auto-sync
48
+
49
+ to achieve the same result. The actions taken by the systemd-managed service can
50
+ be followed with
51
+
52
+ $ journalctl -f -u snapsync.service
53
+
54
+ ## Synchronization and cleanup policies
55
+
56
+ snapsync offers multiple synchronization-and-cleanup policies for targets. These
57
+ policies determine what to copy to the target, as well as what to keep on the
58
+ target.
19
59
 
20
- $ snapsync home /media/backup
60
+ The default policy copies everything and removes nothing. It's great at the
61
+ beginning, but is obviously not a very good long-term strategy ;-)
21
62
 
22
- Snapsync uses sudo to get root access. If you wish to not run it as root, you
23
- will need to change the snapper permissions to give read access to all the
24
- snapper shapshots, e.g.
63
+ Policies can be set at initialization time by passing additional arguments to
64
+ 'snapsync init', or later with 'snapsync policy'. Run
65
+ 'snapsync help init' and 'snapsync help policy' for more information.
25
66
 
26
- $ chmod go+rx /.snapshots
27
- $ chmod go+r /.snapshots/*/info.xml
67
+ ## Manual usage
28
68
 
29
- In addition, sudo will ask for your root password when applicable. If you wish
30
- to fully automate, you will need to allow snapsync to run the btrfs tool without
31
- password in the sudoers file.
69
+ If you prefer using snapsync manually, or use different automation that the one
70
+ provided by auto-sync, run 'snapsync' without arguments to get all the
71
+ possibilities. Targets have configuration files that allow to fine-tune
72
+ snapsync's automated behaviour to that effect.
32
73
 
33
74
  ## Development
34
75
 
data/Rakefile CHANGED
@@ -1,4 +1,3 @@
1
- require "bundler/gem_tasks"
2
1
  require "rake/testtask"
3
2
 
4
3
  Rake::TestTask.new(:test) do |t|
@@ -0,0 +1,24 @@
1
+ #! /bin/sh -ex
2
+
3
+ target=`mktemp -d`
4
+ cd $target
5
+ cat > Gemfile <<GEMFILE
6
+ source "https://rubygems.org"
7
+ gem 'snapsync'
8
+ GEMFILE
9
+
10
+ bundler install --standalone --binstubs
11
+ if test -d /opt/snapsync; then
12
+ sudo rm -rf /opt/snapsync
13
+ sudo cp -r . /opt/snapsync
14
+ fi
15
+
16
+ if test -d /lib/systemd/system; then
17
+ snapsync_gem=`bundler show snapsync`
18
+ cp $snapsync_gem/snapsync.service /lib/systemd/system
19
+ ( systemctl enable snapsync.service
20
+ systemctl start snapsync.service )
21
+ fi
22
+
23
+ rm -rf $target
24
+
@@ -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(["sudo", "btrfs", "filesystem", "sync", target_snapshot_dir.to_s, err: '/dev/null']).read
87
+ IO.popen(["btrfs", "filesystem", "sync", target_snapshot_dir.to_s, err: '/dev/null']).read
88
88
  Snapsync.info "Successfully synchronized #{src.snapshot_dir}"
89
89
  true
90
90
  end
@@ -114,9 +114,9 @@ module Snapsync
114
114
  receive_status, send_status = nil
115
115
  err_send_pipe_r, err_send_pipe_w = IO.pipe
116
116
  err_receive_pipe_r, err_receive_pipe_w = IO.pipe
117
- IO.popen(['sudo', 'btrfs', 'send', *parent_opt, src.subvolume_dir.to_s, err: err_send_pipe_w]) do |send_io|
117
+ IO.popen(['btrfs', 'send', *parent_opt, src.subvolume_dir.to_s, err: err_send_pipe_w]) do |send_io|
118
118
  err_send_pipe_w.close
119
- IO.popen(['sudo', 'btrfs', 'receive', target_snapshot_dir.to_s, err: err_receive_pipe_w, out: '/dev/null'], 'w') do |receive_io|
119
+ IO.popen(['btrfs', 'receive', target_snapshot_dir.to_s, err: err_receive_pipe_w, out: '/dev/null'], 'w') do |receive_io|
120
120
  err_receive_pipe_w.close
121
121
  receive_io.sync = true
122
122
  bytes_transferred = copy_stream(send_io, receive_io, estimated_size: estimated_size)
@@ -142,7 +142,7 @@ module Snapsync
142
142
 
143
143
  if success
144
144
  Snapsync.info "Flushing data to disk"
145
- IO.popen(["sudo", "btrfs", "filesystem", "sync", target_snapshot_dir.to_s, err: '/dev/null']).read
145
+ IO.popen(["btrfs", "filesystem", "sync", target_snapshot_dir.to_s, err: '/dev/null']).read
146
146
  duration = Time.now - start
147
147
  rate = bytes_transferred / duration
148
148
  Snapsync.info "Transferred #{human_readable_size(bytes_transferred)} in #{human_readable_time(duration)} (#{human_readable_size(rate)}/s)"
@@ -155,7 +155,7 @@ module Snapsync
155
155
  Snapsync.warn "Failed to synchronize #{src.snapshot_dir}, deleting target directory"
156
156
  subvolume_dir = target_snapshot_dir + "snapshot"
157
157
  if subvolume_dir.directory?
158
- IO.popen(["sudo", "btrfs", "subvolume", "delete", subvolume_dir.to_s, err: '/dev/null']).read
158
+ IO.popen(["btrfs", "subvolume", "delete", subvolume_dir.to_s, err: '/dev/null']).read
159
159
  end
160
160
  target_snapshot_dir.rmtree
161
161
  end
@@ -51,13 +51,13 @@ module Snapsync
51
51
  LocalSync.new(config, target).sync
52
52
  if should_autoclean_target?(target)
53
53
  if target.cleanup
54
- Snapsync.info "running cleanup"
54
+ Snapsync.info "running cleanup for #{config.name}"
55
55
  target.cleanup.cleanup(target)
56
56
  else
57
- Snapsync.info "#{target.sync_policy.class.name} policy set, no cleanup to do"
57
+ Snapsync.info "#{target.sync_policy.class.name} policy set, no cleanup to do for #{config.name}"
58
58
  end
59
59
  else
60
- Snapsync.info "autoclean not set"
60
+ Snapsync.info "autoclean not set on #{config.name}"
61
61
  end
62
62
  end
63
63
  end
@@ -1,3 +1,3 @@
1
1
  module Snapsync
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -0,0 +1,10 @@
1
+ [Unit]
2
+ Description=service that synchronizes snapper snapshots to other media
3
+ Wants=udisks2.service
4
+
5
+ [Service]
6
+ Type=simple
7
+ ExecStart=/opt/snapsync/bin/snapsync auto-sync
8
+
9
+ [Install]
10
+ WantedBy=default.target
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.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sylvain Joyeux
@@ -14,148 +14,148 @@ dependencies:
14
14
  name: logging
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ~>
18
18
  - !ruby/object:Gem::Version
19
19
  version: '2.0'
20
- - - ">="
20
+ - - '>='
21
21
  - !ruby/object:Gem::Version
22
22
  version: 2.0.0
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
- - - "~>"
27
+ - - ~>
28
28
  - !ruby/object:Gem::Version
29
29
  version: '2.0'
30
- - - ">="
30
+ - - '>='
31
31
  - !ruby/object:Gem::Version
32
32
  version: 2.0.0
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: concurrent-ruby
35
35
  requirement: !ruby/object:Gem::Requirement
36
36
  requirements:
37
- - - "~>"
37
+ - - ~>
38
38
  - !ruby/object:Gem::Version
39
39
  version: 0.9.0
40
- - - ">="
40
+ - - '>='
41
41
  - !ruby/object:Gem::Version
42
42
  version: '0.9'
43
43
  type: :runtime
44
44
  prerelease: false
45
45
  version_requirements: !ruby/object:Gem::Requirement
46
46
  requirements:
47
- - - "~>"
47
+ - - ~>
48
48
  - !ruby/object:Gem::Version
49
49
  version: 0.9.0
50
- - - ">="
50
+ - - '>='
51
51
  - !ruby/object:Gem::Version
52
52
  version: '0.9'
53
53
  - !ruby/object:Gem::Dependency
54
54
  name: ruby-dbus
55
55
  requirement: !ruby/object:Gem::Requirement
56
56
  requirements:
57
- - - "~>"
57
+ - - ~>
58
58
  - !ruby/object:Gem::Version
59
59
  version: 0.11.0
60
- - - ">="
60
+ - - '>='
61
61
  - !ruby/object:Gem::Version
62
62
  version: '0.11'
63
63
  type: :runtime
64
64
  prerelease: false
65
65
  version_requirements: !ruby/object:Gem::Requirement
66
66
  requirements:
67
- - - "~>"
67
+ - - ~>
68
68
  - !ruby/object:Gem::Version
69
69
  version: 0.11.0
70
- - - ">="
70
+ - - '>='
71
71
  - !ruby/object:Gem::Version
72
72
  version: '0.11'
73
73
  - !ruby/object:Gem::Dependency
74
74
  name: thor
75
75
  requirement: !ruby/object:Gem::Requirement
76
76
  requirements:
77
- - - "~>"
77
+ - - ~>
78
78
  - !ruby/object:Gem::Version
79
79
  version: 0.19.0
80
- - - ">="
80
+ - - '>='
81
81
  - !ruby/object:Gem::Version
82
82
  version: 0.19.1
83
83
  type: :runtime
84
84
  prerelease: false
85
85
  version_requirements: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - "~>"
87
+ - - ~>
88
88
  - !ruby/object:Gem::Version
89
89
  version: 0.19.0
90
- - - ">="
90
+ - - '>='
91
91
  - !ruby/object:Gem::Version
92
92
  version: 0.19.1
93
93
  - !ruby/object:Gem::Dependency
94
94
  name: bundler
95
95
  requirement: !ruby/object:Gem::Requirement
96
96
  requirements:
97
- - - "~>"
97
+ - - ~>
98
98
  - !ruby/object:Gem::Version
99
99
  version: '1.10'
100
100
  type: :development
101
101
  prerelease: false
102
102
  version_requirements: !ruby/object:Gem::Requirement
103
103
  requirements:
104
- - - "~>"
104
+ - - ~>
105
105
  - !ruby/object:Gem::Version
106
106
  version: '1.10'
107
107
  - !ruby/object:Gem::Dependency
108
108
  name: rake
109
109
  requirement: !ruby/object:Gem::Requirement
110
110
  requirements:
111
- - - "~>"
111
+ - - ~>
112
112
  - !ruby/object:Gem::Version
113
113
  version: '10.0'
114
114
  type: :development
115
115
  prerelease: false
116
116
  version_requirements: !ruby/object:Gem::Requirement
117
117
  requirements:
118
- - - "~>"
118
+ - - ~>
119
119
  - !ruby/object:Gem::Version
120
120
  version: '10.0'
121
121
  - !ruby/object:Gem::Dependency
122
122
  name: minitest
123
123
  requirement: !ruby/object:Gem::Requirement
124
124
  requirements:
125
- - - "~>"
125
+ - - ~>
126
126
  - !ruby/object:Gem::Version
127
127
  version: '5.0'
128
- - - ">="
128
+ - - '>='
129
129
  - !ruby/object:Gem::Version
130
130
  version: '5.7'
131
131
  type: :development
132
132
  prerelease: false
133
133
  version_requirements: !ruby/object:Gem::Requirement
134
134
  requirements:
135
- - - "~>"
135
+ - - ~>
136
136
  - !ruby/object:Gem::Version
137
137
  version: '5.0'
138
- - - ">="
138
+ - - '>='
139
139
  - !ruby/object:Gem::Version
140
140
  version: '5.7'
141
141
  - !ruby/object:Gem::Dependency
142
142
  name: flexmock
143
143
  requirement: !ruby/object:Gem::Requirement
144
144
  requirements:
145
- - - "~>"
145
+ - - ~>
146
146
  - !ruby/object:Gem::Version
147
147
  version: '1.3'
148
- - - ">="
148
+ - - '>='
149
149
  - !ruby/object:Gem::Version
150
150
  version: 1.3.3
151
151
  type: :development
152
152
  prerelease: false
153
153
  version_requirements: !ruby/object:Gem::Requirement
154
154
  requirements:
155
- - - "~>"
155
+ - - ~>
156
156
  - !ruby/object:Gem::Version
157
157
  version: '1.3'
158
- - - ">="
158
+ - - '>='
159
159
  - !ruby/object:Gem::Version
160
160
  version: 1.3.3
161
161
  description:
@@ -166,13 +166,15 @@ executables:
166
166
  extensions: []
167
167
  extra_rdoc_files: []
168
168
  files:
169
- - ".gitignore"
170
- - ".travis.yml"
169
+ - .gitignore
170
+ - .travis.yml
171
171
  - Gemfile
172
+ - Gemfile.install
172
173
  - LICENSE.txt
173
174
  - README.md
174
175
  - Rakefile
175
176
  - bin/snapsync
177
+ - install.sh
176
178
  - lib/snapsync.rb
177
179
  - lib/snapsync/auto_sync.rb
178
180
  - lib/snapsync/cleanup.rb
@@ -190,6 +192,7 @@ files:
190
192
  - lib/snapsync/timeline_sync_policy.rb
191
193
  - lib/snapsync/version.rb
192
194
  - snapsync.gemspec
195
+ - snapsync.service
193
196
  homepage: https://github.com/doudou/snapsync
194
197
  licenses:
195
198
  - MIT
@@ -200,17 +203,17 @@ require_paths:
200
203
  - lib
201
204
  required_ruby_version: !ruby/object:Gem::Requirement
202
205
  requirements:
203
- - - ">="
206
+ - - '>='
204
207
  - !ruby/object:Gem::Version
205
208
  version: '0'
206
209
  required_rubygems_version: !ruby/object:Gem::Requirement
207
210
  requirements:
208
- - - ">="
211
+ - - '>='
209
212
  - !ruby/object:Gem::Version
210
213
  version: '0'
211
214
  requirements: []
212
215
  rubyforge_project:
213
- rubygems_version: 2.2.2
216
+ rubygems_version: 2.0.14
214
217
  signing_key:
215
218
  specification_version: 4
216
219
  summary: tool to automate backing up snapper snapshots to other medias