backup-agoddard 3.0.27
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of backup-agoddard might be problematic. Click here for more details.
- data/.gitignore +8 -0
- data/.travis.yml +10 -0
- data/Gemfile +28 -0
- data/Guardfile +23 -0
- data/LICENSE.md +24 -0
- data/README.md +478 -0
- data/backup.gemspec +32 -0
- data/bin/backup +11 -0
- data/lib/backup.rb +133 -0
- data/lib/backup/archive.rb +117 -0
- data/lib/backup/binder.rb +22 -0
- data/lib/backup/cleaner.rb +121 -0
- data/lib/backup/cli/helpers.rb +93 -0
- data/lib/backup/cli/utility.rb +255 -0
- data/lib/backup/compressor/base.rb +35 -0
- data/lib/backup/compressor/bzip2.rb +50 -0
- data/lib/backup/compressor/custom.rb +53 -0
- data/lib/backup/compressor/gzip.rb +50 -0
- data/lib/backup/compressor/lzma.rb +52 -0
- data/lib/backup/compressor/pbzip2.rb +59 -0
- data/lib/backup/config.rb +174 -0
- data/lib/backup/configuration.rb +33 -0
- data/lib/backup/configuration/helpers.rb +130 -0
- data/lib/backup/configuration/store.rb +24 -0
- data/lib/backup/database/base.rb +53 -0
- data/lib/backup/database/mongodb.rb +230 -0
- data/lib/backup/database/mysql.rb +160 -0
- data/lib/backup/database/postgresql.rb +144 -0
- data/lib/backup/database/redis.rb +136 -0
- data/lib/backup/database/riak.rb +67 -0
- data/lib/backup/dependency.rb +108 -0
- data/lib/backup/encryptor/base.rb +29 -0
- data/lib/backup/encryptor/gpg.rb +760 -0
- data/lib/backup/encryptor/open_ssl.rb +72 -0
- data/lib/backup/errors.rb +124 -0
- data/lib/backup/hooks.rb +68 -0
- data/lib/backup/logger.rb +152 -0
- data/lib/backup/model.rb +409 -0
- data/lib/backup/notifier/base.rb +81 -0
- data/lib/backup/notifier/campfire.rb +155 -0
- data/lib/backup/notifier/hipchat.rb +93 -0
- data/lib/backup/notifier/mail.rb +206 -0
- data/lib/backup/notifier/prowl.rb +65 -0
- data/lib/backup/notifier/pushover.rb +88 -0
- data/lib/backup/notifier/twitter.rb +70 -0
- data/lib/backup/package.rb +47 -0
- data/lib/backup/packager.rb +100 -0
- data/lib/backup/pipeline.rb +110 -0
- data/lib/backup/splitter.rb +75 -0
- data/lib/backup/storage/base.rb +99 -0
- data/lib/backup/storage/cloudfiles.rb +87 -0
- data/lib/backup/storage/cycler.rb +117 -0
- data/lib/backup/storage/dropbox.rb +178 -0
- data/lib/backup/storage/ftp.rb +119 -0
- data/lib/backup/storage/local.rb +82 -0
- data/lib/backup/storage/ninefold.rb +116 -0
- data/lib/backup/storage/rsync.rb +149 -0
- data/lib/backup/storage/s3.rb +94 -0
- data/lib/backup/storage/scp.rb +99 -0
- data/lib/backup/storage/sftp.rb +108 -0
- data/lib/backup/syncer/base.rb +46 -0
- data/lib/backup/syncer/cloud/base.rb +247 -0
- data/lib/backup/syncer/cloud/cloud_files.rb +78 -0
- data/lib/backup/syncer/cloud/s3.rb +68 -0
- data/lib/backup/syncer/rsync/base.rb +49 -0
- data/lib/backup/syncer/rsync/local.rb +55 -0
- data/lib/backup/syncer/rsync/pull.rb +36 -0
- data/lib/backup/syncer/rsync/push.rb +116 -0
- data/lib/backup/template.rb +46 -0
- data/lib/backup/version.rb +43 -0
- data/spec-live/.gitignore +6 -0
- data/spec-live/README +7 -0
- data/spec-live/backups/config.rb +83 -0
- data/spec-live/backups/config.yml.template +46 -0
- data/spec-live/backups/models.rb +184 -0
- data/spec-live/compressor/custom_spec.rb +30 -0
- data/spec-live/compressor/gzip_spec.rb +30 -0
- data/spec-live/encryptor/gpg_keys.rb +239 -0
- data/spec-live/encryptor/gpg_spec.rb +287 -0
- data/spec-live/notifier/mail_spec.rb +121 -0
- data/spec-live/spec_helper.rb +151 -0
- data/spec-live/storage/dropbox_spec.rb +151 -0
- data/spec-live/storage/local_spec.rb +83 -0
- data/spec-live/storage/scp_spec.rb +193 -0
- data/spec-live/syncer/cloud/s3_spec.rb +124 -0
- data/spec/archive_spec.rb +335 -0
- data/spec/cleaner_spec.rb +312 -0
- data/spec/cli/helpers_spec.rb +301 -0
- data/spec/cli/utility_spec.rb +411 -0
- data/spec/compressor/base_spec.rb +52 -0
- data/spec/compressor/bzip2_spec.rb +217 -0
- data/spec/compressor/custom_spec.rb +106 -0
- data/spec/compressor/gzip_spec.rb +217 -0
- data/spec/compressor/lzma_spec.rb +123 -0
- data/spec/compressor/pbzip2_spec.rb +165 -0
- data/spec/config_spec.rb +321 -0
- data/spec/configuration/helpers_spec.rb +247 -0
- data/spec/configuration/store_spec.rb +39 -0
- data/spec/configuration_spec.rb +62 -0
- data/spec/database/base_spec.rb +63 -0
- data/spec/database/mongodb_spec.rb +510 -0
- data/spec/database/mysql_spec.rb +411 -0
- data/spec/database/postgresql_spec.rb +353 -0
- data/spec/database/redis_spec.rb +334 -0
- data/spec/database/riak_spec.rb +176 -0
- data/spec/dependency_spec.rb +51 -0
- data/spec/encryptor/base_spec.rb +40 -0
- data/spec/encryptor/gpg_spec.rb +909 -0
- data/spec/encryptor/open_ssl_spec.rb +148 -0
- data/spec/errors_spec.rb +306 -0
- data/spec/hooks_spec.rb +35 -0
- data/spec/logger_spec.rb +367 -0
- data/spec/model_spec.rb +694 -0
- data/spec/notifier/base_spec.rb +104 -0
- data/spec/notifier/campfire_spec.rb +217 -0
- data/spec/notifier/hipchat_spec.rb +211 -0
- data/spec/notifier/mail_spec.rb +316 -0
- data/spec/notifier/prowl_spec.rb +138 -0
- data/spec/notifier/pushover_spec.rb +123 -0
- data/spec/notifier/twitter_spec.rb +153 -0
- data/spec/package_spec.rb +61 -0
- data/spec/packager_spec.rb +213 -0
- data/spec/pipeline_spec.rb +259 -0
- data/spec/spec_helper.rb +60 -0
- data/spec/splitter_spec.rb +120 -0
- data/spec/storage/base_spec.rb +166 -0
- data/spec/storage/cloudfiles_spec.rb +254 -0
- data/spec/storage/cycler_spec.rb +247 -0
- data/spec/storage/dropbox_spec.rb +480 -0
- data/spec/storage/ftp_spec.rb +271 -0
- data/spec/storage/local_spec.rb +259 -0
- data/spec/storage/ninefold_spec.rb +343 -0
- data/spec/storage/rsync_spec.rb +362 -0
- data/spec/storage/s3_spec.rb +245 -0
- data/spec/storage/scp_spec.rb +233 -0
- data/spec/storage/sftp_spec.rb +244 -0
- data/spec/syncer/base_spec.rb +109 -0
- data/spec/syncer/cloud/base_spec.rb +515 -0
- data/spec/syncer/cloud/cloud_files_spec.rb +181 -0
- data/spec/syncer/cloud/s3_spec.rb +174 -0
- data/spec/syncer/rsync/base_spec.rb +98 -0
- data/spec/syncer/rsync/local_spec.rb +149 -0
- data/spec/syncer/rsync/pull_spec.rb +98 -0
- data/spec/syncer/rsync/push_spec.rb +333 -0
- data/spec/version_spec.rb +21 -0
- data/templates/cli/utility/archive +25 -0
- data/templates/cli/utility/compressor/bzip2 +4 -0
- data/templates/cli/utility/compressor/custom +11 -0
- data/templates/cli/utility/compressor/gzip +4 -0
- data/templates/cli/utility/compressor/lzma +10 -0
- data/templates/cli/utility/compressor/pbzip2 +10 -0
- data/templates/cli/utility/config +32 -0
- data/templates/cli/utility/database/mongodb +18 -0
- data/templates/cli/utility/database/mysql +21 -0
- data/templates/cli/utility/database/postgresql +17 -0
- data/templates/cli/utility/database/redis +16 -0
- data/templates/cli/utility/database/riak +11 -0
- data/templates/cli/utility/encryptor/gpg +27 -0
- data/templates/cli/utility/encryptor/openssl +9 -0
- data/templates/cli/utility/model.erb +23 -0
- data/templates/cli/utility/notifier/campfire +12 -0
- data/templates/cli/utility/notifier/hipchat +15 -0
- data/templates/cli/utility/notifier/mail +22 -0
- data/templates/cli/utility/notifier/prowl +11 -0
- data/templates/cli/utility/notifier/pushover +11 -0
- data/templates/cli/utility/notifier/twitter +13 -0
- data/templates/cli/utility/splitter +7 -0
- data/templates/cli/utility/storage/cloud_files +22 -0
- data/templates/cli/utility/storage/dropbox +20 -0
- data/templates/cli/utility/storage/ftp +12 -0
- data/templates/cli/utility/storage/local +7 -0
- data/templates/cli/utility/storage/ninefold +9 -0
- data/templates/cli/utility/storage/rsync +11 -0
- data/templates/cli/utility/storage/s3 +19 -0
- data/templates/cli/utility/storage/scp +11 -0
- data/templates/cli/utility/storage/sftp +11 -0
- data/templates/cli/utility/syncer/cloud_files +46 -0
- data/templates/cli/utility/syncer/rsync_local +12 -0
- data/templates/cli/utility/syncer/rsync_pull +17 -0
- data/templates/cli/utility/syncer/rsync_push +17 -0
- data/templates/cli/utility/syncer/s3 +43 -0
- data/templates/general/links +11 -0
- data/templates/general/version.erb +2 -0
- data/templates/notifier/mail/failure.erb +9 -0
- data/templates/notifier/mail/success.erb +7 -0
- data/templates/notifier/mail/warning.erb +9 -0
- data/templates/storage/dropbox/authorization_url.erb +6 -0
- data/templates/storage/dropbox/authorized.erb +4 -0
- data/templates/storage/dropbox/cache_file_written.erb +10 -0
- metadata +277 -0
@@ -0,0 +1,335 @@
|
|
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
|
@@ -0,0 +1,312 @@
|
|
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
|