synco 1.2.0 → 1.3.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,63 +0,0 @@
1
- #!/usr/bin/env rspec
2
-
3
- # Copyright, 2015, by Samuel G. D. Williams. <http://www.codeotaku.com>
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy
6
- # of this software and associated documentation files (the "Software"), to deal
7
- # in the Software without restriction, including without limitation the rights
8
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- # copies of the Software, and to permit persons to whom the Software is
10
- # furnished to do so, subject to the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be included in
13
- # all copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- # THE SOFTWARE.
22
-
23
- require 'fingerprint'
24
- require 'process/group'
25
- require 'fileutils'
26
- require 'digest'
27
-
28
- require 'synco/scope'
29
- require 'synco/script'
30
-
31
- SYNCO_PATH = File.expand_path("../../bin/synco", __dir__)
32
-
33
- RSpec.shared_context "backup script" do
34
- def create_files(master_path, target_path)
35
- FileUtils.rm_rf master_path
36
- FileUtils.rm_rf target_path
37
-
38
- FileUtils.mkdir_p master_path
39
- FileUtils.mkdir_p target_path
40
-
41
- (1...10).each do |i|
42
- path = File.join(master_path, i.to_s)
43
-
44
- FileUtils.mkdir(path)
45
-
46
- text = Digest::MD5.hexdigest(i.to_s)
47
-
48
- File.open(File.join(path, i.to_s), "w") { |f| f.write(text) }
49
- end
50
- end
51
-
52
- let(:tmp_path) {File.join(__dir__, 'tmp')}
53
- let(:master_path) {File.join(__dir__, 'tmp/master')}
54
- let(:target_path) {File.join(__dir__, 'tmp/target')}
55
-
56
- before(:each) do
57
- create_files(master_path, target_path)
58
- end
59
-
60
- after(:each) do
61
- # FileUtils.rm_rf tmp_path
62
- end
63
- end
@@ -1,33 +0,0 @@
1
- #!/usr/bin/env rspec
2
-
3
- # Copyright, 2016, by Samuel G. D. Williams. <http://www.codeotaku.com>
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy
6
- # of this software and associated documentation files (the "Software"), to deal
7
- # in the Software without restriction, including without limitation the rights
8
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- # copies of the Software, and to permit persons to whom the Software is
10
- # furnished to do so, subject to the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be included in
13
- # all copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- # THE SOFTWARE.
22
-
23
- require 'synco/directory'
24
-
25
- RSpec.describe Synco::Directory.new(".", arguments: ['--foo']) do
26
- it "should have arguments" do
27
- expect(subject.arguments).to include('--foo')
28
- end
29
-
30
- it "must be relative path" do
31
- expect{Synco::Directory.new("/var")}.to raise_error(ArgumentError)
32
- end
33
- end
@@ -1,56 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'synco'
4
- require 'synco/shells/ssh'
5
- require 'synco/methods/rsync'
6
-
7
- # Check we've got two paths for sync.
8
- unless ARGV.size == 2
9
- $stderr.puts "Usage: #{$0} [master] [copy]"
10
- exit(255)
11
- end
12
-
13
- # $growl = Growl.new "localhost", "Synco", ["Backup Status"]
14
- # $growl.register
15
-
16
- $stdout.sync = true
17
- $stderr.sync = true
18
-
19
- Synco::run_script do |script|
20
- self.method = Synco::Methods::RSyncSnapshot.new(:push, "--archive", "--compress", "--stats")
21
-
22
- self.master = :src
23
-
24
- server(:src) do |server|
25
- server.root = ARGV[0]
26
- end
27
-
28
- server(:dst) do |server|
29
- server.root = ARGV[1]
30
-
31
- # Runs after all directories have been successfully backed up.
32
- server.on(:success) do
33
- target.run "synco", "rotate"
34
- target.run "synco", "prune"
35
- end
36
- end
37
-
38
- # This event is fired before the backup starts
39
- #script.on(:prepare) do
40
- # $growl.notify "Backup Status", "Starting Backup", "Starting at #{Time.now.to_s}"
41
- #end
42
- #
43
- ## This event occurs if the backup is successful
44
- #script.on(:success) do
45
- # $growl.notify "Backup Status", "Backup Successful", script.log.string
46
- #end
47
- #
48
- ## This event occurs if any part of the backup fails and is not handled elsewhere.
49
- #script.on(:failure) do |failure|
50
- # $growl.notify "Backup Status", "Backup Failure", failure.to_s
51
- #
52
- # raise failure
53
- #end
54
-
55
- backup('./')
56
- end
@@ -1,91 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- # You need to have the FSSM gem installed for this to work.
4
- require 'fssm'
5
-
6
- require 'synco'
7
- require 'synco/shells/ssh'
8
- require 'synco/methods/rsync'
9
- require 'synco/event_timer'
10
-
11
- MONITOR = ARGV.delete "-m"
12
-
13
- # Check we've got two paths for sync.
14
- unless ARGV.size == 2
15
- $stderr.puts "Usage: #{$0} [master] [copy]"
16
- exit(255)
17
- end
18
-
19
- script = Synco::Script.new do |script|
20
- script.method = Synco::Methods::RSync.new(:push, :arguments => ["--archive", "--delete"])
21
-
22
- script.master = :src
23
-
24
- server(:src) do |server|
25
- server.root = ARGV[0]
26
- end
27
-
28
- server(:dst) do |server|
29
- server.root = ARGV[1]
30
-
31
- #server.on(:prepare) do
32
- # logger.warn "Aborting backup!"
33
- # server.abort!
34
- #end
35
- end
36
-
37
- #server(:remote) do |server|
38
- # server.host = "ayako.oriontransfer.org"
39
- # server.shell = Synco::Shells::SSH.new(:user => "nobody")
40
- # server.root = "/tmp/sync-test"
41
- #end
42
-
43
- #server(:remote2) do |server|
44
- # server.host = "remote2.example.com"
45
- # server.root = "/tmp/sync-test"
46
- #
47
- # server.on(:prepare) do |controller|
48
- # controller.run! "mysqldump", "..."
49
- # end
50
- #
51
- # server.on(:success) do |controller|
52
- # controller.run! "uname", "-a"
53
- # end
54
- #end
55
-
56
- backup('./')
57
- end
58
-
59
- # Initial sync:
60
-
61
- context = Synco::Context.new(script)
62
- context.run!
63
-
64
- if MONITOR
65
- # Monitor directories for changes:
66
- monitor = FSSM::Monitor.new(:directories => true)
67
-
68
- # The event timer aggregates events into a single callback which will be called at most
69
- # once every k seconds (where k = 10 in this case).
70
- $event_timer = Synco::EventTimer.new(10) do
71
- $script.run!
72
- end
73
-
74
- $script.directories.each do |directory|
75
- full_path = $script[:src].full_path(directory)
76
- puts "Monitoring path: #{full_path}"
77
-
78
- monitor.path(full_path, "**/*") do
79
- update { $event_timer.trigger! }
80
- delete { $event_timer.trigger! }
81
- create { $event_timer.trigger! }
82
- end
83
- end
84
-
85
- begin
86
- monitor.run
87
- ensure
88
- # We should wait for the backup to complete nicely.
89
- $event_timer.join
90
- end
91
- end
@@ -1,62 +0,0 @@
1
- #!/usr/bin/env rspec
2
-
3
- # Copyright, 2016, by Samuel G. D. Williams. <http://www.codeotaku.com>
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy
6
- # of this software and associated documentation files (the "Software"), to deal
7
- # in the Software without restriction, including without limitation the rights
8
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- # copies of the Software, and to permit persons to whom the Software is
10
- # furnished to do so, subject to the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be included in
13
- # all copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- # THE SOFTWARE.
22
-
23
- require 'synco/scope'
24
- require 'synco/methods/scp'
25
-
26
- require_relative 'backup_script'
27
-
28
- RSpec.describe Synco::Methods::SCP do
29
- include_context "backup script"
30
-
31
- let(:test_server) {ENV.fetch('TEST_SERVER', 'localhost')}
32
-
33
- let(:script) {Synco::Script.new}
34
- let(:logger) {Logger.new($stderr)}
35
- let(:master_server) {Synco::Server.new('localhost', root: master_path)}
36
- let(:target_server) {Synco::Server.new(test_server, root: target_path)}
37
-
38
- let(:group) {Process::Group.new}
39
- let(:script_scope) {Synco::ScriptScope.new(script, logger, group)}
40
- let(:sync_scope) {Synco::TargetScope.new(script_scope, target_server)}
41
-
42
- let(:directory) {Synco::Directory.new(".", arguments: ['--archive'])}
43
- let(:directory_scope) {Synco::DirectoryScope.new(sync_scope, directory)}
44
-
45
- # This example shows all the state which goes into one single method invocation:
46
- it 'should copy files from master to target' do
47
- script.instance_variable_set(:@master_server, master_server)
48
- script.instance_variable_set(:@current_server, master_server)
49
-
50
- expect(directory_scope.master_server).to_not be == nil
51
- expect(directory_scope.target_server).to_not be == nil
52
- expect(directory_scope.current_server).to_not be == nil
53
-
54
- group.wait do
55
- Fiber.new do
56
- subject.call(directory_scope)
57
- end.resume
58
- end
59
-
60
- expect(Fingerprint).to be_identical(master_path, target_path)
61
- end
62
- end
@@ -1,89 +0,0 @@
1
- #!/usr/bin/env rspec
2
-
3
- # Copyright, 2016, by Samuel G. D. Williams. <http://www.codeotaku.com>
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy
6
- # of this software and associated documentation files (the "Software"), to deal
7
- # in the Software without restriction, including without limitation the rights
8
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- # copies of the Software, and to permit persons to whom the Software is
10
- # furnished to do so, subject to the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be included in
13
- # all copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- # THE SOFTWARE.
22
-
23
- require 'logger'
24
- require 'synco/script'
25
- require 'synco/scope'
26
- require 'synco/methods/rsync'
27
-
28
- require_relative 'backup_script'
29
-
30
- RSpec.describe Synco::Methods::RSync do
31
- include_context "backup script"
32
-
33
- it 'should copy files using rsync' do
34
- script = Synco::Script.build do |script|
35
- script.method = Synco::Methods::RSync.new(archive: true)
36
-
37
- script.server(:master) do |server|
38
- server.root = master_path
39
- end
40
-
41
- script.server(:backup) do |server|
42
- server.root = target_path
43
- end
44
-
45
- script.copy '.'
46
- end
47
-
48
- expect(script.method.arguments).to include('--archive')
49
- expect(script.method.arguments).to_not include('--stats')
50
-
51
- Synco::Runner.new(script).call
52
-
53
- expect(Fingerprint).to be_identical(master_path, target_path)
54
- end
55
-
56
- it 'should copy files using rsync snapshot' do
57
- script = Synco::Script.build do |script|
58
- script.method = Synco::Methods::RSyncSnapshot.new
59
-
60
- script.server(:master) do |server|
61
- server.root = master_path
62
- end
63
-
64
- script.server(:backup) do |server|
65
- server.root = target_path
66
-
67
- server.on(:success) do
68
- run SYNCO_PATH, "rotate", chdir: target_server.root
69
- run SYNCO_PATH, "prune", chdir: target_server.root
70
- end
71
- end
72
-
73
- script.copy '.', arguments: %W{--archive}
74
- end
75
-
76
- expect(script.method.arguments).to include('--archive', '--stats')
77
-
78
- Synco::Runner.new(script).call
79
-
80
- expect(Fingerprint).to be_identical(master_path, File.join(target_path, Synco::LATEST_NAME))
81
- end
82
- end
83
-
84
- RSpec.describe Synco::Methods::RSyncSnapshot do
85
- it 'should generate correct command for ssh shell' do
86
- expect(subject.escape(['ssh', '-o', 'BatchMode=yes'])).to be == 'ssh -o BatchMode=yes'
87
- end
88
- end
89
-
@@ -1,58 +0,0 @@
1
- #!/usr/bin/env rspec
2
-
3
- # Copyright, 2016, by Samuel G. D. Williams. <http://www.codeotaku.com>
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy
6
- # of this software and associated documentation files (the "Software"), to deal
7
- # in the Software without restriction, including without limitation the rights
8
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- # copies of the Software, and to permit persons to whom the Software is
10
- # furnished to do so, subject to the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be included in
13
- # all copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- # THE SOFTWARE.
22
-
23
- require 'logger'
24
- require 'synco/script'
25
- require 'synco/scope'
26
- require 'synco/methods/scp'
27
-
28
- require_relative 'backup_script'
29
-
30
- RSpec.describe Synco::Methods::SCP do
31
- include_context "backup script"
32
-
33
- it 'should build a script with desired configuration' do
34
- script = Synco::Script.build do |script|
35
- script.method = Synco::Methods::SCP.new
36
-
37
- script.server(:master) do |server|
38
- server.root = master_path
39
- end
40
-
41
- script.server(:target) do |server|
42
- server.root = target_path
43
- end
44
-
45
- script.copy(".")
46
-
47
- script.on(:failure) do |exception|
48
- logger.error{exception}
49
- end
50
- end
51
-
52
- expect(script.events).to include(:failure)
53
-
54
- Synco::Runner.new(script).call
55
-
56
- expect(Fingerprint).to be_identical(master_path, target_path)
57
- end
58
- end
@@ -1,51 +0,0 @@
1
- #!/usr/bin/env rspec
2
-
3
- # Copyright, 2016, by Samuel G. D. Williams. <http://www.codeotaku.com>
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy
6
- # of this software and associated documentation files (the "Software"), to deal
7
- # in the Software without restriction, including without limitation the rights
8
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- # copies of the Software, and to permit persons to whom the Software is
10
- # furnished to do so, subject to the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be included in
13
- # all copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- # THE SOFTWARE.
22
-
23
- require 'logger'
24
- require 'synco/script'
25
- require 'synco/methods/scp'
26
-
27
- RSpec.describe Synco::Script do
28
- it 'should build a script with desired configuration' do
29
- script = Synco::Script.build do |script|
30
- script.server(:master) do |server|
31
- end
32
-
33
- script.server(:backup) do |server|
34
- server.root = 'backup'
35
-
36
- server.on(:prepare) do
37
- run "synco", "mount", chdir: server.root
38
- end
39
- end
40
- end
41
-
42
- # After building, everything should be frozen..
43
- expect(script).to be_frozen
44
-
45
- # We should have the two servers defined:
46
- expect(script.servers).to include(:master, :backup)
47
-
48
- # We should have a single event for backup server:
49
- expect(script[:backup].events).to include(:prepare)
50
- end
51
- end
@@ -1,40 +0,0 @@
1
- #!/usr/bin/env rspec
2
-
3
- # Copyright, 2016, by Samuel G. D. Williams. <http://www.codeotaku.com>
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy
6
- # of this software and associated documentation files (the "Software"), to deal
7
- # in the Software without restriction, including without limitation the rights
8
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- # copies of the Software, and to permit persons to whom the Software is
10
- # furnished to do so, subject to the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be included in
13
- # all copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- # THE SOFTWARE.
22
-
23
- require 'synco/server'
24
- require 'synco/shells/ssh'
25
-
26
- RSpec.describe Synco::Shells::SSH do
27
- let(:server) {Synco::Server.new('localhost')}
28
-
29
- it 'should generate a connection command' do
30
- expect(subject.connection_command(server)).to be == ['ssh', 'localhost']
31
- end
32
- end
33
-
34
- RSpec.describe Synco::Shells::SSH.new(batch_mode: true) do
35
- let(:server) {Synco::Server.new('localhost')}
36
-
37
- it 'should generate a connection command with options' do
38
- expect(subject.connection_command(server)).to be == ['ssh', '-o', 'BatchMode=yes', 'localhost']
39
- end
40
- end
@@ -1,76 +0,0 @@
1
- #!/usr/bin/env rspec
2
-
3
- # Copyright, 2016, by Samuel G. D. Williams. <http://www.codeotaku.com>
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy
6
- # of this software and associated documentation files (the "Software"), to deal
7
- # in the Software without restriction, including without limitation the rights
8
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- # copies of the Software, and to permit persons to whom the Software is
10
- # furnished to do so, subject to the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be included in
13
- # all copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- # THE SOFTWARE.
22
-
23
- require 'synco/disk'
24
- require 'synco/methods/rsync'
25
- require_relative 'backup_script'
26
-
27
- RSpec.describe Synco::Methods::RSyncSnapshot, if: Synco::Disk.available?('TEST') do
28
- include_context "backup script"
29
-
30
- before(:each) do
31
- Synco::Disk.unmount(target_path)
32
- end
33
-
34
- after(:each) do
35
- Synco::Disk.unmount(target_path)
36
- end
37
-
38
- it 'should mount and backup to an attached USB stick' do
39
- script = Synco::Script.build do |script|
40
- script.method = Synco::Methods::RSyncSnapshot.new
41
-
42
- script.master = :source
43
-
44
- script.server(:source) do |server|
45
- server.root = master_path
46
- end
47
-
48
- script.server(:destination) do |server|
49
- server.mountpoint = target_path
50
- server.root = target_path
51
-
52
- server.on(:prepare) do
53
- target_server.run "synco", "mount", target_server.mountpoint, 'TEST'
54
- end
55
-
56
- # Runs after all directories have been successfully backed up.
57
- server.on(:success) do
58
- run "synco", "rotate", chdir: server.root
59
- run "synco", "prune", chdir: server.root
60
- end
61
-
62
- server.on(:finish) do
63
- target_server.run "synco", "unmount", target_server.mountpoint
64
- end
65
- end
66
-
67
- script.backup('.')
68
- end
69
-
70
- Synco::Runner.new(script).call
71
-
72
- Synco::Disk.mount(target_path, 'TEST')
73
-
74
- expect(Fingerprint).to be_identical(master_path, File.join(target_path, Synco::LATEST_NAME))
75
- end
76
- end
@@ -1,50 +0,0 @@
1
- #!/usr/bin/env rspec
2
-
3
- # Copyright, 2016, by Samuel G. D. Williams. <http://www.codeotaku.com>
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy
6
- # of this software and associated documentation files (the "Software"), to deal
7
- # in the Software without restriction, including without limitation the rights
8
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- # copies of the Software, and to permit persons to whom the Software is
10
- # furnished to do so, subject to the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be included in
13
- # all copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- # THE SOFTWARE.
22
-
23
- require 'logger'
24
- require 'synco/script'
25
- require 'synco/scope'
26
- require 'synco/methods/zfs'
27
-
28
- RSpec.describe Synco::Methods::ZFS do
29
- xit 'should mirror two ZFS partitions' do
30
- script = Synco::Script.build(master: :source) do |script|
31
- script.method = Synco::Methods::ZFS.new
32
-
33
- script.server(:master) do |server|
34
- server.host = 'hinoki.local'
35
- server.root = '/tank/test/source'
36
- end
37
-
38
- script.server(:backup) do |server|
39
- server.host = 'hinoki.local'
40
- server.root = '/tank/test/destination'
41
- end
42
-
43
- script.copy("./")
44
- end
45
-
46
- Synco::Runner.new(script).call
47
-
48
- expect(Fingerprint).to be_identical(script[:master].root, script[:backup].root)
49
- end
50
- end