backup 3.0.27 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (166) hide show
  1. data/LICENSE.md +1 -1
  2. data/README.md +139 -386
  3. data/bin/backup +1 -7
  4. data/lib/backup.rb +3 -9
  5. data/lib/backup/archive.rb +26 -20
  6. data/lib/backup/cleaner.rb +2 -2
  7. data/lib/backup/cli.rb +366 -0
  8. data/lib/backup/compressor/base.rb +2 -2
  9. data/lib/backup/compressor/gzip.rb +35 -1
  10. data/lib/backup/config.rb +1 -2
  11. data/lib/backup/database/base.rb +2 -2
  12. data/lib/backup/database/mongodb.rb +3 -3
  13. data/lib/backup/database/mysql.rb +3 -2
  14. data/lib/backup/database/postgresql.rb +3 -2
  15. data/lib/backup/database/riak.rb +18 -5
  16. data/lib/backup/dependency.rb +144 -93
  17. data/lib/backup/encryptor/base.rb +2 -2
  18. data/lib/backup/logger.rb +108 -110
  19. data/lib/backup/logger/console.rb +51 -0
  20. data/lib/backup/logger/logfile.rb +113 -0
  21. data/lib/backup/logger/syslog.rb +116 -0
  22. data/lib/backup/model.rb +67 -65
  23. data/lib/backup/notifier/base.rb +1 -1
  24. data/lib/backup/notifier/hipchat.rb +1 -1
  25. data/lib/backup/notifier/mail.rb +1 -1
  26. data/lib/backup/notifier/pushover.rb +6 -3
  27. data/lib/backup/packager.rb +4 -4
  28. data/lib/backup/pipeline.rb +17 -3
  29. data/lib/backup/splitter.rb +2 -2
  30. data/lib/backup/storage/base.rb +2 -2
  31. data/lib/backup/storage/cloudfiles.rb +2 -2
  32. data/lib/backup/storage/dropbox.rb +4 -4
  33. data/lib/backup/storage/ftp.rb +2 -2
  34. data/lib/backup/storage/local.rb +2 -2
  35. data/lib/backup/storage/ninefold.rb +2 -2
  36. data/lib/backup/storage/rsync.rb +3 -3
  37. data/lib/backup/storage/s3.rb +2 -2
  38. data/lib/backup/storage/scp.rb +2 -6
  39. data/lib/backup/storage/sftp.rb +2 -5
  40. data/lib/backup/syncer/base.rb +1 -1
  41. data/lib/backup/syncer/cloud/base.rb +15 -8
  42. data/lib/backup/syncer/rsync/local.rb +1 -1
  43. data/lib/backup/syncer/rsync/pull.rb +1 -1
  44. data/lib/backup/syncer/rsync/push.rb +1 -1
  45. data/lib/backup/utilities.rb +211 -0
  46. data/lib/backup/version.rb +1 -1
  47. data/templates/cli/{utility/archive → archive} +4 -8
  48. data/templates/cli/{utility/compressor → compressor}/bzip2 +0 -0
  49. data/templates/cli/{utility/compressor → compressor}/custom +0 -0
  50. data/templates/cli/{utility/compressor → compressor}/gzip +0 -0
  51. data/templates/cli/{utility/compressor → compressor}/lzma +0 -0
  52. data/templates/cli/{utility/compressor → compressor}/pbzip2 +0 -0
  53. data/templates/cli/config +68 -0
  54. data/templates/cli/{utility/database → database}/mongodb +1 -1
  55. data/templates/cli/{utility/database → database}/mysql +1 -1
  56. data/templates/cli/{utility/database → database}/postgresql +1 -1
  57. data/templates/cli/{utility/database → database}/redis +0 -0
  58. data/templates/cli/database/riak +20 -0
  59. data/templates/cli/{utility/encryptor → encryptor}/gpg +0 -0
  60. data/templates/cli/{utility/encryptor → encryptor}/openssl +0 -0
  61. data/templates/cli/{utility/model.erb → model.erb} +4 -4
  62. data/templates/cli/{utility/notifier → notifier}/campfire +0 -0
  63. data/templates/cli/{utility/notifier → notifier}/hipchat +0 -0
  64. data/templates/cli/{utility/notifier → notifier}/mail +0 -0
  65. data/templates/cli/{utility/notifier → notifier}/prowl +0 -0
  66. data/templates/cli/{utility/notifier → notifier}/pushover +0 -0
  67. data/templates/cli/{utility/notifier → notifier}/twitter +0 -0
  68. data/templates/cli/{utility/splitter → splitter} +0 -0
  69. data/templates/cli/{utility/storage → storage}/cloud_files +0 -0
  70. data/templates/cli/{utility/storage → storage}/dropbox +0 -0
  71. data/templates/cli/{utility/storage → storage}/ftp +0 -0
  72. data/templates/cli/{utility/storage → storage}/local +0 -0
  73. data/templates/cli/{utility/storage → storage}/ninefold +0 -0
  74. data/templates/cli/{utility/storage → storage}/rsync +0 -0
  75. data/templates/cli/{utility/storage → storage}/s3 +0 -0
  76. data/templates/cli/{utility/storage → storage}/scp +0 -0
  77. data/templates/cli/{utility/storage → storage}/sftp +0 -0
  78. data/templates/cli/{utility/syncer → syncer}/cloud_files +0 -0
  79. data/templates/cli/{utility/syncer → syncer}/rsync_local +0 -0
  80. data/templates/cli/{utility/syncer → syncer}/rsync_pull +0 -0
  81. data/templates/cli/{utility/syncer → syncer}/rsync_push +0 -0
  82. data/templates/cli/{utility/syncer → syncer}/s3 +0 -0
  83. metadata +55 -131
  84. data/.gitignore +0 -8
  85. data/.travis.yml +0 -10
  86. data/Gemfile +0 -28
  87. data/Guardfile +0 -23
  88. data/backup.gemspec +0 -32
  89. data/lib/backup/cli/helpers.rb +0 -93
  90. data/lib/backup/cli/utility.rb +0 -255
  91. data/spec-live/.gitignore +0 -6
  92. data/spec-live/README +0 -7
  93. data/spec-live/backups/config.rb +0 -83
  94. data/spec-live/backups/config.yml.template +0 -46
  95. data/spec-live/backups/models.rb +0 -184
  96. data/spec-live/compressor/custom_spec.rb +0 -30
  97. data/spec-live/compressor/gzip_spec.rb +0 -30
  98. data/spec-live/encryptor/gpg_keys.rb +0 -239
  99. data/spec-live/encryptor/gpg_spec.rb +0 -287
  100. data/spec-live/notifier/mail_spec.rb +0 -121
  101. data/spec-live/spec_helper.rb +0 -151
  102. data/spec-live/storage/dropbox_spec.rb +0 -151
  103. data/spec-live/storage/local_spec.rb +0 -83
  104. data/spec-live/storage/scp_spec.rb +0 -193
  105. data/spec-live/syncer/cloud/s3_spec.rb +0 -124
  106. data/spec/archive_spec.rb +0 -335
  107. data/spec/cleaner_spec.rb +0 -312
  108. data/spec/cli/helpers_spec.rb +0 -301
  109. data/spec/cli/utility_spec.rb +0 -411
  110. data/spec/compressor/base_spec.rb +0 -52
  111. data/spec/compressor/bzip2_spec.rb +0 -217
  112. data/spec/compressor/custom_spec.rb +0 -106
  113. data/spec/compressor/gzip_spec.rb +0 -217
  114. data/spec/compressor/lzma_spec.rb +0 -123
  115. data/spec/compressor/pbzip2_spec.rb +0 -165
  116. data/spec/config_spec.rb +0 -321
  117. data/spec/configuration/helpers_spec.rb +0 -247
  118. data/spec/configuration/store_spec.rb +0 -39
  119. data/spec/configuration_spec.rb +0 -62
  120. data/spec/database/base_spec.rb +0 -63
  121. data/spec/database/mongodb_spec.rb +0 -510
  122. data/spec/database/mysql_spec.rb +0 -411
  123. data/spec/database/postgresql_spec.rb +0 -353
  124. data/spec/database/redis_spec.rb +0 -334
  125. data/spec/database/riak_spec.rb +0 -176
  126. data/spec/dependency_spec.rb +0 -51
  127. data/spec/encryptor/base_spec.rb +0 -40
  128. data/spec/encryptor/gpg_spec.rb +0 -909
  129. data/spec/encryptor/open_ssl_spec.rb +0 -148
  130. data/spec/errors_spec.rb +0 -306
  131. data/spec/logger_spec.rb +0 -367
  132. data/spec/model_spec.rb +0 -666
  133. data/spec/notifier/base_spec.rb +0 -104
  134. data/spec/notifier/campfire_spec.rb +0 -217
  135. data/spec/notifier/hipchat_spec.rb +0 -211
  136. data/spec/notifier/mail_spec.rb +0 -316
  137. data/spec/notifier/prowl_spec.rb +0 -138
  138. data/spec/notifier/pushover_spec.rb +0 -123
  139. data/spec/notifier/twitter_spec.rb +0 -153
  140. data/spec/package_spec.rb +0 -61
  141. data/spec/packager_spec.rb +0 -213
  142. data/spec/pipeline_spec.rb +0 -259
  143. data/spec/spec_helper.rb +0 -60
  144. data/spec/splitter_spec.rb +0 -120
  145. data/spec/storage/base_spec.rb +0 -166
  146. data/spec/storage/cloudfiles_spec.rb +0 -254
  147. data/spec/storage/cycler_spec.rb +0 -247
  148. data/spec/storage/dropbox_spec.rb +0 -480
  149. data/spec/storage/ftp_spec.rb +0 -271
  150. data/spec/storage/local_spec.rb +0 -259
  151. data/spec/storage/ninefold_spec.rb +0 -343
  152. data/spec/storage/rsync_spec.rb +0 -362
  153. data/spec/storage/s3_spec.rb +0 -245
  154. data/spec/storage/scp_spec.rb +0 -233
  155. data/spec/storage/sftp_spec.rb +0 -244
  156. data/spec/syncer/base_spec.rb +0 -109
  157. data/spec/syncer/cloud/base_spec.rb +0 -515
  158. data/spec/syncer/cloud/cloud_files_spec.rb +0 -181
  159. data/spec/syncer/cloud/s3_spec.rb +0 -174
  160. data/spec/syncer/rsync/base_spec.rb +0 -98
  161. data/spec/syncer/rsync/local_spec.rb +0 -149
  162. data/spec/syncer/rsync/pull_spec.rb +0 -98
  163. data/spec/syncer/rsync/push_spec.rb +0 -333
  164. data/spec/version_spec.rb +0 -21
  165. data/templates/cli/utility/config +0 -32
  166. data/templates/cli/utility/database/riak +0 -11
@@ -1,259 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require File.expand_path('../spec_helper.rb', __FILE__)
4
-
5
- describe 'Backup::Pipeline' do
6
- let(:pipeline) { Backup::Pipeline.new }
7
-
8
- describe '#initialize' do
9
- it 'should create a new pipeline' do
10
- pipeline.instance_variable_get(:@commands).should == []
11
- pipeline.errors.should == []
12
- pipeline.stderr.should == ''
13
- end
14
- end
15
-
16
- describe '#<<' do
17
- it 'should add a command string to @commands' do
18
- pipeline << 'a command string'
19
- pipeline.instance_variable_get(:@commands).should == ['a command string']
20
- end
21
- end
22
-
23
- describe '#run' do
24
- let(:stdout) { mock }
25
- let(:stderr) { mock }
26
-
27
- before do
28
- pipeline.expects(:pipeline).returns('foo')
29
- # stub CLI::Helpers#command_name so it simply returns what it's passed
30
- pipeline.class.send(:define_method, :command_name, lambda {|arg| arg } )
31
- end
32
-
33
- context 'when pipeline command is successfully executed' do
34
- before do
35
- Open4.expects(:popen4).with('foo').yields(nil, nil, stdout, stderr)
36
- end
37
-
38
- context 'when all commands within the pipeline are successful' do
39
- before do
40
- stdout.expects(:read).returns("0|0:1|0:\n")
41
- end
42
-
43
- context 'when commands output no stderr messages' do
44
- before do
45
- stderr.expects(:read).returns('')
46
- pipeline.stubs(:stderr_messages).returns(false)
47
- end
48
-
49
- it 'should process the returned stdout/stderr and report no errors' do
50
- Backup::Logger.expects(:warn).never
51
-
52
- pipeline.run
53
- pipeline.stderr.should == ''
54
- pipeline.errors.should == []
55
- end
56
- end
57
-
58
- context 'when successful commands output messages on stderr' do
59
- before do
60
- stderr.expects(:read).returns("stderr output\n")
61
- pipeline.stubs(:stderr_messages).returns('stderr_messages_output')
62
- end
63
-
64
- it 'should log a warning with the stderr messages' do
65
- Backup::Logger.expects(:warn).with('stderr_messages_output')
66
-
67
- pipeline.run
68
- pipeline.stderr.should == 'stderr output'
69
- pipeline.errors.should == []
70
- end
71
- end
72
- end # context 'when all commands within the pipeline are successful'
73
-
74
- context 'when commands within the pipeline are not successful' do
75
- before do
76
- pipeline.instance_variable_set(:@commands, ['first', 'second', 'third'])
77
- stderr.expects(:read).returns("stderr output\n")
78
- pipeline.stubs(:stderr_messages).returns('success? should be false')
79
- end
80
-
81
- context 'when the commands return in sequence' do
82
- before do
83
- stdout.expects(:read).returns("0|0:1|1:2|0:\n")
84
- end
85
-
86
- it 'should set @errors and @stderr without logging warnings' do
87
- Backup::Logger.expects(:warn).never
88
-
89
- pipeline.run
90
- pipeline.stderr.should == 'stderr output'
91
- pipeline.errors.count.should be(1)
92
- pipeline.errors.first.should be_a_kind_of SystemCallError
93
- pipeline.errors.first.errno.should be(1)
94
- pipeline.errors.first.message.should match(
95
- "'second' returned exit code: 1"
96
- )
97
- end
98
- end # context 'when the commands return in sequence'
99
-
100
- context 'when the commands return out of sequence' do
101
- before do
102
- stdout.expects(:read).returns("1|1:2|0:0|0:\n")
103
- end
104
-
105
- it 'should properly associate the exitstatus for each command' do
106
- Backup::Logger.expects(:warn).never
107
-
108
- pipeline.run
109
- pipeline.stderr.should == 'stderr output'
110
- pipeline.errors.count.should be(1)
111
- pipeline.errors.first.should be_a_kind_of SystemCallError
112
- pipeline.errors.first.errno.should be(1)
113
- pipeline.errors.first.message.should match(
114
- "'second' returned exit code: 1"
115
- )
116
- end
117
- end # context 'when the commands return out of sequence'
118
-
119
- context 'when multiple commands fail (out of sequence)' do
120
- before do
121
- stdout.expects(:read).returns("1|1:2|0:0|3:\n")
122
- end
123
-
124
- it 'should properly associate the exitstatus for each command' do
125
- Backup::Logger.expects(:warn).never
126
-
127
- pipeline.run
128
- pipeline.stderr.should == 'stderr output'
129
- pipeline.errors.count.should be(2)
130
- pipeline.errors.each {|err| err.should be_a_kind_of SystemCallError }
131
- pipeline.errors[0].errno.should be(3)
132
- pipeline.errors[0].message.should match(
133
- "'first' returned exit code: 3"
134
- )
135
- pipeline.errors[1].errno.should be(1)
136
- pipeline.errors[1].message.should match(
137
- "'second' returned exit code: 1"
138
- )
139
- end
140
- end # context 'when the commands return (out of sequence)'
141
-
142
- end # context 'when commands within the pipeline are not successful'
143
- end # context 'when pipeline command is successfully executed'
144
-
145
- context 'when pipeline command fails to execute' do
146
- before do
147
- Open4.expects(:popen4).with('foo').raises('exec failed')
148
- end
149
-
150
- it 'should raise an error' do
151
- expect do
152
- pipeline.run
153
- end.to raise_error(
154
- Backup::Errors::Pipeline::ExecutionError,
155
- "Pipeline::ExecutionError: RuntimeError: exec failed"
156
- )
157
- end
158
- end # context 'when pipeline command fails to execute'
159
-
160
- end # describe '#run'
161
-
162
- describe '#success?' do
163
- it 'returns true when @errors is empty' do
164
- pipeline.success?.should be_true
165
- end
166
-
167
- it 'returns false when @errors is not empty' do
168
- pipeline.instance_variable_set(:@errors, ['foo'])
169
- pipeline.success?.should be_false
170
- end
171
- end # describe '#success?'
172
-
173
- describe '#error_messages' do
174
- before do
175
- pipeline.instance_variable_set(
176
- :@errors, [
177
- StandardError.new('standard error'),
178
- RuntimeError.new('runtime error')
179
- ]
180
- )
181
- end
182
-
183
- context 'when #stderr_messages has messages' do
184
- before do
185
- pipeline.expects(:stderr_messages).returns('stderr messages')
186
- end
187
-
188
- it 'should output #stderr_messages and formatted system error messages' do
189
- pipeline.error_messages.should == 'stderr messages' +
190
- "The following system errors were returned:\n" +
191
- "Error: StandardError: standard error\n" +
192
- "Error: RuntimeError: runtime error"
193
- end
194
- end
195
-
196
- context 'when #stderr_messages has no messages' do
197
- before do
198
- pipeline.expects(:stderr_messages).returns(false)
199
- end
200
-
201
- it 'should only output the formatted system error messages' do
202
- pipeline.error_messages.should ==
203
- "The following system errors were returned:\n" +
204
- "Error: StandardError: standard error\n" +
205
- "Error: RuntimeError: runtime error"
206
- end
207
- end
208
- end # describe '#error_messages'
209
-
210
- describe '#pipeline' do
211
- context 'when there are multiple system commands to execute' do
212
- before do
213
- pipeline.instance_variable_set(:@commands, %w{ one two three })
214
- end
215
-
216
- it 'should build a pipeline with redirected/collected exit codes' do
217
- pipeline.send(:pipeline).should ==
218
- '{ { one 2>&4 ; echo "0|$?:" >&3 ; } | ' +
219
- '{ two 2>&4 ; echo "1|$?:" >&3 ; } | ' +
220
- '{ three 2>&4 ; echo "2|$?:" >&3 ; } } 3>&1 1>&2 4>&2'
221
- end
222
- end
223
-
224
- context 'when there is only one system command to execute' do
225
- before do
226
- pipeline.instance_variable_set(:@commands, ['foo'])
227
- end
228
-
229
- it 'should build the command line in the same manner, but without pipes' do
230
- pipeline.send(:pipeline).should ==
231
- '{ { foo 2>&4 ; echo "0|$?:" >&3 ; } } 3>&1 1>&2 4>&2'
232
- end
233
- end
234
- end # describe '#pipeline'
235
-
236
- describe '#stderr_message' do
237
- context 'when @stderr has messages' do
238
- before do
239
- pipeline.instance_variable_set(:@stderr, "stderr message\n output")
240
- end
241
-
242
- it 'should return a formatted message with the @stderr messages' do
243
- pipeline.send(:stderr_messages).should ==
244
- " Pipeline STDERR Messages:\n" +
245
- " (Note: may be interleaved if multiple commands returned error messages)\n" +
246
- "\n" +
247
- " stderr message\n" +
248
- " output\n"
249
- end
250
- end
251
-
252
- context 'when @stderr is empty' do
253
- it 'should return false' do
254
- pipeline.send(:stderr_messages).should be_false
255
- end
256
- end
257
- end # describe '#stderr_message'
258
-
259
- end #describe 'Backup::Pipeline'
data/spec/spec_helper.rb DELETED
@@ -1,60 +0,0 @@
1
- # encoding: utf-8
2
-
3
- ##
4
- # Use Bundler
5
- require 'rubygems' if RUBY_VERSION < '1.9'
6
- require 'bundler/setup'
7
-
8
- ##
9
- # Load Backup
10
- require 'backup'
11
-
12
- require 'timecop'
13
-
14
- module Backup::ExampleHelpers
15
- # ripped from MiniTest :)
16
- # RSpec doesn't have a method for this? Am I missing something?
17
- def capture_io
18
- require 'stringio'
19
-
20
- orig_stdout, orig_stderr = $stdout, $stderr
21
- captured_stdout, captured_stderr = StringIO.new, StringIO.new
22
- $stdout, $stderr = captured_stdout, captured_stderr
23
-
24
- yield
25
-
26
- return captured_stdout.string, captured_stderr.string
27
- ensure
28
- $stdout = orig_stdout
29
- $stderr = orig_stderr
30
- end
31
- end
32
-
33
- require 'rspec/autorun'
34
- RSpec.configure do |config|
35
- ##
36
- # Use Mocha to mock with RSpec
37
- config.mock_with :mocha
38
-
39
- ##
40
- # Example Helpers
41
- config.include Backup::ExampleHelpers
42
-
43
- ##
44
- # Actions to perform before each example
45
- config.before(:each) do
46
- FileUtils.collect_method(:noop).each do |method|
47
- FileUtils.stubs(method).raises("Unexpected call to FileUtils.#{ method }")
48
- end
49
-
50
- Open4.stubs(:popen4).raises('Unexpected call to Open4::popen4()')
51
-
52
- [:message, :error, :warn, :normal, :silent].each do |method|
53
- Backup::Logger.stubs(method).raises("Unexpected call to Backup::Logger.#{ method }")
54
- end
55
- end
56
- end
57
-
58
- unless @_put_ruby_version
59
- puts @_put_ruby_version = "\n\nRuby version: #{ RUBY_DESCRIPTION }\n\n"
60
- end
@@ -1,120 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require File.expand_path('../spec_helper.rb', __FILE__)
4
-
5
- describe Backup::Splitter do
6
- let(:model) { Backup::Model.new(:test_trigger, 'test label') }
7
- let(:splitter) { Backup::Splitter.new(model, 250) }
8
- let(:package) { mock }
9
-
10
- describe '#initialize' do
11
- it 'should set instance variables' do
12
- splitter.instance_variable_get(:@model).should be(model)
13
- splitter.instance_variable_get(:@chunk_size).should be(250)
14
- end
15
- end
16
-
17
- describe '#split_with' do
18
- it 'should yield the split command, performing before/after methods' do
19
- s = sequence ''
20
- given_block = mock
21
- block = lambda {|arg| given_block.got(arg) }
22
- splitter.instance_variable_set(:@split_command, 'split command')
23
-
24
- splitter.expects(:before_packaging).in_sequence(s)
25
- given_block.expects(:got).in_sequence(s).with('split command')
26
- splitter.expects(:after_packaging).in_sequence(s)
27
-
28
- splitter.split_with(&block)
29
- end
30
- end
31
-
32
- # Note: using a 'M' suffix for the byte size is not OSX compatible
33
- describe '#before_packaging' do
34
- before do
35
- model.instance_variable_set(:@package, package)
36
- splitter.expects(:utility).with(:split).returns('split')
37
- package.expects(:basename).returns('base_filename')
38
- end
39
-
40
- it 'should set @package and @split_command' do
41
- Backup::Logger.expects(:message).with(
42
- 'Splitter configured with a chunk size of 250MB.'
43
- )
44
- splitter.send(:before_packaging)
45
-
46
- splitter.instance_variable_get(:@package).should be(package)
47
-
48
- split_suffix = File.join(Backup::Config.tmp_path, 'base_filename-')
49
- splitter.instance_variable_get(:@split_command).should ==
50
- "split -b 250m - '#{ split_suffix }'"
51
- end
52
- end
53
-
54
- describe '#after_packaging' do
55
- before do
56
- splitter.instance_variable_set(:@package, package)
57
- end
58
-
59
- context 'when splitting occurred during packaging' do
60
- before do
61
- splitter.expects(:chunk_suffixes).returns(['aa', 'ab'])
62
- end
63
-
64
- it 'should set the chunk_suffixes for the package' do
65
- package.expects(:chunk_suffixes=).with(['aa', 'ab'])
66
- splitter.send(:after_packaging)
67
- end
68
- end
69
-
70
- context 'when splitting did not occur during packaging' do
71
- before do
72
- splitter.expects(:chunk_suffixes).returns(['aa'])
73
- package.expects(:basename).twice.returns('base_filename')
74
- end
75
-
76
- it 'should remove the suffix from the only package file' do
77
- package.expects(:chunk_suffixes=).never
78
- FileUtils.expects(:mv).with(
79
- File.join(Backup::Config.tmp_path, 'base_filename-aa'),
80
- File.join(Backup::Config.tmp_path, 'base_filename')
81
- )
82
- splitter.send(:after_packaging)
83
- end
84
- end
85
- end # describe '#after_packaging'
86
-
87
- describe '#chunk_suffixes' do
88
- before do
89
- splitter.expects(:chunks).returns(
90
- ['/path/to/file.tar-aa', '/path/to/file.tar-ab']
91
- )
92
- end
93
-
94
- it 'should return an array of chunk suffixes' do
95
- splitter.send(:chunk_suffixes).should == ['aa', 'ab']
96
- end
97
- end
98
-
99
- describe '#chunks' do
100
- before do
101
- splitter.instance_variable_set(:@package, package)
102
- package.expects(:basename).returns('base_filename')
103
- FileUtils.unstub(:touch)
104
- end
105
-
106
- it 'should return a sorted array of chunked file paths' do
107
- Dir.mktmpdir do |dir|
108
- Backup::Config.expects(:tmp_path).returns(dir)
109
- FileUtils.touch(File.join(dir, 'base_filename-aa'))
110
- FileUtils.touch(File.join(dir, 'base_filename-ab'))
111
-
112
- splitter.send(:chunks).should == [
113
- File.join(dir, 'base_filename-aa'),
114
- File.join(dir, 'base_filename-ab')
115
- ]
116
- end
117
- end
118
- end
119
-
120
- end
@@ -1,166 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require File.expand_path('../../spec_helper.rb', __FILE__)
4
-
5
- describe Backup::Storage::Base do
6
- let(:model) { Backup::Model.new(:test_trigger, 'test label') }
7
- let(:package) { mock }
8
- let(:storage) { Backup::Storage::Base.new(model) }
9
-
10
- it 'should include Configuration::Helpers' do
11
- Backup::Storage::Base.
12
- include?(Backup::Configuration::Helpers).should be_true
13
- end
14
-
15
- describe '#initialize' do
16
- after { Backup::Storage::Base.clear_defaults! }
17
-
18
- it 'should load pre-configured defaults' do
19
- Backup::Storage::Base.any_instance.expects(:load_defaults!)
20
- storage
21
- end
22
-
23
- it 'should set a reference to the model' do
24
- storage.instance_variable_get(:@model).should == model
25
- end
26
-
27
- it 'should set a reference to the storage_id' do
28
- storage = Backup::Storage::Base.new(model, 'test_id')
29
- storage.storage_id.should == 'test_id'
30
- end
31
-
32
- it 'should not require the storage_id' do
33
- storage.instance_variable_defined?(:@storage_id).should be_true
34
- storage.storage_id.should be_nil
35
- end
36
-
37
- context 'when no pre-configured defaults have been set' do
38
- it 'should set default values' do
39
- storage.keep.should be_nil
40
- storage.storage_id.should be_nil
41
- end
42
- end # context 'when no pre-configured defaults have been set'
43
-
44
- context 'when pre-configured defaults have been set' do
45
- before do
46
- Backup::Storage::Base.defaults do |s|
47
- s.keep = 5
48
- end
49
- end
50
-
51
- it 'should use pre-configured defaults' do
52
- storage.keep.should be(5)
53
- end
54
- end # context 'when pre-configured defaults have been set'
55
- end # describe '#initialize'
56
-
57
- describe '#perform!' do
58
- before do
59
- model.instance_variable_set(:@package, package)
60
- end
61
-
62
- it 'should call #transfer!, then #cycle!' do
63
- s = sequence ''
64
- storage.expects(:transfer!).in_sequence(s)
65
- storage.expects(:cycle!).in_sequence(s)
66
- storage.perform!
67
- storage.instance_variable_get(:@package).should be(package)
68
- end
69
- end
70
-
71
- describe '#storage_name' do
72
- context 'when given a storage_id' do
73
- before { storage.storage_id = 'storage id' }
74
- it 'should return a log-friendly name with the storage_id' do
75
- storage.send(:storage_name).should == 'Storage::Base (storage id)'
76
- end
77
- end
78
-
79
- context 'when not given a storage_id' do
80
- it 'should return a log-friendly name without a storage_id' do
81
- storage.send(:storage_name).should == 'Storage::Base'
82
- end
83
- end
84
- end
85
-
86
- describe '#local_path' do
87
- it 'should return the configured tmp_path' do
88
- storage.send(:local_path).should == Backup::Config.tmp_path
89
- end
90
- end
91
-
92
- describe '#remote_path_for' do
93
- before do
94
- package.expects(:trigger).returns('test_trigger')
95
- package.expects(:time).returns('backup_time')
96
- storage.expects(:path).returns('base/remote/path')
97
- end
98
-
99
- it 'should return the remote_path for the given package' do
100
- storage.send(:remote_path_for, package).should ==
101
- File.join('base/remote/path', 'test_trigger', 'backup_time')
102
- end
103
- end
104
-
105
- describe '#files_to_transfer_for' do
106
- let(:given_block) { mock }
107
- before do
108
- package.stubs(:filenames).returns(
109
- ['2011.12.31.11.00.02.backup.tar.enc-aa',
110
- '2011.12.31.11.00.02.backup.tar.enc-ab']
111
- )
112
- end
113
-
114
- it 'should yield the full filename and the filename without the timestamp' do
115
- given_block.expects(:got).with(
116
- '2011.12.31.11.00.02.backup.tar.enc-aa', 'backup.tar.enc-aa'
117
- )
118
- given_block.expects(:got).with(
119
- '2011.12.31.11.00.02.backup.tar.enc-ab', 'backup.tar.enc-ab'
120
- )
121
- storage.send(:files_to_transfer_for, package) do |local_file, remote_file|
122
- given_block.got(local_file, remote_file)
123
- end
124
- end
125
-
126
- it 'should have an alias method called #transferred_files_for' do
127
- storage.method(:transferred_files_for).should ==
128
- storage.method(:files_to_transfer_for)
129
- end
130
- end
131
-
132
- describe '#cycle!' do
133
- before do
134
- storage.stubs(:storage_name).returns('Storage Name')
135
- storage.instance_variable_set(:@package, package)
136
- end
137
-
138
- context 'when keep is set and > 0' do
139
- before { storage.keep = 1 }
140
- it 'should cycle' do
141
- s = sequence ''
142
- Backup::Logger.expects(:message).in_sequence(s).
143
- with('Storage Name: Cycling Started...')
144
- Backup::Storage::Cycler.expects(:cycle!).in_sequence(s).
145
- with(storage, package)
146
- Backup::Logger.expects(:message).in_sequence(s).
147
- with('Storage Name: Cycling Complete!')
148
-
149
- storage.send(:cycle!)
150
- end
151
- end
152
-
153
- context 'when keep is not set or == 0' do
154
- it 'should return nil when not set' do
155
- storage.keep = nil
156
- storage.send(:cycle!).should be_nil
157
- end
158
-
159
- it 'should return nil when == 0' do
160
- storage.keep = 0
161
- storage.send(:cycle!).should be_nil
162
- end
163
- end
164
- end
165
-
166
- end