backup_checksum 3.0.23
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/.gitignore +7 -0
- data/.travis.yml +10 -0
- data/Gemfile +28 -0
- data/Gemfile.lock +130 -0
- data/Guardfile +21 -0
- data/LICENSE.md +24 -0
- data/README.md +476 -0
- data/backup_checksum.gemspec +32 -0
- data/bin/backup +11 -0
- data/lib/backup.rb +217 -0
- data/lib/backup/archive.rb +117 -0
- data/lib/backup/binder.rb +22 -0
- data/lib/backup/checksum/base.rb +44 -0
- data/lib/backup/checksum/shasum.rb +16 -0
- data/lib/backup/cleaner.rb +121 -0
- data/lib/backup/cli/helpers.rb +88 -0
- data/lib/backup/cli/utility.rb +247 -0
- data/lib/backup/compressor/base.rb +29 -0
- data/lib/backup/compressor/bzip2.rb +50 -0
- data/lib/backup/compressor/gzip.rb +47 -0
- data/lib/backup/compressor/lzma.rb +50 -0
- data/lib/backup/compressor/pbzip2.rb +56 -0
- data/lib/backup/config.rb +173 -0
- data/lib/backup/configuration/base.rb +15 -0
- data/lib/backup/configuration/checksum/base.rb +9 -0
- data/lib/backup/configuration/checksum/shasum.rb +9 -0
- data/lib/backup/configuration/compressor/base.rb +9 -0
- data/lib/backup/configuration/compressor/bzip2.rb +23 -0
- data/lib/backup/configuration/compressor/gzip.rb +23 -0
- data/lib/backup/configuration/compressor/lzma.rb +23 -0
- data/lib/backup/configuration/compressor/pbzip2.rb +28 -0
- data/lib/backup/configuration/database/base.rb +19 -0
- data/lib/backup/configuration/database/mongodb.rb +49 -0
- data/lib/backup/configuration/database/mysql.rb +42 -0
- data/lib/backup/configuration/database/postgresql.rb +41 -0
- data/lib/backup/configuration/database/redis.rb +39 -0
- data/lib/backup/configuration/database/riak.rb +29 -0
- data/lib/backup/configuration/encryptor/base.rb +9 -0
- data/lib/backup/configuration/encryptor/gpg.rb +17 -0
- data/lib/backup/configuration/encryptor/open_ssl.rb +32 -0
- data/lib/backup/configuration/helpers.rb +52 -0
- data/lib/backup/configuration/notifier/base.rb +28 -0
- data/lib/backup/configuration/notifier/campfire.rb +25 -0
- data/lib/backup/configuration/notifier/hipchat.rb +41 -0
- data/lib/backup/configuration/notifier/mail.rb +112 -0
- data/lib/backup/configuration/notifier/presently.rb +25 -0
- data/lib/backup/configuration/notifier/prowl.rb +23 -0
- data/lib/backup/configuration/notifier/twitter.rb +21 -0
- data/lib/backup/configuration/storage/base.rb +18 -0
- data/lib/backup/configuration/storage/cloudfiles.rb +25 -0
- data/lib/backup/configuration/storage/dropbox.rb +58 -0
- data/lib/backup/configuration/storage/ftp.rb +29 -0
- data/lib/backup/configuration/storage/local.rb +17 -0
- data/lib/backup/configuration/storage/ninefold.rb +20 -0
- data/lib/backup/configuration/storage/rsync.rb +29 -0
- data/lib/backup/configuration/storage/s3.rb +25 -0
- data/lib/backup/configuration/storage/scp.rb +25 -0
- data/lib/backup/configuration/storage/sftp.rb +25 -0
- data/lib/backup/configuration/syncer/base.rb +10 -0
- data/lib/backup/configuration/syncer/cloud.rb +23 -0
- data/lib/backup/configuration/syncer/cloud_files.rb +30 -0
- data/lib/backup/configuration/syncer/rsync/base.rb +28 -0
- data/lib/backup/configuration/syncer/rsync/local.rb +11 -0
- data/lib/backup/configuration/syncer/rsync/pull.rb +11 -0
- data/lib/backup/configuration/syncer/rsync/push.rb +31 -0
- data/lib/backup/configuration/syncer/s3.rb +23 -0
- data/lib/backup/database/base.rb +59 -0
- data/lib/backup/database/mongodb.rb +232 -0
- data/lib/backup/database/mysql.rb +163 -0
- data/lib/backup/database/postgresql.rb +146 -0
- data/lib/backup/database/redis.rb +139 -0
- data/lib/backup/database/riak.rb +69 -0
- data/lib/backup/dependency.rb +114 -0
- data/lib/backup/encryptor/base.rb +29 -0
- data/lib/backup/encryptor/gpg.rb +80 -0
- data/lib/backup/encryptor/open_ssl.rb +72 -0
- data/lib/backup/errors.rb +124 -0
- data/lib/backup/logger.rb +152 -0
- data/lib/backup/model.rb +386 -0
- data/lib/backup/notifier/base.rb +81 -0
- data/lib/backup/notifier/campfire.rb +168 -0
- data/lib/backup/notifier/hipchat.rb +99 -0
- data/lib/backup/notifier/mail.rb +206 -0
- data/lib/backup/notifier/presently.rb +88 -0
- data/lib/backup/notifier/prowl.rb +65 -0
- data/lib/backup/notifier/twitter.rb +70 -0
- data/lib/backup/package.rb +51 -0
- data/lib/backup/packager.rb +108 -0
- data/lib/backup/pipeline.rb +107 -0
- data/lib/backup/splitter.rb +75 -0
- data/lib/backup/storage/base.rb +119 -0
- data/lib/backup/storage/cloudfiles.rb +87 -0
- data/lib/backup/storage/cycler.rb +117 -0
- data/lib/backup/storage/dropbox.rb +181 -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 +42 -0
- data/lib/backup/syncer/cloud.rb +190 -0
- data/lib/backup/syncer/cloud_files.rb +56 -0
- data/lib/backup/syncer/rsync/base.rb +52 -0
- data/lib/backup/syncer/rsync/local.rb +53 -0
- data/lib/backup/syncer/rsync/pull.rb +38 -0
- data/lib/backup/syncer/rsync/push.rb +113 -0
- data/lib/backup/syncer/s3.rb +47 -0
- data/lib/backup/template.rb +46 -0
- data/lib/backup/version.rb +43 -0
- data/spec/archive_spec.rb +335 -0
- data/spec/cleaner_spec.rb +304 -0
- data/spec/cli/helpers_spec.rb +176 -0
- data/spec/cli/utility_spec.rb +363 -0
- data/spec/compressor/base_spec.rb +31 -0
- data/spec/compressor/bzip2_spec.rb +83 -0
- data/spec/compressor/gzip_spec.rb +83 -0
- data/spec/compressor/lzma_spec.rb +83 -0
- data/spec/compressor/pbzip2_spec.rb +124 -0
- data/spec/config_spec.rb +321 -0
- data/spec/configuration/base_spec.rb +35 -0
- data/spec/configuration/compressor/bzip2_spec.rb +29 -0
- data/spec/configuration/compressor/gzip_spec.rb +29 -0
- data/spec/configuration/compressor/lzma_spec.rb +29 -0
- data/spec/configuration/compressor/pbzip2_spec.rb +32 -0
- data/spec/configuration/database/base_spec.rb +17 -0
- data/spec/configuration/database/mongodb_spec.rb +56 -0
- data/spec/configuration/database/mysql_spec.rb +53 -0
- data/spec/configuration/database/postgresql_spec.rb +53 -0
- data/spec/configuration/database/redis_spec.rb +50 -0
- data/spec/configuration/database/riak_spec.rb +35 -0
- data/spec/configuration/encryptor/gpg_spec.rb +26 -0
- data/spec/configuration/encryptor/open_ssl_spec.rb +35 -0
- data/spec/configuration/notifier/base_spec.rb +32 -0
- data/spec/configuration/notifier/campfire_spec.rb +32 -0
- data/spec/configuration/notifier/hipchat_spec.rb +44 -0
- data/spec/configuration/notifier/mail_spec.rb +71 -0
- data/spec/configuration/notifier/presently_spec.rb +35 -0
- data/spec/configuration/notifier/prowl_spec.rb +29 -0
- data/spec/configuration/notifier/twitter_spec.rb +35 -0
- data/spec/configuration/storage/cloudfiles_spec.rb +41 -0
- data/spec/configuration/storage/dropbox_spec.rb +38 -0
- data/spec/configuration/storage/ftp_spec.rb +44 -0
- data/spec/configuration/storage/local_spec.rb +29 -0
- data/spec/configuration/storage/ninefold_spec.rb +32 -0
- data/spec/configuration/storage/rsync_spec.rb +41 -0
- data/spec/configuration/storage/s3_spec.rb +38 -0
- data/spec/configuration/storage/scp_spec.rb +41 -0
- data/spec/configuration/storage/sftp_spec.rb +41 -0
- data/spec/configuration/syncer/cloud_files_spec.rb +44 -0
- data/spec/configuration/syncer/rsync/base_spec.rb +33 -0
- data/spec/configuration/syncer/rsync/local_spec.rb +10 -0
- data/spec/configuration/syncer/rsync/pull_spec.rb +10 -0
- data/spec/configuration/syncer/rsync/push_spec.rb +43 -0
- data/spec/configuration/syncer/s3_spec.rb +38 -0
- data/spec/database/base_spec.rb +54 -0
- data/spec/database/mongodb_spec.rb +428 -0
- data/spec/database/mysql_spec.rb +335 -0
- data/spec/database/postgresql_spec.rb +278 -0
- data/spec/database/redis_spec.rb +260 -0
- data/spec/database/riak_spec.rb +108 -0
- data/spec/dependency_spec.rb +49 -0
- data/spec/encryptor/base_spec.rb +30 -0
- data/spec/encryptor/gpg_spec.rb +134 -0
- data/spec/encryptor/open_ssl_spec.rb +129 -0
- data/spec/errors_spec.rb +306 -0
- data/spec/logger_spec.rb +363 -0
- data/spec/model_spec.rb +649 -0
- data/spec/notifier/base_spec.rb +89 -0
- data/spec/notifier/campfire_spec.rb +199 -0
- data/spec/notifier/hipchat_spec.rb +188 -0
- data/spec/notifier/mail_spec.rb +280 -0
- data/spec/notifier/presently_spec.rb +181 -0
- data/spec/notifier/prowl_spec.rb +117 -0
- data/spec/notifier/twitter_spec.rb +132 -0
- data/spec/package_spec.rb +61 -0
- data/spec/packager_spec.rb +225 -0
- data/spec/pipeline_spec.rb +257 -0
- data/spec/spec_helper.rb +59 -0
- data/spec/splitter_spec.rb +120 -0
- data/spec/storage/base_spec.rb +160 -0
- data/spec/storage/cloudfiles_spec.rb +230 -0
- data/spec/storage/cycler_spec.rb +239 -0
- data/spec/storage/dropbox_spec.rb +370 -0
- data/spec/storage/ftp_spec.rb +247 -0
- data/spec/storage/local_spec.rb +235 -0
- data/spec/storage/ninefold_spec.rb +319 -0
- data/spec/storage/rsync_spec.rb +345 -0
- data/spec/storage/s3_spec.rb +221 -0
- data/spec/storage/scp_spec.rb +209 -0
- data/spec/storage/sftp_spec.rb +220 -0
- data/spec/syncer/base_spec.rb +22 -0
- data/spec/syncer/cloud_files_spec.rb +192 -0
- data/spec/syncer/rsync/base_spec.rb +118 -0
- data/spec/syncer/rsync/local_spec.rb +121 -0
- data/spec/syncer/rsync/pull_spec.rb +90 -0
- data/spec/syncer/rsync/push_spec.rb +327 -0
- data/spec/syncer/s3_spec.rb +192 -0
- data/spec/version_spec.rb +21 -0
- data/templates/cli/utility/archive +25 -0
- data/templates/cli/utility/compressor/bzip2 +7 -0
- data/templates/cli/utility/compressor/gzip +7 -0
- data/templates/cli/utility/compressor/lzma +7 -0
- data/templates/cli/utility/compressor/pbzip2 +7 -0
- data/templates/cli/utility/config +31 -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 +12 -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/presently +13 -0
- data/templates/cli/utility/notifier/prowl +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 +48 -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 +45 -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 +311 -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.expects(:utility).with(:tar).returns('tar')
|
|
142
|
+
FileUtils.expects(:mkdir_p).with(archive_path)
|
|
143
|
+
Backup::Pipeline.expects(:new).returns(pipeline)
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
context 'when both #paths and #excludes were added' do
|
|
147
|
+
before do
|
|
148
|
+
archive.instance_variable_set(:@paths, paths)
|
|
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
|
+
before do
|
|
180
|
+
archive.instance_variable_set(:@paths, paths)
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
it 'should render only the syntax for adds' do
|
|
184
|
+
Backup::Logger.expects(:message).in_sequence(s).with(
|
|
185
|
+
"Backup::Archive has started archiving:\n" +
|
|
186
|
+
" /path/to/add\n" +
|
|
187
|
+
" /another/path/to/add"
|
|
188
|
+
)
|
|
189
|
+
|
|
190
|
+
pipeline.expects(:<<).in_sequence(s).with(
|
|
191
|
+
"tar -cPf - '/path/to/add' '/another/path/to/add'"
|
|
192
|
+
)
|
|
193
|
+
pipeline.expects(:<<).in_sequence(s).with(
|
|
194
|
+
"cat > '#{ File.join(archive_path, 'test_archive.tar') }'"
|
|
195
|
+
)
|
|
196
|
+
pipeline.expects(:run).in_sequence(s)
|
|
197
|
+
pipeline.expects(:success?).in_sequence(s).returns(true)
|
|
198
|
+
|
|
199
|
+
Backup::Logger.expects(:message).in_sequence(s).with(
|
|
200
|
+
"Backup::Archive Complete!"
|
|
201
|
+
)
|
|
202
|
+
|
|
203
|
+
archive.perform!
|
|
204
|
+
end
|
|
205
|
+
end # context 'when no excludes were added'
|
|
206
|
+
|
|
207
|
+
context 'with #paths, #excludes and #tar_args' do
|
|
208
|
+
before do
|
|
209
|
+
archive.instance_variable_set(:@paths, paths)
|
|
210
|
+
archive.instance_variable_set(:@excludes, excludes)
|
|
211
|
+
archive.instance_variable_set(:@tar_args, '-h --xattrs')
|
|
212
|
+
end
|
|
213
|
+
|
|
214
|
+
it 'should render the syntax for all three' do
|
|
215
|
+
Backup::Logger.expects(:message).in_sequence(s).with(
|
|
216
|
+
"Backup::Archive has started archiving:\n" +
|
|
217
|
+
" /path/to/add\n" +
|
|
218
|
+
" /another/path/to/add"
|
|
219
|
+
)
|
|
220
|
+
|
|
221
|
+
pipeline.expects(:<<).in_sequence(s).with(
|
|
222
|
+
"tar -h --xattrs -cPf - " +
|
|
223
|
+
"--exclude='/path/to/exclude' --exclude='/another/path/to/exclude' " +
|
|
224
|
+
"'/path/to/add' '/another/path/to/add'"
|
|
225
|
+
)
|
|
226
|
+
pipeline.expects(:<<).in_sequence(s).with(
|
|
227
|
+
"cat > '#{ File.join(archive_path, 'test_archive.tar') }'"
|
|
228
|
+
)
|
|
229
|
+
pipeline.expects(:run).in_sequence(s)
|
|
230
|
+
pipeline.expects(:success?).in_sequence(s).returns(true)
|
|
231
|
+
|
|
232
|
+
Backup::Logger.expects(:message).in_sequence(s).with(
|
|
233
|
+
"Backup::Archive Complete!"
|
|
234
|
+
)
|
|
235
|
+
|
|
236
|
+
archive.perform!
|
|
237
|
+
end
|
|
238
|
+
end # context 'with #paths, #excludes and #tar_args'
|
|
239
|
+
|
|
240
|
+
context 'with #paths, #excludes, #tar_args and a Gzip Compressor' do
|
|
241
|
+
before do
|
|
242
|
+
archive.instance_variable_set(:@paths, paths)
|
|
243
|
+
archive.instance_variable_set(:@excludes, excludes)
|
|
244
|
+
archive.instance_variable_set(:@tar_args, '-h --xattrs')
|
|
245
|
+
compressor = mock
|
|
246
|
+
model.expects(:compressor).twice.returns(compressor)
|
|
247
|
+
compressor.expects(:compress_with).yields('gzip', '.gz')
|
|
248
|
+
end
|
|
249
|
+
|
|
250
|
+
it 'should render the syntax with compressor modifications' do
|
|
251
|
+
Backup::Logger.expects(:message).in_sequence(s).with(
|
|
252
|
+
"Backup::Archive has started archiving:\n" +
|
|
253
|
+
" /path/to/add\n" +
|
|
254
|
+
" /another/path/to/add"
|
|
255
|
+
)
|
|
256
|
+
|
|
257
|
+
pipeline.expects(:<<).in_sequence(s).with(
|
|
258
|
+
"tar -h --xattrs -cPf - " +
|
|
259
|
+
"--exclude='/path/to/exclude' --exclude='/another/path/to/exclude' " +
|
|
260
|
+
"'/path/to/add' '/another/path/to/add'"
|
|
261
|
+
)
|
|
262
|
+
pipeline.expects(:<<).in_sequence(s).with('gzip')
|
|
263
|
+
pipeline.expects(:<<).in_sequence(s).with(
|
|
264
|
+
"cat > '#{ File.join(archive_path, 'test_archive.tar.gz') }'"
|
|
265
|
+
)
|
|
266
|
+
pipeline.expects(:run).in_sequence(s)
|
|
267
|
+
pipeline.expects(:success?).in_sequence(s).returns(true)
|
|
268
|
+
|
|
269
|
+
Backup::Logger.expects(:message).in_sequence(s).with(
|
|
270
|
+
"Backup::Archive Complete!"
|
|
271
|
+
)
|
|
272
|
+
|
|
273
|
+
archive.perform!
|
|
274
|
+
end
|
|
275
|
+
end # context 'with #paths, #excludes, #tar_args and a Gzip Compressor'
|
|
276
|
+
|
|
277
|
+
context 'when pipeline command fails' do
|
|
278
|
+
before do
|
|
279
|
+
pipeline.stubs(:<<)
|
|
280
|
+
pipeline.expects(:run)
|
|
281
|
+
pipeline.expects(:success?).returns(false)
|
|
282
|
+
pipeline.expects(:error_messages).returns('pipeline_errors')
|
|
283
|
+
end
|
|
284
|
+
|
|
285
|
+
it 'should raise an error' do
|
|
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,304 @@
|
|
|
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
|
+
context 'when files exist in the packaging folder' do
|
|
225
|
+
it 'should return true' do
|
|
226
|
+
Dir.mktmpdir do |path|
|
|
227
|
+
Backup::Config.update(:root_path => path)
|
|
228
|
+
FileUtils.mkdir_p(
|
|
229
|
+
File.join(Backup::Config.tmp_path, 'test_trigger', 'archives')
|
|
230
|
+
)
|
|
231
|
+
cleaner.send(:packaging_folder_dirty?).should be_true
|
|
232
|
+
end
|
|
233
|
+
end
|
|
234
|
+
end
|
|
235
|
+
|
|
236
|
+
context 'when files do not exist in the packaging folder' do
|
|
237
|
+
it 'should return false' do
|
|
238
|
+
Dir.mktmpdir do |path|
|
|
239
|
+
Backup::Config.update(:root_path => path)
|
|
240
|
+
FileUtils.mkdir_p(
|
|
241
|
+
File.join(Backup::Config.tmp_path, 'test_trigger')
|
|
242
|
+
)
|
|
243
|
+
cleaner.send(:packaging_folder_dirty?).should be_false
|
|
244
|
+
end
|
|
245
|
+
end
|
|
246
|
+
end
|
|
247
|
+
end
|
|
248
|
+
|
|
249
|
+
describe '#tmp_path_package_files' do
|
|
250
|
+
before do
|
|
251
|
+
cleaner.instance_variable_set(:@model, model)
|
|
252
|
+
FileUtils.unstub(:mkdir_p)
|
|
253
|
+
FileUtils.unstub(:touch)
|
|
254
|
+
end
|
|
255
|
+
|
|
256
|
+
context 'when packaging files exist in the tmp_path' do
|
|
257
|
+
it 'should return the files' do
|
|
258
|
+
Dir.mktmpdir do |path|
|
|
259
|
+
Backup::Config.update(:root_path => path)
|
|
260
|
+
FileUtils.mkdir_p(Backup::Config.tmp_path)
|
|
261
|
+
|
|
262
|
+
package_files = [
|
|
263
|
+
'2012.01.06.12.05.30.test_trigger.tar',
|
|
264
|
+
'2012.02.06.12.05.30.test_trigger.tar-aa',
|
|
265
|
+
'2012.03.06.12.05.30.test_trigger.tar.enc',
|
|
266
|
+
'2012.04.06.12.05.30.test_trigger.tar.enc-aa'
|
|
267
|
+
].map! {|f| File.join(Backup::Config.tmp_path, f) }
|
|
268
|
+
|
|
269
|
+
other_files = [
|
|
270
|
+
'2012.01.06.12.05.30.test_trigger.target.tar',
|
|
271
|
+
'2012.01.06.12.05.30.other_trigger.tar',
|
|
272
|
+
'foo.tar'
|
|
273
|
+
].map! {|f| File.join(Backup::Config.tmp_path, f) }
|
|
274
|
+
|
|
275
|
+
FileUtils.touch(package_files + other_files)
|
|
276
|
+
Dir[File.join(Backup::Config.tmp_path, '*')].count.should be(7)
|
|
277
|
+
|
|
278
|
+
cleaner.send(:tmp_path_package_files).sort.should == package_files
|
|
279
|
+
end
|
|
280
|
+
end
|
|
281
|
+
end
|
|
282
|
+
|
|
283
|
+
context 'when no packaging files exist in the tmp_path' do
|
|
284
|
+
it 'should return an empty array' do
|
|
285
|
+
Dir.mktmpdir do |path|
|
|
286
|
+
Backup::Config.update(:root_path => path)
|
|
287
|
+
FileUtils.mkdir_p(Backup::Config.tmp_path)
|
|
288
|
+
|
|
289
|
+
other_files = [
|
|
290
|
+
'2012.01.06.12.05.30.test_trigger.target.tar',
|
|
291
|
+
'2012.01.06.12.05.30.other_trigger.tar',
|
|
292
|
+
'foo.tar'
|
|
293
|
+
].map! {|f| File.join(Backup::Config.tmp_path, f) }
|
|
294
|
+
|
|
295
|
+
FileUtils.touch(other_files)
|
|
296
|
+
Dir[File.join(Backup::Config.tmp_path, '*')].count.should be(3)
|
|
297
|
+
|
|
298
|
+
cleaner.send(:tmp_path_package_files).should == []
|
|
299
|
+
end
|
|
300
|
+
end
|
|
301
|
+
end
|
|
302
|
+
end
|
|
303
|
+
|
|
304
|
+
end
|