backup 3.0.27 → 3.1.0
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/LICENSE.md +1 -1
- data/README.md +139 -386
- data/bin/backup +1 -7
- data/lib/backup.rb +3 -9
- data/lib/backup/archive.rb +26 -20
- data/lib/backup/cleaner.rb +2 -2
- data/lib/backup/cli.rb +366 -0
- data/lib/backup/compressor/base.rb +2 -2
- data/lib/backup/compressor/gzip.rb +35 -1
- data/lib/backup/config.rb +1 -2
- data/lib/backup/database/base.rb +2 -2
- data/lib/backup/database/mongodb.rb +3 -3
- data/lib/backup/database/mysql.rb +3 -2
- data/lib/backup/database/postgresql.rb +3 -2
- data/lib/backup/database/riak.rb +18 -5
- data/lib/backup/dependency.rb +144 -93
- data/lib/backup/encryptor/base.rb +2 -2
- data/lib/backup/logger.rb +108 -110
- data/lib/backup/logger/console.rb +51 -0
- data/lib/backup/logger/logfile.rb +113 -0
- data/lib/backup/logger/syslog.rb +116 -0
- data/lib/backup/model.rb +67 -65
- data/lib/backup/notifier/base.rb +1 -1
- data/lib/backup/notifier/hipchat.rb +1 -1
- data/lib/backup/notifier/mail.rb +1 -1
- data/lib/backup/notifier/pushover.rb +6 -3
- data/lib/backup/packager.rb +4 -4
- data/lib/backup/pipeline.rb +17 -3
- data/lib/backup/splitter.rb +2 -2
- data/lib/backup/storage/base.rb +2 -2
- data/lib/backup/storage/cloudfiles.rb +2 -2
- data/lib/backup/storage/dropbox.rb +4 -4
- data/lib/backup/storage/ftp.rb +2 -2
- data/lib/backup/storage/local.rb +2 -2
- data/lib/backup/storage/ninefold.rb +2 -2
- data/lib/backup/storage/rsync.rb +3 -3
- data/lib/backup/storage/s3.rb +2 -2
- data/lib/backup/storage/scp.rb +2 -6
- data/lib/backup/storage/sftp.rb +2 -5
- data/lib/backup/syncer/base.rb +1 -1
- data/lib/backup/syncer/cloud/base.rb +15 -8
- data/lib/backup/syncer/rsync/local.rb +1 -1
- data/lib/backup/syncer/rsync/pull.rb +1 -1
- data/lib/backup/syncer/rsync/push.rb +1 -1
- data/lib/backup/utilities.rb +211 -0
- data/lib/backup/version.rb +1 -1
- data/templates/cli/{utility/archive → archive} +4 -8
- data/templates/cli/{utility/compressor → compressor}/bzip2 +0 -0
- data/templates/cli/{utility/compressor → compressor}/custom +0 -0
- data/templates/cli/{utility/compressor → compressor}/gzip +0 -0
- data/templates/cli/{utility/compressor → compressor}/lzma +0 -0
- data/templates/cli/{utility/compressor → compressor}/pbzip2 +0 -0
- data/templates/cli/config +68 -0
- data/templates/cli/{utility/database → database}/mongodb +1 -1
- data/templates/cli/{utility/database → database}/mysql +1 -1
- data/templates/cli/{utility/database → database}/postgresql +1 -1
- data/templates/cli/{utility/database → database}/redis +0 -0
- data/templates/cli/database/riak +20 -0
- data/templates/cli/{utility/encryptor → encryptor}/gpg +0 -0
- data/templates/cli/{utility/encryptor → encryptor}/openssl +0 -0
- data/templates/cli/{utility/model.erb → model.erb} +4 -4
- data/templates/cli/{utility/notifier → notifier}/campfire +0 -0
- data/templates/cli/{utility/notifier → notifier}/hipchat +0 -0
- data/templates/cli/{utility/notifier → notifier}/mail +0 -0
- data/templates/cli/{utility/notifier → notifier}/prowl +0 -0
- data/templates/cli/{utility/notifier → notifier}/pushover +0 -0
- data/templates/cli/{utility/notifier → notifier}/twitter +0 -0
- data/templates/cli/{utility/splitter → splitter} +0 -0
- data/templates/cli/{utility/storage → storage}/cloud_files +0 -0
- data/templates/cli/{utility/storage → storage}/dropbox +0 -0
- data/templates/cli/{utility/storage → storage}/ftp +0 -0
- data/templates/cli/{utility/storage → storage}/local +0 -0
- data/templates/cli/{utility/storage → storage}/ninefold +0 -0
- data/templates/cli/{utility/storage → storage}/rsync +0 -0
- data/templates/cli/{utility/storage → storage}/s3 +0 -0
- data/templates/cli/{utility/storage → storage}/scp +0 -0
- data/templates/cli/{utility/storage → storage}/sftp +0 -0
- data/templates/cli/{utility/syncer → syncer}/cloud_files +0 -0
- data/templates/cli/{utility/syncer → syncer}/rsync_local +0 -0
- data/templates/cli/{utility/syncer → syncer}/rsync_pull +0 -0
- data/templates/cli/{utility/syncer → syncer}/rsync_push +0 -0
- data/templates/cli/{utility/syncer → syncer}/s3 +0 -0
- metadata +55 -131
- data/.gitignore +0 -8
- data/.travis.yml +0 -10
- data/Gemfile +0 -28
- data/Guardfile +0 -23
- data/backup.gemspec +0 -32
- data/lib/backup/cli/helpers.rb +0 -93
- data/lib/backup/cli/utility.rb +0 -255
- data/spec-live/.gitignore +0 -6
- data/spec-live/README +0 -7
- data/spec-live/backups/config.rb +0 -83
- data/spec-live/backups/config.yml.template +0 -46
- data/spec-live/backups/models.rb +0 -184
- data/spec-live/compressor/custom_spec.rb +0 -30
- data/spec-live/compressor/gzip_spec.rb +0 -30
- data/spec-live/encryptor/gpg_keys.rb +0 -239
- data/spec-live/encryptor/gpg_spec.rb +0 -287
- data/spec-live/notifier/mail_spec.rb +0 -121
- data/spec-live/spec_helper.rb +0 -151
- data/spec-live/storage/dropbox_spec.rb +0 -151
- data/spec-live/storage/local_spec.rb +0 -83
- data/spec-live/storage/scp_spec.rb +0 -193
- data/spec-live/syncer/cloud/s3_spec.rb +0 -124
- data/spec/archive_spec.rb +0 -335
- data/spec/cleaner_spec.rb +0 -312
- data/spec/cli/helpers_spec.rb +0 -301
- data/spec/cli/utility_spec.rb +0 -411
- data/spec/compressor/base_spec.rb +0 -52
- data/spec/compressor/bzip2_spec.rb +0 -217
- data/spec/compressor/custom_spec.rb +0 -106
- data/spec/compressor/gzip_spec.rb +0 -217
- data/spec/compressor/lzma_spec.rb +0 -123
- data/spec/compressor/pbzip2_spec.rb +0 -165
- data/spec/config_spec.rb +0 -321
- data/spec/configuration/helpers_spec.rb +0 -247
- data/spec/configuration/store_spec.rb +0 -39
- data/spec/configuration_spec.rb +0 -62
- data/spec/database/base_spec.rb +0 -63
- data/spec/database/mongodb_spec.rb +0 -510
- data/spec/database/mysql_spec.rb +0 -411
- data/spec/database/postgresql_spec.rb +0 -353
- data/spec/database/redis_spec.rb +0 -334
- data/spec/database/riak_spec.rb +0 -176
- data/spec/dependency_spec.rb +0 -51
- data/spec/encryptor/base_spec.rb +0 -40
- data/spec/encryptor/gpg_spec.rb +0 -909
- data/spec/encryptor/open_ssl_spec.rb +0 -148
- data/spec/errors_spec.rb +0 -306
- data/spec/logger_spec.rb +0 -367
- data/spec/model_spec.rb +0 -666
- data/spec/notifier/base_spec.rb +0 -104
- data/spec/notifier/campfire_spec.rb +0 -217
- data/spec/notifier/hipchat_spec.rb +0 -211
- data/spec/notifier/mail_spec.rb +0 -316
- data/spec/notifier/prowl_spec.rb +0 -138
- data/spec/notifier/pushover_spec.rb +0 -123
- data/spec/notifier/twitter_spec.rb +0 -153
- data/spec/package_spec.rb +0 -61
- data/spec/packager_spec.rb +0 -213
- data/spec/pipeline_spec.rb +0 -259
- data/spec/spec_helper.rb +0 -60
- data/spec/splitter_spec.rb +0 -120
- data/spec/storage/base_spec.rb +0 -166
- data/spec/storage/cloudfiles_spec.rb +0 -254
- data/spec/storage/cycler_spec.rb +0 -247
- data/spec/storage/dropbox_spec.rb +0 -480
- data/spec/storage/ftp_spec.rb +0 -271
- data/spec/storage/local_spec.rb +0 -259
- data/spec/storage/ninefold_spec.rb +0 -343
- data/spec/storage/rsync_spec.rb +0 -362
- data/spec/storage/s3_spec.rb +0 -245
- data/spec/storage/scp_spec.rb +0 -233
- data/spec/storage/sftp_spec.rb +0 -244
- data/spec/syncer/base_spec.rb +0 -109
- data/spec/syncer/cloud/base_spec.rb +0 -515
- data/spec/syncer/cloud/cloud_files_spec.rb +0 -181
- data/spec/syncer/cloud/s3_spec.rb +0 -174
- data/spec/syncer/rsync/base_spec.rb +0 -98
- data/spec/syncer/rsync/local_spec.rb +0 -149
- data/spec/syncer/rsync/pull_spec.rb +0 -98
- data/spec/syncer/rsync/push_spec.rb +0 -333
- data/spec/version_spec.rb +0 -21
- data/templates/cli/utility/config +0 -32
- data/templates/cli/utility/database/riak +0 -11
data/spec/database/redis_spec.rb
DELETED
|
@@ -1,334 +0,0 @@
|
|
|
1
|
-
# encoding: utf-8
|
|
2
|
-
|
|
3
|
-
require File.expand_path('../../spec_helper.rb', __FILE__)
|
|
4
|
-
|
|
5
|
-
describe Backup::Database::Redis do
|
|
6
|
-
let(:model) { Backup::Model.new('foo', 'foo') }
|
|
7
|
-
let(:db) do
|
|
8
|
-
Backup::Database::Redis.new(model) do |db|
|
|
9
|
-
db.name = 'mydatabase'
|
|
10
|
-
db.path = '/var/lib/redis/db/'
|
|
11
|
-
db.password = 'secret'
|
|
12
|
-
db.host = 'localhost'
|
|
13
|
-
db.port = '123'
|
|
14
|
-
db.socket = '/redis.sock'
|
|
15
|
-
db.invoke_save = true
|
|
16
|
-
|
|
17
|
-
db.additional_options = ['--query', '--foo']
|
|
18
|
-
db.redis_cli_utility = '/path/to/redis-cli'
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
it 'should be a subclass of Database::Base' do
|
|
23
|
-
Backup::Database::Redis.superclass.
|
|
24
|
-
should == Backup::Database::Base
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
describe '#initialize' do
|
|
28
|
-
|
|
29
|
-
it 'should load pre-configured defaults through Base' do
|
|
30
|
-
Backup::Database::Redis.any_instance.expects(:load_defaults!)
|
|
31
|
-
db
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
it 'should pass the model reference to Base' do
|
|
35
|
-
db.instance_variable_get(:@model).should == model
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
context 'when no pre-configured defaults have been set' do
|
|
39
|
-
context 'when options are specified' do
|
|
40
|
-
it 'should use the given values' do
|
|
41
|
-
db.name.should == 'mydatabase'
|
|
42
|
-
db.path.should == '/var/lib/redis/db/'
|
|
43
|
-
db.password.should == 'secret'
|
|
44
|
-
db.host.should == 'localhost'
|
|
45
|
-
db.port.should == '123'
|
|
46
|
-
db.socket.should == '/redis.sock'
|
|
47
|
-
db.invoke_save.should == true
|
|
48
|
-
|
|
49
|
-
db.additional_options.should == ['--query', '--foo']
|
|
50
|
-
db.redis_cli_utility.should == '/path/to/redis-cli'
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
context 'when options are not specified' do
|
|
55
|
-
before do
|
|
56
|
-
Backup::Database::Redis.any_instance.expects(:utility).
|
|
57
|
-
with('redis-cli').returns('/real/redis-cli')
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
it 'should provide default values' do
|
|
61
|
-
db = Backup::Database::Redis.new(model)
|
|
62
|
-
|
|
63
|
-
db.name.should == 'dump'
|
|
64
|
-
db.path.should be_nil
|
|
65
|
-
db.password.should be_nil
|
|
66
|
-
db.host.should be_nil
|
|
67
|
-
db.port.should be_nil
|
|
68
|
-
db.socket.should be_nil
|
|
69
|
-
db.invoke_save.should be_nil
|
|
70
|
-
|
|
71
|
-
db.additional_options.should == []
|
|
72
|
-
db.redis_cli_utility.should == '/real/redis-cli'
|
|
73
|
-
end
|
|
74
|
-
end
|
|
75
|
-
end # context 'when no pre-configured defaults have been set'
|
|
76
|
-
|
|
77
|
-
context 'when pre-configured defaults have been set' do
|
|
78
|
-
before do
|
|
79
|
-
Backup::Database::Redis.defaults do |db|
|
|
80
|
-
db.name = 'db_name'
|
|
81
|
-
db.path = 'db_path'
|
|
82
|
-
db.password = 'db_password'
|
|
83
|
-
db.host = 'db_host'
|
|
84
|
-
db.port = 789
|
|
85
|
-
db.socket = '/foo.sock'
|
|
86
|
-
db.invoke_save = true
|
|
87
|
-
|
|
88
|
-
db.additional_options = ['--add', '--opts']
|
|
89
|
-
db.redis_cli_utility = '/default/path/to/redis-cli'
|
|
90
|
-
end
|
|
91
|
-
end
|
|
92
|
-
|
|
93
|
-
after { Backup::Database::Redis.clear_defaults! }
|
|
94
|
-
|
|
95
|
-
context 'when options are specified' do
|
|
96
|
-
it 'should override the pre-configured defaults' do
|
|
97
|
-
db.name.should == 'mydatabase'
|
|
98
|
-
db.path.should == '/var/lib/redis/db/'
|
|
99
|
-
db.password.should == 'secret'
|
|
100
|
-
db.host.should == 'localhost'
|
|
101
|
-
db.port.should == '123'
|
|
102
|
-
db.socket.should == '/redis.sock'
|
|
103
|
-
db.invoke_save.should == true
|
|
104
|
-
|
|
105
|
-
db.additional_options.should == ['--query', '--foo']
|
|
106
|
-
db.redis_cli_utility.should == '/path/to/redis-cli'
|
|
107
|
-
end
|
|
108
|
-
end
|
|
109
|
-
|
|
110
|
-
context 'when options are not specified' do
|
|
111
|
-
it 'should use the pre-configured defaults' do
|
|
112
|
-
db = Backup::Database::Redis.new(model)
|
|
113
|
-
|
|
114
|
-
db.name.should == 'db_name'
|
|
115
|
-
db.path.should == 'db_path'
|
|
116
|
-
db.password.should == 'db_password'
|
|
117
|
-
db.host.should == 'db_host'
|
|
118
|
-
db.port.should == 789
|
|
119
|
-
db.socket.should == '/foo.sock'
|
|
120
|
-
db.invoke_save.should == true
|
|
121
|
-
|
|
122
|
-
db.additional_options.should == ['--add', '--opts']
|
|
123
|
-
db.redis_cli_utility.should == '/default/path/to/redis-cli'
|
|
124
|
-
end
|
|
125
|
-
end
|
|
126
|
-
end # context 'when no pre-configured defaults have been set'
|
|
127
|
-
end # describe '#initialize'
|
|
128
|
-
|
|
129
|
-
describe '#perform!' do
|
|
130
|
-
let(:s) { sequence '' }
|
|
131
|
-
before do
|
|
132
|
-
# superclass actions
|
|
133
|
-
db.expects(:prepare!).in_sequence(s)
|
|
134
|
-
db.expects(:log!).in_sequence(s)
|
|
135
|
-
end
|
|
136
|
-
|
|
137
|
-
context 'when #invoke_save is true' do
|
|
138
|
-
before { db.invoke_save = true }
|
|
139
|
-
it 'should copy over after persisting (saving) the most recent updates' do
|
|
140
|
-
db.expects(:invoke_save!).in_sequence(s)
|
|
141
|
-
db.expects(:copy!).in_sequence(s)
|
|
142
|
-
|
|
143
|
-
db.perform!
|
|
144
|
-
end
|
|
145
|
-
end
|
|
146
|
-
|
|
147
|
-
context 'when #invoke_save is not true' do
|
|
148
|
-
before { db.invoke_save = nil }
|
|
149
|
-
it 'should copy over without persisting (saving) first' do
|
|
150
|
-
db.expects(:invoke_save!).never
|
|
151
|
-
db.expects(:copy!).in_sequence(s)
|
|
152
|
-
|
|
153
|
-
db.perform!
|
|
154
|
-
end
|
|
155
|
-
end
|
|
156
|
-
|
|
157
|
-
end # describe '#perform!'
|
|
158
|
-
|
|
159
|
-
describe '#invoke_save!' do
|
|
160
|
-
before do
|
|
161
|
-
db.stubs(:credential_options).returns(:credential_options_output)
|
|
162
|
-
db.stubs(:connectivity_options).returns(:connectivity_options_output)
|
|
163
|
-
db.stubs(:user_options).returns(:user_options_output)
|
|
164
|
-
end
|
|
165
|
-
|
|
166
|
-
context 'when response is OK' do
|
|
167
|
-
it 'should run the redis-cli command string' do
|
|
168
|
-
db.expects(:run).with(
|
|
169
|
-
'/path/to/redis-cli credential_options_output ' +
|
|
170
|
-
'connectivity_options_output user_options_output SAVE'
|
|
171
|
-
).returns('result OK for command')
|
|
172
|
-
|
|
173
|
-
expect do
|
|
174
|
-
db.send(:invoke_save!)
|
|
175
|
-
end.not_to raise_error
|
|
176
|
-
end
|
|
177
|
-
end
|
|
178
|
-
|
|
179
|
-
context 'when response is not OK' do
|
|
180
|
-
it 'should raise an error' do
|
|
181
|
-
db.stubs(:run).returns('result not ok for command')
|
|
182
|
-
db.stubs(:database).returns('database_filename')
|
|
183
|
-
|
|
184
|
-
expect do
|
|
185
|
-
db.send(:invoke_save!)
|
|
186
|
-
end.to raise_error {|err|
|
|
187
|
-
err.should be_an_instance_of Backup::Errors::Database::Redis::CommandError
|
|
188
|
-
err.message.should match(/Could not invoke the Redis SAVE command/)
|
|
189
|
-
err.message.should match(/The database_filename file/)
|
|
190
|
-
err.message.should match(/Redis CLI response: result not ok/)
|
|
191
|
-
}
|
|
192
|
-
end
|
|
193
|
-
end
|
|
194
|
-
|
|
195
|
-
end # describe '#invoke_save!'
|
|
196
|
-
|
|
197
|
-
describe '#copy!' do
|
|
198
|
-
let(:src_path) { '/var/lib/redis/db/mydatabase.rdb' }
|
|
199
|
-
let(:dst_path) { '/dump/path/mydatabase.rdb' }
|
|
200
|
-
let(:compressor) { mock }
|
|
201
|
-
|
|
202
|
-
context 'when the database exists' do
|
|
203
|
-
before do
|
|
204
|
-
db.instance_variable_set(:@dump_path, '/dump/path')
|
|
205
|
-
File.expects(:exist?).with(src_path).returns(true)
|
|
206
|
-
end
|
|
207
|
-
|
|
208
|
-
context 'when no compressor is configured' do
|
|
209
|
-
it 'should copy the database' do
|
|
210
|
-
db.expects(:run).never
|
|
211
|
-
|
|
212
|
-
FileUtils.expects(:cp).with(src_path, dst_path)
|
|
213
|
-
db.send(:copy!)
|
|
214
|
-
end
|
|
215
|
-
end
|
|
216
|
-
|
|
217
|
-
context 'when a compressor is configured' do
|
|
218
|
-
before do
|
|
219
|
-
model.stubs(:compressor).returns(compressor)
|
|
220
|
-
compressor.expects(:compress_with).yields('compressor_command', '.gz')
|
|
221
|
-
end
|
|
222
|
-
|
|
223
|
-
it 'should copy the database using the compressor' do
|
|
224
|
-
FileUtils.expects(:cp).never
|
|
225
|
-
|
|
226
|
-
db.expects(:run).with(
|
|
227
|
-
"compressor_command -c #{ src_path } > #{ dst_path }.gz"
|
|
228
|
-
)
|
|
229
|
-
db.send(:copy!)
|
|
230
|
-
end
|
|
231
|
-
end
|
|
232
|
-
end
|
|
233
|
-
|
|
234
|
-
context 'when the database does not exist' do
|
|
235
|
-
it 'should raise an error if the database dump file is not found' do
|
|
236
|
-
File.expects(:exist?).returns(false)
|
|
237
|
-
expect do
|
|
238
|
-
db.send(:copy!)
|
|
239
|
-
end.to raise_error {|err|
|
|
240
|
-
err.should be_an_instance_of Backup::Errors::Database::Redis::NotFoundError
|
|
241
|
-
err.message.should match(/Redis database dump not found/)
|
|
242
|
-
err.message.should match(/File path was #{src_path}/)
|
|
243
|
-
}
|
|
244
|
-
end
|
|
245
|
-
end
|
|
246
|
-
end # describe '#copy!'
|
|
247
|
-
|
|
248
|
-
describe '#database' do
|
|
249
|
-
it 'should return the database name with the extension added' do
|
|
250
|
-
db.send(:database).should == 'mydatabase.rdb'
|
|
251
|
-
end
|
|
252
|
-
end
|
|
253
|
-
|
|
254
|
-
describe '#credential_options' do
|
|
255
|
-
context 'when #password is set' do
|
|
256
|
-
it 'should return the redis-cli syntax for the credential options' do
|
|
257
|
-
db.send(:credential_options).should == "-a 'secret'"
|
|
258
|
-
end
|
|
259
|
-
end
|
|
260
|
-
|
|
261
|
-
context 'when password is not set' do
|
|
262
|
-
it 'should return an empty string' do
|
|
263
|
-
db.password = nil
|
|
264
|
-
db.send(:credential_options).should == ''
|
|
265
|
-
end
|
|
266
|
-
end
|
|
267
|
-
end
|
|
268
|
-
|
|
269
|
-
describe '#connectivity_options' do
|
|
270
|
-
it 'should return the redis syntax for the connectivity options' do
|
|
271
|
-
db.send(:connectivity_options).should ==
|
|
272
|
-
"-h 'localhost' -p '123' -s '/redis.sock'"
|
|
273
|
-
end
|
|
274
|
-
|
|
275
|
-
context 'when only the #port is set' do
|
|
276
|
-
it 'should return only the port' do
|
|
277
|
-
db.host = nil
|
|
278
|
-
db.socket = nil
|
|
279
|
-
db.send(:connectivity_options).should == "-p '123'"
|
|
280
|
-
end
|
|
281
|
-
end
|
|
282
|
-
end
|
|
283
|
-
|
|
284
|
-
describe '#user_options' do
|
|
285
|
-
context 'when #additional_options are set' do
|
|
286
|
-
it 'should return the options' do
|
|
287
|
-
db.send(:user_options).should == '--query --foo'
|
|
288
|
-
end
|
|
289
|
-
end
|
|
290
|
-
|
|
291
|
-
context 'when #additional_options is not set' do
|
|
292
|
-
it 'should return an empty string' do
|
|
293
|
-
db.additional_options = []
|
|
294
|
-
db.send(:user_options).should == ''
|
|
295
|
-
end
|
|
296
|
-
end
|
|
297
|
-
end
|
|
298
|
-
|
|
299
|
-
describe 'deprecations' do
|
|
300
|
-
describe '#utility_path' do
|
|
301
|
-
before do
|
|
302
|
-
Backup::Database::Redis.any_instance.stubs(:utility)
|
|
303
|
-
Backup::Logger.expects(:warn).with {|err|
|
|
304
|
-
err.should be_an_instance_of Backup::Errors::ConfigurationError
|
|
305
|
-
err.message.should match(
|
|
306
|
-
/Use Redis#redis_cli_utility instead/
|
|
307
|
-
)
|
|
308
|
-
}
|
|
309
|
-
end
|
|
310
|
-
after do
|
|
311
|
-
Backup::Database::Redis.clear_defaults!
|
|
312
|
-
end
|
|
313
|
-
|
|
314
|
-
context 'when set directly' do
|
|
315
|
-
it 'should issue a deprecation warning and set the replacement value' do
|
|
316
|
-
redis = Backup::Database::Redis.new(model) do |db|
|
|
317
|
-
db.utility_path = 'foo'
|
|
318
|
-
end
|
|
319
|
-
redis.redis_cli_utility.should == 'foo'
|
|
320
|
-
end
|
|
321
|
-
end
|
|
322
|
-
|
|
323
|
-
context 'when set as a default' do
|
|
324
|
-
it 'should issue a deprecation warning and set the replacement value' do
|
|
325
|
-
redis = Backup::Database::Redis.defaults do |db|
|
|
326
|
-
db.utility_path = 'foo'
|
|
327
|
-
end
|
|
328
|
-
redis = Backup::Database::Redis.new(model)
|
|
329
|
-
redis.redis_cli_utility.should == 'foo'
|
|
330
|
-
end
|
|
331
|
-
end
|
|
332
|
-
end # describe '#utility_path'
|
|
333
|
-
end
|
|
334
|
-
end
|
data/spec/database/riak_spec.rb
DELETED
|
@@ -1,176 +0,0 @@
|
|
|
1
|
-
# encoding: utf-8
|
|
2
|
-
|
|
3
|
-
require File.expand_path('../../spec_helper.rb', __FILE__)
|
|
4
|
-
|
|
5
|
-
describe Backup::Database::Riak do
|
|
6
|
-
let(:model) { Backup::Model.new('foo', 'foo') }
|
|
7
|
-
let(:db) do
|
|
8
|
-
Backup::Database::Riak.new(model) do |db|
|
|
9
|
-
db.name = 'mydatabase'
|
|
10
|
-
db.node = 'riak@localhost'
|
|
11
|
-
db.cookie = 'riak'
|
|
12
|
-
db.riak_admin_utility = '/path/to/riak-admin'
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
it 'should be a subclass of Database::Base' do
|
|
17
|
-
Backup::Database::Riak.superclass.
|
|
18
|
-
should == Backup::Database::Base
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
describe '#initialize' do
|
|
22
|
-
|
|
23
|
-
it 'should load pre-configured defaults through Base' do
|
|
24
|
-
Backup::Database::Riak.any_instance.expects(:load_defaults!)
|
|
25
|
-
db
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
it 'should pass the model reference to Base' do
|
|
29
|
-
db.instance_variable_get(:@model).should == model
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
context 'when no pre-configured defaults have been set' do
|
|
33
|
-
context 'when options are specified' do
|
|
34
|
-
it 'should use the given values' do
|
|
35
|
-
db.name.should == 'mydatabase'
|
|
36
|
-
db.node.should == 'riak@localhost'
|
|
37
|
-
db.cookie.should == 'riak'
|
|
38
|
-
db.riak_admin_utility.should == '/path/to/riak-admin'
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
context 'when options are not specified' do
|
|
43
|
-
before do
|
|
44
|
-
Backup::Database::Riak.any_instance.expects(:utility).
|
|
45
|
-
with('riak-admin').returns('/real/riak-admin')
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
it 'should provide default values' do
|
|
49
|
-
db = Backup::Database::Riak.new(model)
|
|
50
|
-
|
|
51
|
-
db.name.should be_nil
|
|
52
|
-
db.node.should be_nil
|
|
53
|
-
db.cookie.should be_nil
|
|
54
|
-
db.riak_admin_utility.should == '/real/riak-admin'
|
|
55
|
-
end
|
|
56
|
-
end
|
|
57
|
-
end # context 'when no pre-configured defaults have been set'
|
|
58
|
-
|
|
59
|
-
context 'when pre-configured defaults have been set' do
|
|
60
|
-
before do
|
|
61
|
-
Backup::Database::Riak.defaults do |db|
|
|
62
|
-
db.name = 'db_name'
|
|
63
|
-
db.node = 'db_node'
|
|
64
|
-
db.cookie = 'db_cookie'
|
|
65
|
-
db.riak_admin_utility = '/default/path/to/riak-admin'
|
|
66
|
-
end
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
after { Backup::Database::Riak.clear_defaults! }
|
|
70
|
-
|
|
71
|
-
context 'when options are specified' do
|
|
72
|
-
it 'should override the pre-configured defaults' do
|
|
73
|
-
db.name.should == 'mydatabase'
|
|
74
|
-
db.node.should == 'riak@localhost'
|
|
75
|
-
db.cookie.should == 'riak'
|
|
76
|
-
db.riak_admin_utility.should == '/path/to/riak-admin'
|
|
77
|
-
end
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
context 'when options are not specified' do
|
|
81
|
-
it 'should use the pre-configured defaults' do
|
|
82
|
-
db = Backup::Database::Riak.new(model)
|
|
83
|
-
|
|
84
|
-
db.name.should == 'db_name'
|
|
85
|
-
db.node.should == 'db_node'
|
|
86
|
-
db.cookie.should == 'db_cookie'
|
|
87
|
-
db.riak_admin_utility.should == '/default/path/to/riak-admin'
|
|
88
|
-
end
|
|
89
|
-
end
|
|
90
|
-
end # context 'when no pre-configured defaults have been set'
|
|
91
|
-
end # describe '#initialize'
|
|
92
|
-
|
|
93
|
-
describe '#perform!' do
|
|
94
|
-
let(:compressor) { mock }
|
|
95
|
-
let(:s) { sequence '' }
|
|
96
|
-
before do
|
|
97
|
-
# superclass actions
|
|
98
|
-
db.expects(:prepare!).in_sequence(s)
|
|
99
|
-
db.expects(:log!).in_sequence(s)
|
|
100
|
-
db.instance_variable_set(:@dump_path, '/dump/path')
|
|
101
|
-
|
|
102
|
-
db.stubs(:riakadmin).returns('riakadmin_command')
|
|
103
|
-
end
|
|
104
|
-
|
|
105
|
-
context 'when no compressor is configured' do
|
|
106
|
-
it 'should only perform the riak-admin backup command' do
|
|
107
|
-
FileUtils.expects(:chown_R).with('riak', 'riak', '/dump/path')
|
|
108
|
-
db.expects(:run).in_sequence(s).
|
|
109
|
-
with('riakadmin_command /dump/path/mydatabase node')
|
|
110
|
-
|
|
111
|
-
db.perform!
|
|
112
|
-
end
|
|
113
|
-
end
|
|
114
|
-
|
|
115
|
-
context 'when a compressor is configured' do
|
|
116
|
-
before do
|
|
117
|
-
model.stubs(:compressor).returns(compressor)
|
|
118
|
-
compressor.expects(:compress_with).yields('compressor_command', '.gz')
|
|
119
|
-
end
|
|
120
|
-
|
|
121
|
-
it 'should compress the backup file and remove the source file' do
|
|
122
|
-
FileUtils.expects(:chown_R).with('riak', 'riak', '/dump/path')
|
|
123
|
-
db.expects(:run).in_sequence(s).
|
|
124
|
-
with('riakadmin_command /dump/path/mydatabase node')
|
|
125
|
-
db.expects(:run).in_sequence(s).with(
|
|
126
|
-
"compressor_command -c /dump/path/mydatabase > /dump/path/mydatabase.gz"
|
|
127
|
-
)
|
|
128
|
-
FileUtils.expects(:rm_f).in_sequence(s).with('/dump/path/mydatabase')
|
|
129
|
-
|
|
130
|
-
db.perform!
|
|
131
|
-
end
|
|
132
|
-
end
|
|
133
|
-
end
|
|
134
|
-
|
|
135
|
-
describe '#riakadmin' do
|
|
136
|
-
it 'should return the full riakadmin string' do
|
|
137
|
-
db.send(:riakadmin).should == "/path/to/riak-admin backup riak@localhost riak"
|
|
138
|
-
end
|
|
139
|
-
end
|
|
140
|
-
|
|
141
|
-
describe 'deprecations' do
|
|
142
|
-
describe '#utility_path' do
|
|
143
|
-
before do
|
|
144
|
-
Backup::Database::Riak.any_instance.stubs(:utility)
|
|
145
|
-
Backup::Logger.expects(:warn).with {|err|
|
|
146
|
-
err.should be_an_instance_of Backup::Errors::ConfigurationError
|
|
147
|
-
err.message.should match(
|
|
148
|
-
/Use Riak#riak_admin_utility instead/
|
|
149
|
-
)
|
|
150
|
-
}
|
|
151
|
-
end
|
|
152
|
-
after do
|
|
153
|
-
Backup::Database::Riak.clear_defaults!
|
|
154
|
-
end
|
|
155
|
-
|
|
156
|
-
context 'when set directly' do
|
|
157
|
-
it 'should issue a deprecation warning and set the replacement value' do
|
|
158
|
-
riak = Backup::Database::Riak.new(model) do |db|
|
|
159
|
-
db.utility_path = 'foo'
|
|
160
|
-
end
|
|
161
|
-
riak.riak_admin_utility.should == 'foo'
|
|
162
|
-
end
|
|
163
|
-
end
|
|
164
|
-
|
|
165
|
-
context 'when set as a default' do
|
|
166
|
-
it 'should issue a deprecation warning and set the replacement value' do
|
|
167
|
-
riak = Backup::Database::Riak.defaults do |db|
|
|
168
|
-
db.utility_path = 'foo'
|
|
169
|
-
end
|
|
170
|
-
riak = Backup::Database::Riak.new(model)
|
|
171
|
-
riak.riak_admin_utility.should == 'foo'
|
|
172
|
-
end
|
|
173
|
-
end
|
|
174
|
-
end # describe '#utility_path'
|
|
175
|
-
end
|
|
176
|
-
end
|