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
data/spec/archive_spec.rb DELETED
@@ -1,335 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require File.expand_path('../spec_helper.rb', __FILE__)
4
-
5
- describe Backup::Archive do
6
- let(:model) { Backup::Model.new(:test_trigger, 'test model') }
7
- let(:archive) { Backup::Archive.new(model, :test_archive) }
8
-
9
- describe '#initialize' do
10
-
11
- it 'should have no paths' do
12
- archive.paths.should == []
13
- end
14
-
15
- it 'should have no excludes' do
16
- archive.excludes.should == []
17
- end
18
-
19
- it 'should have no tar_args' do
20
- archive.tar_args.should == ''
21
- end
22
-
23
- it 'should set a reference to the given model' do
24
- archive.instance_variable_get(:@model).should be(model)
25
- end
26
-
27
- it 'should convert name to a String' do
28
- archive.name.should be_a_kind_of String
29
- archive.name.should == 'test_archive'
30
- end
31
-
32
- context 'when a configuration block is given' do
33
- let(:archive) do
34
- Backup::Archive.new(model, :test_archive) do |a|
35
- a.add 'added_path'
36
- a.add 'another/added_path'
37
- a.exclude 'excluded_path'
38
- a.exclude 'another/excluded_path'
39
- a.tar_options '-h --xattrs'
40
- end
41
- end
42
-
43
- before do
44
- File.stubs(:exist?).returns(true)
45
- end
46
-
47
- it 'should add @paths' do
48
- archive.paths.should == [
49
- File.expand_path('added_path'),
50
- File.expand_path('another/added_path')
51
- ]
52
- end
53
-
54
- it 'should add @excludes' do
55
- archive.excludes.should == [
56
- File.expand_path('excluded_path'),
57
- File.expand_path('another/excluded_path')
58
- ]
59
- end
60
-
61
- it 'should add @tar_args' do
62
- archive.tar_args.should == '-h --xattrs'
63
- end
64
- end
65
-
66
- end # describe '#initialize'
67
-
68
- describe '#add' do
69
-
70
- context 'when the path exists' do
71
- it 'should expand and add the path to @paths' do
72
- File.expects(:exist?).with(File.expand_path('foo')).returns(true)
73
- Backup::Logger.expects(:warn).never
74
-
75
- archive.add 'foo'
76
- archive.paths.should == [File.expand_path('foo')]
77
- end
78
- end
79
-
80
- context 'when a path does not exist' do
81
- it 'should omit the path and log a warning' do
82
- File.expects(:exist?).with(
83
- File.expand_path('path')
84
- ).returns(true)
85
- File.expects(:exist?).with(
86
- File.expand_path('foo')
87
- ).returns(false)
88
- File.expects(:exist?).with(
89
- File.expand_path('another/path')
90
- ).returns(true)
91
-
92
- Backup::Logger.expects(:warn).with do |err|
93
- err.should be_an_instance_of Backup::Errors::Archive::NotFoundError
94
- err.message.should ==
95
- "Archive::NotFoundError: The following path was not found:\n" +
96
- " #{ File.expand_path('foo') }\n" +
97
- " This path will be omitted from the 'test_archive' Archive."
98
- end
99
-
100
- archive.add 'path'
101
- archive.add 'foo'
102
- archive.add 'another/path'
103
- archive.paths.should == [
104
- File.expand_path('path'),
105
- File.expand_path('another/path')
106
- ]
107
- end
108
- end
109
- end
110
-
111
- describe '#exclude' do
112
- it 'should expand and add the given path to #excludes' do
113
- archive.exclude 'path'
114
- archive.exclude 'another/path'
115
- archive.excludes.should == [
116
- File.expand_path('path'),
117
- File.expand_path('another/path')
118
- ]
119
- end
120
- end
121
-
122
- describe '#tar_options' do
123
- it 'should set #tar_options to the given string' do
124
- archive = Backup::Archive.new(model, :test_archive) do |a|
125
- a.tar_options '-h --xattrs'
126
- end
127
- archive.tar_args.should == '-h --xattrs'
128
- end
129
- end
130
-
131
- describe '#perform!' do
132
- let(:archive_path) do
133
- File.join(Backup::Config.tmp_path, 'test_trigger', 'archives')
134
- end
135
- let(:paths) { ['/path/to/add', '/another/path/to/add'] }
136
- let(:excludes) { ['/path/to/exclude', '/another/path/to/exclude'] }
137
- let(:pipeline) { mock }
138
- let(:s) { sequence '' }
139
-
140
- before do
141
- archive.instance_variable_set(:@paths, paths)
142
- archive.expects(:utility).with(:tar).returns('tar')
143
- FileUtils.expects(:mkdir_p).with(archive_path)
144
- Backup::Pipeline.expects(:new).returns(pipeline)
145
- end
146
-
147
- context 'when both #paths and #excludes were added' do
148
- before do
149
- archive.instance_variable_set(:@excludes, excludes)
150
- end
151
-
152
- it 'should render the syntax for both' do
153
- Backup::Logger.expects(:message).in_sequence(s).with(
154
- "Backup::Archive has started archiving:\n" +
155
- " /path/to/add\n" +
156
- " /another/path/to/add"
157
- )
158
-
159
- pipeline.expects(:<<).in_sequence(s).with(
160
- "tar -cPf - " +
161
- "--exclude='/path/to/exclude' --exclude='/another/path/to/exclude' " +
162
- "'/path/to/add' '/another/path/to/add'"
163
- )
164
- pipeline.expects(:<<).in_sequence(s).with(
165
- "cat > '#{ File.join(archive_path, 'test_archive.tar') }'"
166
- )
167
- pipeline.expects(:run).in_sequence(s)
168
- pipeline.expects(:success?).in_sequence(s).returns(true)
169
-
170
- Backup::Logger.expects(:message).in_sequence(s).with(
171
- "Backup::Archive Complete!"
172
- )
173
-
174
- archive.perform!
175
- end
176
- end # context 'when both #paths and #excludes were added'
177
-
178
- context 'when no excludes were added' do
179
- it 'should render only the syntax for adds' do
180
- Backup::Logger.expects(:message).in_sequence(s).with(
181
- "Backup::Archive has started archiving:\n" +
182
- " /path/to/add\n" +
183
- " /another/path/to/add"
184
- )
185
-
186
- pipeline.expects(:<<).in_sequence(s).with(
187
- "tar -cPf - '/path/to/add' '/another/path/to/add'"
188
- )
189
- pipeline.expects(:<<).in_sequence(s).with(
190
- "cat > '#{ File.join(archive_path, 'test_archive.tar') }'"
191
- )
192
- pipeline.expects(:run).in_sequence(s)
193
- pipeline.expects(:success?).in_sequence(s).returns(true)
194
-
195
- Backup::Logger.expects(:message).in_sequence(s).with(
196
- "Backup::Archive Complete!"
197
- )
198
-
199
- archive.perform!
200
- end
201
- end # context 'when no excludes were added'
202
-
203
- context 'with #paths, #excludes and #tar_args' do
204
- before do
205
- archive.instance_variable_set(:@excludes, excludes)
206
- archive.instance_variable_set(:@tar_args, '-h --xattrs')
207
- end
208
-
209
- it 'should render the syntax for all three' do
210
- Backup::Logger.expects(:message).in_sequence(s).with(
211
- "Backup::Archive has started archiving:\n" +
212
- " /path/to/add\n" +
213
- " /another/path/to/add"
214
- )
215
-
216
- pipeline.expects(:<<).in_sequence(s).with(
217
- "tar -h --xattrs -cPf - " +
218
- "--exclude='/path/to/exclude' --exclude='/another/path/to/exclude' " +
219
- "'/path/to/add' '/another/path/to/add'"
220
- )
221
- pipeline.expects(:<<).in_sequence(s).with(
222
- "cat > '#{ File.join(archive_path, 'test_archive.tar') }'"
223
- )
224
- pipeline.expects(:run).in_sequence(s)
225
- pipeline.expects(:success?).in_sequence(s).returns(true)
226
-
227
- Backup::Logger.expects(:message).in_sequence(s).with(
228
- "Backup::Archive Complete!"
229
- )
230
-
231
- archive.perform!
232
- end
233
- end # context 'with #paths, #excludes and #tar_args'
234
-
235
- context 'with #paths, #excludes, #tar_args and a Gzip Compressor' do
236
- before do
237
- archive.instance_variable_set(:@excludes, excludes)
238
- archive.instance_variable_set(:@tar_args, '-h --xattrs')
239
- compressor = mock
240
- model.expects(:compressor).twice.returns(compressor)
241
- compressor.expects(:compress_with).yields('gzip', '.gz')
242
- end
243
-
244
- it 'should render the syntax with compressor modifications' do
245
- Backup::Logger.expects(:message).in_sequence(s).with(
246
- "Backup::Archive has started archiving:\n" +
247
- " /path/to/add\n" +
248
- " /another/path/to/add"
249
- )
250
-
251
- pipeline.expects(:<<).in_sequence(s).with(
252
- "tar -h --xattrs -cPf - " +
253
- "--exclude='/path/to/exclude' --exclude='/another/path/to/exclude' " +
254
- "'/path/to/add' '/another/path/to/add'"
255
- )
256
- pipeline.expects(:<<).in_sequence(s).with('gzip')
257
- pipeline.expects(:<<).in_sequence(s).with(
258
- "cat > '#{ File.join(archive_path, 'test_archive.tar.gz') }'"
259
- )
260
- pipeline.expects(:run).in_sequence(s)
261
- pipeline.expects(:success?).in_sequence(s).returns(true)
262
-
263
- Backup::Logger.expects(:message).in_sequence(s).with(
264
- "Backup::Archive Complete!"
265
- )
266
-
267
- archive.perform!
268
- end
269
- end # context 'with #paths, #excludes, #tar_args and a Gzip Compressor'
270
-
271
- context 'when pipeline command fails' do
272
- before do
273
- pipeline.stubs(:<<)
274
- pipeline.expects(:run)
275
- pipeline.expects(:success?).returns(false)
276
- pipeline.expects(:error_messages).returns('pipeline_errors')
277
- end
278
-
279
- it 'should raise an error' do
280
- Backup::Logger.expects(:message).with(
281
- "Backup::Archive has started archiving:\n" +
282
- " /path/to/add\n" +
283
- " /another/path/to/add"
284
- )
285
-
286
- expect do
287
- archive.perform!
288
- end.to raise_error(
289
- Backup::Errors::Archive::PipelineError,
290
- "Archive::PipelineError: Failed to Create Backup Archive\n" +
291
- " pipeline_errors"
292
- )
293
- end
294
- end # context 'when pipeline command fails'
295
-
296
- end # describe '#perform!'
297
-
298
- describe '#paths_to_package' do
299
- before do
300
- archive.instance_variable_set(
301
- :@paths,
302
- ['/home/rspecuser/somefile',
303
- '/home/rspecuser/logs',
304
- '/home/rspecuser/dotfiles']
305
- )
306
- end
307
-
308
- it 'should return a tar friendly string' do
309
- archive.send(:paths_to_package).should ==
310
- "'/home/rspecuser/somefile' '/home/rspecuser/logs' '/home/rspecuser/dotfiles'"
311
- end
312
- end
313
-
314
- describe '#paths_to_exclude' do
315
- context 'when no excludes are added' do
316
- it 'should return nil' do
317
- archive.send(:paths_to_exclude).should be_nil
318
- end
319
- end
320
-
321
- context 'when excludes are added' do
322
- before do
323
- archive.instance_variable_set(
324
- :@excludes,
325
- ['/home/rspecuser/badfile',
326
- '/home/rspecuser/wrongdir']
327
- )
328
- end
329
- it 'should return a tar friendly string' do
330
- archive.send(:paths_to_exclude).should ==
331
- "--exclude='/home/rspecuser/badfile' --exclude='/home/rspecuser/wrongdir'"
332
- end
333
- end
334
- end
335
- end
data/spec/cleaner_spec.rb DELETED
@@ -1,312 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require File.expand_path('../spec_helper.rb', __FILE__)
4
-
5
- describe 'Backup::Cleaner' do
6
- let(:model) { Backup::Model.new(:test_trigger, 'test label') }
7
- let(:cleaner) { Backup::Cleaner }
8
-
9
- describe '#prepare' do
10
- let(:error_tail) do
11
- " Please check the log for messages and/or your notifications\n" +
12
- " concerning this backup: 'test label (test_trigger)'\n" +
13
- " The temporary files which had to be removed should not have existed."
14
- end
15
-
16
- context 'when neither the tmp_path is dirty or package files exist' do
17
- it 'should do nothing' do
18
- cleaner.expects(:packaging_folder_dirty?).returns(false)
19
- cleaner.expects(:tmp_path_package_files).returns([])
20
- FileUtils.expects(:rm_rf).never
21
- FileUtils.expects(:rm_f).never
22
- Backup::Logger.expects(:warn).never
23
-
24
- cleaner.prepare(model)
25
- end
26
- end
27
-
28
- context 'when the tmp_path is dirty' do
29
- it 'should remove tmp_path and log a warning' do
30
- cleaner.expects(:packaging_folder_dirty?).returns(true)
31
- cleaner.expects(:tmp_path_package_files).returns([])
32
- FileUtils.expects(:rm_f).never
33
-
34
- FileUtils.expects(:rm_rf).with(
35
- File.join(Backup::Config.tmp_path, 'test_trigger')
36
- )
37
- Backup::Logger.expects(:warn).with do |err|
38
- err.should be_an_instance_of Backup::Errors::CleanerError
39
- err.message.should == "CleanerError: Cleanup Warning\n" +
40
- " The temporary backup folder still contains files!\n" +
41
- " '#{ File.join(Backup::Config.tmp_path, 'test_trigger') }'\n" +
42
- " These files will now be removed.\n" +
43
- " \n" + error_tail
44
- end
45
-
46
- cleaner.prepare(model)
47
- end
48
- end
49
-
50
- context 'when package files exist' do
51
- it 'should remove the files and log a warning' do
52
- cleaner.expects(:packaging_folder_dirty?).returns(false)
53
- cleaner.expects(:tmp_path_package_files).returns(['file1', 'file2'])
54
- FileUtils.expects(:rm_rf).never
55
-
56
- FileUtils.expects(:rm_f).with('file1')
57
- FileUtils.expects(:rm_f).with('file2')
58
-
59
- Backup::Logger.expects(:warn).with do |err|
60
- err.should be_an_instance_of Backup::Errors::CleanerError
61
- err.message.should == "CleanerError: Cleanup Warning\n" +
62
- " The temporary backup folder '#{ Backup::Config.tmp_path }'\n" +
63
- " appears to contain the package files from the previous backup!\n" +
64
- " file1\n" +
65
- " file2\n" +
66
- " These files will now be removed.\n" +
67
- " \n" + error_tail
68
- end
69
-
70
- cleaner.prepare(model)
71
- end
72
- end
73
-
74
- context 'both the tmp_path is dirty and package files exist' do
75
- it 'should clean both and log a warning' do
76
- cleaner.expects(:packaging_folder_dirty?).returns(true)
77
- cleaner.expects(:tmp_path_package_files).returns(['file1', 'file2'])
78
-
79
- FileUtils.expects(:rm_rf).with(
80
- File.join(Backup::Config.tmp_path, 'test_trigger')
81
- )
82
- FileUtils.expects(:rm_f).with('file1')
83
- FileUtils.expects(:rm_f).with('file2')
84
-
85
- Backup::Logger.expects(:warn).with do |err|
86
- err.should be_an_instance_of Backup::Errors::CleanerError
87
- err.message.should == "CleanerError: Cleanup Warning\n" +
88
- " The temporary backup folder still contains files!\n" +
89
- " '#{ File.join(Backup::Config.tmp_path, 'test_trigger') }'\n" +
90
- " These files will now be removed.\n" +
91
- " \n" +
92
- " #{ '-' * 74 }\n" +
93
- " The temporary backup folder '#{ Backup::Config.tmp_path }'\n" +
94
- " appears to contain the package files from the previous backup!\n" +
95
- " file1\n" +
96
- " file2\n" +
97
- " These files will now be removed.\n" +
98
- " \n" + error_tail
99
- end
100
-
101
- cleaner.prepare(model)
102
- end
103
- end
104
-
105
- end # describe '#prepare'
106
-
107
- describe '#remove_packaging' do
108
- it 'should remove the packaging directory and log a message' do
109
- Backup::Logger.expects(:message).with(
110
- "Cleaning up the temporary files..."
111
- )
112
- FileUtils.expects(:rm_rf).with(
113
- File.join(Backup::Config.tmp_path, 'test_trigger')
114
- )
115
-
116
- cleaner.remove_packaging(model)
117
- end
118
- end
119
-
120
- describe '#remove_package' do
121
- let(:package) { mock }
122
- it 'should remove the files for the given package and log a message' do
123
- package.expects(:filenames).returns(['file1', 'file2'])
124
- Backup::Logger.expects(:message).with(
125
- "Cleaning up the package files..."
126
- )
127
- FileUtils.expects(:rm_f).with(
128
- File.join(Backup::Config.tmp_path, 'file1')
129
- )
130
- FileUtils.expects(:rm_f).with(
131
- File.join(Backup::Config.tmp_path, 'file2')
132
- )
133
-
134
- cleaner.remove_package(package)
135
- end
136
- end
137
-
138
- describe '#warnings' do
139
- let(:error_tail) do
140
- " Make sure you check these files before the next scheduled backup for\n" +
141
- " 'test label (test_trigger)'\n" +
142
- " These files will be removed at that time!"
143
- end
144
-
145
- context 'when neither the tmp_path is dirty or package files exist' do
146
- it 'should do nothing' do
147
- cleaner.expects(:packaging_folder_dirty?).returns(false)
148
- cleaner.expects(:tmp_path_package_files).returns([])
149
- Backup::Logger.expects(:warn).never
150
-
151
- cleaner.warnings(model)
152
- end
153
- end
154
-
155
- context 'when the tmp_path is dirty' do
156
- it 'should remove tmp_path and log a warning' do
157
- cleaner.expects(:packaging_folder_dirty?).returns(true)
158
- cleaner.expects(:tmp_path_package_files).returns([])
159
-
160
- Backup::Logger.expects(:warn).with do |err|
161
- err.should be_an_instance_of Backup::Errors::CleanerError
162
- err.message.should == "CleanerError: Cleanup Warning\n" +
163
- " The temporary backup folder still contains files!\n" +
164
- " '#{ File.join(Backup::Config.tmp_path, 'test_trigger') }'\n" +
165
- " This folder may contain completed Archives and/or Database backups.\n" +
166
- " \n" + error_tail
167
- end
168
-
169
- cleaner.warnings(model)
170
- end
171
- end
172
-
173
- context 'when package files exist' do
174
- it 'should remove the files and log a warning' do
175
- cleaner.expects(:packaging_folder_dirty?).returns(false)
176
- cleaner.expects(:tmp_path_package_files).returns(['file1', 'file2'])
177
-
178
- Backup::Logger.expects(:warn).with do |err|
179
- err.should be_an_instance_of Backup::Errors::CleanerError
180
- err.message.should == "CleanerError: Cleanup Warning\n" +
181
- " The temporary backup folder '#{ Backup::Config.tmp_path }'\n" +
182
- " appears to contain the backup files which were to be stored:\n" +
183
- " file1\n" +
184
- " file2\n" +
185
- " \n" + error_tail
186
- end
187
-
188
- cleaner.warnings(model)
189
- end
190
- end
191
-
192
- context 'both the tmp_path is dirty and package files exist' do
193
- it 'should clean both and log a warning' do
194
- cleaner.expects(:packaging_folder_dirty?).returns(true)
195
- cleaner.expects(:tmp_path_package_files).returns(['file1', 'file2'])
196
-
197
- Backup::Logger.expects(:warn).with do |err|
198
- err.should be_an_instance_of Backup::Errors::CleanerError
199
- err.message.should == "CleanerError: Cleanup Warning\n" +
200
- " The temporary backup folder still contains files!\n" +
201
- " '#{ File.join(Backup::Config.tmp_path, 'test_trigger') }'\n" +
202
- " This folder may contain completed Archives and/or Database backups.\n" +
203
- " \n" +
204
- " #{ '-' * 74 }\n" +
205
- " The temporary backup folder '#{ Backup::Config.tmp_path }'\n" +
206
- " appears to contain the backup files which were to be stored:\n" +
207
- " file1\n" +
208
- " file2\n" +
209
- " \n" + error_tail
210
- end
211
-
212
- cleaner.warnings(model)
213
- end
214
- end
215
-
216
- end # describe '#warnings'
217
-
218
- describe '#packaging_folder_dirty?' do
219
- before do
220
- cleaner.instance_variable_set(:@model, model)
221
- FileUtils.unstub(:mkdir_p)
222
- end
223
-
224
- after do
225
- Backup::Config.send(:reset!)
226
- end
227
-
228
- context 'when files exist in the packaging folder' do
229
- it 'should return true' do
230
- Dir.mktmpdir do |path|
231
- Backup::Config.update(:root_path => path)
232
- FileUtils.mkdir_p(
233
- File.join(Backup::Config.tmp_path, 'test_trigger', 'archives')
234
- )
235
- cleaner.send(:packaging_folder_dirty?).should be_true
236
- end
237
- end
238
- end
239
-
240
- context 'when files do not exist in the packaging folder' do
241
- it 'should return false' do
242
- Dir.mktmpdir do |path|
243
- Backup::Config.update(:root_path => path)
244
- FileUtils.mkdir_p(
245
- File.join(Backup::Config.tmp_path, 'test_trigger')
246
- )
247
- cleaner.send(:packaging_folder_dirty?).should be_false
248
- end
249
- end
250
- end
251
- end
252
-
253
- describe '#tmp_path_package_files' do
254
- before do
255
- cleaner.instance_variable_set(:@model, model)
256
- FileUtils.unstub(:mkdir_p)
257
- FileUtils.unstub(:touch)
258
- end
259
-
260
- after do
261
- Backup::Config.send(:reset!)
262
- end
263
-
264
- context 'when packaging files exist in the tmp_path' do
265
- it 'should return the files' do
266
- Dir.mktmpdir do |path|
267
- Backup::Config.update(:root_path => path)
268
- FileUtils.mkdir_p(Backup::Config.tmp_path)
269
-
270
- package_files = [
271
- '2012.01.06.12.05.30.test_trigger.tar',
272
- '2012.02.06.12.05.30.test_trigger.tar-aa',
273
- '2012.03.06.12.05.30.test_trigger.tar.enc',
274
- '2012.04.06.12.05.30.test_trigger.tar.enc-aa'
275
- ].map! {|f| File.join(Backup::Config.tmp_path, f) }
276
-
277
- other_files = [
278
- '2012.01.06.12.05.30.test_trigger.target.tar',
279
- '2012.01.06.12.05.30.other_trigger.tar',
280
- 'foo.tar'
281
- ].map! {|f| File.join(Backup::Config.tmp_path, f) }
282
-
283
- FileUtils.touch(package_files + other_files)
284
- Dir[File.join(Backup::Config.tmp_path, '*')].count.should be(7)
285
-
286
- cleaner.send(:tmp_path_package_files).sort.should == package_files
287
- end
288
- end
289
- end
290
-
291
- context 'when no packaging files exist in the tmp_path' do
292
- it 'should return an empty array' do
293
- Dir.mktmpdir do |path|
294
- Backup::Config.update(:root_path => path)
295
- FileUtils.mkdir_p(Backup::Config.tmp_path)
296
-
297
- other_files = [
298
- '2012.01.06.12.05.30.test_trigger.target.tar',
299
- '2012.01.06.12.05.30.other_trigger.tar',
300
- 'foo.tar'
301
- ].map! {|f| File.join(Backup::Config.tmp_path, f) }
302
-
303
- FileUtils.touch(other_files)
304
- Dir[File.join(Backup::Config.tmp_path, '*')].count.should be(3)
305
-
306
- cleaner.send(:tmp_path_package_files).should == []
307
- end
308
- end
309
- end
310
- end
311
-
312
- end