duplicati 0.0.6 → 0.0.7

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.
data/lib/duplicati.rb CHANGED
@@ -12,7 +12,7 @@ class Duplicati
12
12
  end
13
13
  end
14
14
 
15
- attr_reader :opts, :execution_success
15
+ attr_reader :opts
16
16
 
17
17
  def initialize(opts={})
18
18
  opts[:log_path] ||= "duplicati.log"
@@ -31,7 +31,7 @@ class Duplicati
31
31
  def backup
32
32
  execute Backup.new(
33
33
  options :duplicati_path, :backup_paths, :backup_store_path,
34
- :backup_encryption_key, :inclusion_filters, :exclusion_filters, :log_path
34
+ :backup_encryption_key, :inclusion_filters, :exclusion_filters, :log_path
35
35
  ).command
36
36
  end
37
37
 
@@ -43,12 +43,12 @@ class Duplicati
43
43
  end
44
44
 
45
45
  def execute(command)
46
- old_log_file_size = File.read(@opts[:log_path]).strip.size rescue 0
47
46
  formatted_command = format command
48
47
  puts formatted_command if $DEBUG
49
- @execution_success = system(formatted_command) && File.read(@opts[:log_path]).strip.size > old_log_file_size
48
+ system(formatted_command)
49
+ @exit_status = $?.exitstatus
50
50
  notify
51
- @execution_success
51
+ execution_success?
52
52
  end
53
53
 
54
54
  def options(*options_to_extract)
@@ -64,9 +64,20 @@ class Duplicati
64
64
 
65
65
  def notify
66
66
  @opts[:notifications].each do |notification|
67
- notification.notify @execution_success
67
+ notification.notify execution_success?
68
68
  end
69
69
  end
70
70
 
71
+ # https://code.google.com/p/duplicati/issues/detail?id=678
72
+ # 0 - Success
73
+ # 1 - Success (but no changed files)
74
+ # 2 - Completed by retried some files, or some files were locked (warnings)
75
+ # 50 - Some files were uploaded, then connection died
76
+ # 100 - No connection to server -> Fatal error
77
+ # 200 - Invalid command/arguments
78
+ def execution_success?
79
+ @exit_status && @exit_status.between?(0, 2)
80
+ end
81
+
71
82
  end
72
83
 
@@ -18,8 +18,8 @@ class Duplicati
18
18
  --volsize=100mb
19
19
  --auto-cleanup
20
20
  --full-if-older-than=1M
21
- --usn-policy=on
22
- --snapshot-policy=on
21
+ --usn-policy=auto
22
+ --snapshot-policy=auto
23
23
  --full-if-sourcefolder-changed
24
24
  2>&1 1>> "#{@log_path}" &&
25
25
 
@@ -1,3 +1,3 @@
1
1
  class Duplicati
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
@@ -37,8 +37,8 @@ describe Duplicati::Backup do
37
37
  --volsize=100mb
38
38
  --auto-cleanup
39
39
  --full-if-older-than=1M
40
- --usn-policy=on
41
- --snapshot-policy=on
40
+ --usn-policy=auto
41
+ --snapshot-policy=auto
42
42
  --full-if-sourcefolder-changed
43
43
  2>&1 1>> "/zzz/output.log" &&
44
44
 
@@ -121,34 +121,53 @@ describe Duplicati do
121
121
  command with spaces"
122
122
  Object.any_instance.should_receive(:system).with("multiline command with spaces")
123
123
 
124
- Duplicati.new(:log_path => "foo").send(:execute, cmd)
124
+ Duplicati.new.send(:execute, cmd)
125
125
  end
126
126
 
127
- context "#execution_success" do
128
- it "is false when command itself fails" do
127
+ context "#execution_success?" do
128
+ it "is false when command fails with negative exit status" do
129
129
  Object.any_instance.should_receive(:system).and_return false
130
+ $?.should_receive(:exitstatus).and_return -1
130
131
 
131
132
  duplicati = Duplicati.new
132
- duplicati.send(:execute, "")
133
- duplicati.execution_success.should be_false
133
+ duplicati.send(:execute, "").should be_false
134
+ duplicati.should_not be_execution_success
134
135
  end
135
136
 
136
- it "is false when command succeeds and log file size does not increase" do
137
+ it "is false when command fails with exit status above 2" do
138
+ Object.any_instance.should_receive(:system).and_return false
139
+ $?.should_receive(:exitstatus).and_return 3
140
+
141
+ duplicati = Duplicati.new
142
+ duplicati.send(:execute, "").should be_false
143
+ duplicati.should_not be_execution_success
144
+ end
145
+
146
+ it "is true when command succeeds with exit status 0" do
147
+ Object.any_instance.should_receive(:system).and_return true
148
+ $?.should_receive(:exitstatus).and_return 0
149
+
150
+ duplicati = Duplicati.new
151
+ duplicati.send(:execute, "").should be_true
152
+ duplicati.should be_execution_success
153
+ end
154
+
155
+ it "is true when command succeeds with exit status 1" do
137
156
  Object.any_instance.should_receive(:system).and_return true
138
- File.should_receive(:read).with("foo").and_return "", ""
157
+ $?.should_receive(:exitstatus).and_return 1
139
158
 
140
- duplicati = Duplicati.new :log_path => "foo"
141
- duplicati.send(:execute, "")
142
- duplicati.execution_success.should be_false
159
+ duplicati = Duplicati.new
160
+ duplicati.send(:execute, "").should be_true
161
+ duplicati.should be_execution_success
143
162
  end
144
163
 
145
- it "is true when command succeeds and log file size increases" do
164
+ it "is true when command succeeds with exit status 2" do
146
165
  Object.any_instance.should_receive(:system).and_return true
147
- File.should_receive(:read).with("foo").and_return "", "output"
166
+ $?.should_receive(:exitstatus).and_return 2
148
167
 
149
- duplicati = Duplicati.new :log_path => "foo"
150
- duplicati.send(:execute, "")
151
- duplicati.execution_success.should be_true
168
+ duplicati = Duplicati.new
169
+ duplicati.send(:execute, "").should be_true
170
+ duplicati.should be_execution_success
152
171
  end
153
172
  end
154
173
 
@@ -157,8 +176,9 @@ describe Duplicati do
157
176
  Duplicati.any_instance.unstub(:notify)
158
177
  end
159
178
 
160
- it "notifies with all possible notifications" do
179
+ it "notifies with all possible notifications with false execution success" do
161
180
  Object.any_instance.stub(:system).and_return false
181
+ $?.should_receive(:exitstatus).and_return 3
162
182
  notification1 = double('notification1').as_null_object
163
183
  notification2 = double('notification2').as_null_object
164
184
 
@@ -166,6 +186,17 @@ describe Duplicati do
166
186
  notification2.should_receive(:notify).with(false)
167
187
  Duplicati.new(:notifications => [notification1, notification2]).send(:execute, "")
168
188
  end
189
+
190
+ it "notifies with all possible notifications with true execution success" do
191
+ Object.any_instance.stub(:system).and_return true
192
+ $?.should_receive(:exitstatus).and_return 0
193
+ notification1 = double('notification1').as_null_object
194
+ notification2 = double('notification2').as_null_object
195
+
196
+ notification1.should_receive(:notify).with(true)
197
+ notification2.should_receive(:notify).with(true)
198
+ Duplicati.new(:notifications => [notification1, notification2]).send(:execute, "")
199
+ end
169
200
  end
170
201
 
171
202
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: duplicati
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-15 00:00:00.000000000 Z
12
+ date: 2013-02-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -84,12 +84,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
84
84
  - - ! '>='
85
85
  - !ruby/object:Gem::Version
86
86
  version: '0'
87
+ segments:
88
+ - 0
89
+ hash: -480531571
87
90
  required_rubygems_version: !ruby/object:Gem::Requirement
88
91
  none: false
89
92
  requirements:
90
93
  - - ! '>='
91
94
  - !ruby/object:Gem::Version
92
95
  version: '0'
96
+ segments:
97
+ - 0
98
+ hash: -480531571
93
99
  requirements: []
94
100
  rubyforge_project:
95
101
  rubygems_version: 1.8.24
@@ -103,4 +109,3 @@ test_files:
103
109
  - spec/duplicati/notification/mail_spec.rb
104
110
  - spec/duplicati_spec.rb
105
111
  - spec/spec_helper.rb
106
- has_rdoc: