backup 3.0.20 → 3.0.21
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -5
- data/Gemfile.lock +46 -50
- data/README.md +54 -27
- data/lib/backup.rb +16 -39
- data/lib/backup/archive.rb +42 -18
- data/lib/backup/cleaner.rb +110 -25
- data/lib/backup/cli/helpers.rb +17 -32
- data/lib/backup/cli/utility.rb +46 -107
- data/lib/backup/compressor/base.rb +14 -2
- data/lib/backup/compressor/bzip2.rb +10 -24
- data/lib/backup/compressor/gzip.rb +10 -24
- data/lib/backup/compressor/lzma.rb +10 -23
- data/lib/backup/compressor/pbzip2.rb +12 -32
- data/lib/backup/config.rb +171 -0
- data/lib/backup/configuration/compressor/base.rb +1 -2
- data/lib/backup/configuration/compressor/pbzip2.rb +4 -4
- data/lib/backup/configuration/database/base.rb +2 -1
- data/lib/backup/configuration/database/mongodb.rb +8 -0
- data/lib/backup/configuration/database/mysql.rb +4 -0
- data/lib/backup/configuration/database/postgresql.rb +4 -0
- data/lib/backup/configuration/database/redis.rb +4 -0
- data/lib/backup/configuration/database/riak.rb +5 -1
- data/lib/backup/configuration/encryptor/base.rb +1 -2
- data/lib/backup/configuration/encryptor/open_ssl.rb +1 -1
- data/lib/backup/configuration/helpers.rb +7 -2
- data/lib/backup/configuration/notifier/base.rb +4 -28
- data/lib/backup/configuration/storage/base.rb +1 -1
- data/lib/backup/configuration/storage/dropbox.rb +14 -4
- data/lib/backup/configuration/syncer/base.rb +10 -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 +0 -4
- data/lib/backup/database/base.rb +25 -7
- data/lib/backup/database/mongodb.rb +112 -75
- data/lib/backup/database/mysql.rb +54 -29
- data/lib/backup/database/postgresql.rb +60 -42
- data/lib/backup/database/redis.rb +61 -39
- data/lib/backup/database/riak.rb +35 -11
- data/lib/backup/dependency.rb +4 -5
- data/lib/backup/encryptor/base.rb +13 -1
- data/lib/backup/encryptor/gpg.rb +39 -39
- data/lib/backup/encryptor/open_ssl.rb +28 -38
- data/lib/backup/logger.rb +20 -11
- data/lib/backup/model.rb +206 -163
- data/lib/backup/notifier/base.rb +27 -25
- data/lib/backup/notifier/campfire.rb +7 -13
- data/lib/backup/notifier/hipchat.rb +28 -28
- data/lib/backup/notifier/mail.rb +24 -26
- data/lib/backup/notifier/presently.rb +10 -18
- data/lib/backup/notifier/prowl.rb +9 -17
- data/lib/backup/notifier/twitter.rb +11 -18
- data/lib/backup/package.rb +47 -0
- data/lib/backup/packager.rb +81 -16
- data/lib/backup/splitter.rb +48 -35
- data/lib/backup/storage/base.rb +44 -172
- data/lib/backup/storage/cloudfiles.rb +31 -46
- data/lib/backup/storage/cycler.rb +117 -0
- data/lib/backup/storage/dropbox.rb +92 -76
- data/lib/backup/storage/ftp.rb +30 -40
- data/lib/backup/storage/local.rb +44 -45
- data/lib/backup/storage/ninefold.rb +55 -49
- data/lib/backup/storage/rsync.rb +49 -56
- data/lib/backup/storage/s3.rb +33 -44
- data/lib/backup/storage/scp.rb +21 -48
- data/lib/backup/storage/sftp.rb +26 -40
- data/lib/backup/syncer/base.rb +7 -0
- data/lib/backup/syncer/rsync/base.rb +78 -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 +42 -32
- data/lib/backup/version.rb +1 -1
- data/spec/archive_spec.rb +235 -69
- data/spec/cleaner_spec.rb +304 -0
- data/spec/cli/helpers_spec.rb +142 -1
- data/spec/cli/utility_spec.rb +338 -13
- data/spec/compressor/base_spec.rb +31 -0
- data/spec/compressor/bzip2_spec.rb +60 -35
- data/spec/compressor/gzip_spec.rb +60 -35
- data/spec/compressor/lzma_spec.rb +60 -35
- data/spec/compressor/pbzip2_spec.rb +98 -37
- data/spec/config_spec.rb +321 -0
- data/spec/configuration/base_spec.rb +4 -4
- data/spec/configuration/compressor/bzip2_spec.rb +1 -0
- data/spec/configuration/compressor/gzip_spec.rb +1 -0
- data/spec/configuration/compressor/lzma_spec.rb +1 -0
- data/spec/configuration/compressor/pbzip2_spec.rb +32 -0
- data/spec/configuration/database/base_spec.rb +2 -1
- data/spec/configuration/database/mongodb_spec.rb +26 -16
- data/spec/configuration/database/mysql_spec.rb +4 -0
- data/spec/configuration/database/postgresql_spec.rb +4 -0
- data/spec/configuration/database/redis_spec.rb +4 -0
- data/spec/configuration/database/riak_spec.rb +4 -0
- data/spec/configuration/encryptor/gpg_spec.rb +1 -0
- data/spec/configuration/encryptor/open_ssl_spec.rb +1 -0
- data/spec/configuration/notifier/base_spec.rb +32 -0
- data/spec/configuration/notifier/campfire_spec.rb +1 -0
- data/spec/configuration/notifier/hipchat_spec.rb +1 -0
- data/spec/configuration/notifier/mail_spec.rb +1 -0
- data/spec/configuration/notifier/presently_spec.rb +1 -0
- data/spec/configuration/notifier/prowl_spec.rb +1 -0
- data/spec/configuration/notifier/twitter_spec.rb +1 -0
- data/spec/configuration/storage/cloudfiles_spec.rb +1 -0
- data/spec/configuration/storage/dropbox_spec.rb +4 -3
- data/spec/configuration/storage/ftp_spec.rb +1 -0
- data/spec/configuration/storage/local_spec.rb +1 -0
- data/spec/configuration/storage/ninefold_spec.rb +1 -0
- data/spec/configuration/storage/rsync_spec.rb +3 -1
- data/spec/configuration/storage/s3_spec.rb +1 -0
- data/spec/configuration/storage/scp_spec.rb +1 -0
- data/spec/configuration/storage/sftp_spec.rb +1 -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_spec.rb → rsync/push_spec.rb} +12 -15
- data/spec/configuration/syncer/s3_spec.rb +2 -3
- data/spec/database/base_spec.rb +35 -20
- data/spec/database/mongodb_spec.rb +298 -119
- data/spec/database/mysql_spec.rb +147 -72
- data/spec/database/postgresql_spec.rb +155 -100
- data/spec/database/redis_spec.rb +200 -97
- data/spec/database/riak_spec.rb +82 -24
- data/spec/dependency_spec.rb +49 -0
- data/spec/encryptor/base_spec.rb +30 -0
- data/spec/encryptor/gpg_spec.rb +105 -28
- data/spec/encryptor/open_ssl_spec.rb +85 -114
- data/spec/logger_spec.rb +74 -8
- data/spec/model_spec.rb +528 -220
- data/spec/notifier/base_spec.rb +89 -0
- data/spec/notifier/campfire_spec.rb +147 -119
- data/spec/notifier/hipchat_spec.rb +140 -145
- data/spec/notifier/mail_spec.rb +190 -248
- data/spec/notifier/presently_spec.rb +147 -282
- data/spec/notifier/prowl_spec.rb +79 -111
- data/spec/notifier/twitter_spec.rb +87 -106
- data/spec/package_spec.rb +61 -0
- data/spec/packager_spec.rb +154 -0
- data/spec/spec_helper.rb +36 -13
- data/spec/splitter_spec.rb +90 -41
- data/spec/storage/base_spec.rb +95 -239
- data/spec/storage/cloudfiles_spec.rb +185 -75
- data/spec/storage/cycler_spec.rb +239 -0
- data/spec/storage/dropbox_spec.rb +318 -87
- data/spec/storage/ftp_spec.rb +165 -152
- data/spec/storage/local_spec.rb +206 -54
- data/spec/storage/ninefold_spec.rb +264 -128
- data/spec/storage/rsync_spec.rb +244 -163
- data/spec/storage/s3_spec.rb +175 -64
- data/spec/storage/scp_spec.rb +156 -150
- data/spec/storage/sftp_spec.rb +153 -135
- data/spec/syncer/base_spec.rb +22 -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 +180 -91
- data/templates/cli/utility/config +1 -1
- data/templates/cli/utility/database/mongodb +4 -0
- data/templates/cli/utility/database/mysql +3 -0
- data/templates/cli/utility/database/postgresql +3 -0
- data/templates/cli/utility/database/redis +3 -0
- data/templates/cli/utility/database/riak +3 -0
- data/templates/cli/utility/storage/dropbox +4 -1
- data/templates/cli/utility/syncer/rsync_local +12 -0
- data/templates/cli/utility/syncer/{rsync → rsync_pull} +2 -2
- data/templates/cli/utility/syncer/rsync_push +17 -0
- data/templates/storage/dropbox/authorization_url.erb +1 -1
- metadata +42 -17
- data/lib/backup/configuration/syncer/rsync.rb +0 -45
- data/lib/backup/finder.rb +0 -87
- data/lib/backup/storage/object.rb +0 -47
- data/lib/backup/syncer/rsync.rb +0 -152
- data/spec/backup_spec.rb +0 -11
- data/spec/finder_spec.rb +0 -91
- data/spec/storage/object_spec.rb +0 -74
- data/spec/syncer/rsync_spec.rb +0 -195
data/spec/database/redis_spec.rb
CHANGED
@@ -3,155 +3,258 @@
|
|
3
3
|
require File.expand_path('../../spec_helper.rb', __FILE__)
|
4
4
|
|
5
5
|
describe Backup::Database::Redis do
|
6
|
-
|
7
|
-
before do
|
8
|
-
Backup::Database::Redis.any_instance.stubs(:load_defaults!)
|
9
|
-
end
|
10
|
-
|
6
|
+
let(:model) { Backup::Model.new('foo', 'foo') }
|
11
7
|
let(:db) do
|
12
|
-
Backup::Database::Redis.new do |db|
|
13
|
-
db.name
|
14
|
-
db.path
|
15
|
-
db.password
|
16
|
-
db.host
|
17
|
-
db.port
|
18
|
-
db.socket
|
19
|
-
db.invoke_save
|
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
|
20
16
|
|
21
|
-
db.additional_options = ['--query']
|
17
|
+
db.additional_options = ['--query', '--foo']
|
18
|
+
db.redis_cli_utility = '/path/to/redis-cli'
|
22
19
|
end
|
23
20
|
end
|
24
21
|
|
25
|
-
describe '#
|
22
|
+
describe '#initialize' do
|
26
23
|
it 'should read the adapter details correctly' do
|
27
24
|
db.name.should == 'mydatabase'
|
25
|
+
db.path.should == '/var/lib/redis/db/'
|
28
26
|
db.password.should == 'secret'
|
29
27
|
db.host.should == 'localhost'
|
30
|
-
db.port.should == 123
|
28
|
+
db.port.should == '123'
|
31
29
|
db.socket.should == '/redis.sock'
|
32
30
|
db.invoke_save.should == true
|
33
31
|
|
34
|
-
db.additional_options.should == '--query'
|
32
|
+
db.additional_options.should == ['--query', '--foo']
|
33
|
+
db.redis_cli_utility.should == '/path/to/redis-cli'
|
35
34
|
end
|
36
35
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
36
|
+
context 'when options are not set' do
|
37
|
+
before do
|
38
|
+
Backup::Database::Redis.any_instance.expects(:utility).
|
39
|
+
with('redis-cli').returns('/real/redis-cli')
|
41
40
|
end
|
42
41
|
|
43
|
-
|
42
|
+
it 'should use default values' do
|
43
|
+
db = Backup::Database::Redis.new(model)
|
44
|
+
|
45
|
+
db.name.should == 'dump'
|
46
|
+
db.path.should be_nil
|
47
|
+
db.password.should be_nil
|
48
|
+
db.host.should be_nil
|
49
|
+
db.port.should be_nil
|
50
|
+
db.socket.should be_nil
|
51
|
+
db.invoke_save.should be_nil
|
52
|
+
|
53
|
+
db.additional_options.should == []
|
54
|
+
db.redis_cli_utility.should == '/real/redis-cli'
|
55
|
+
end
|
44
56
|
end
|
45
|
-
end
|
46
57
|
|
47
|
-
|
48
|
-
|
49
|
-
|
58
|
+
context 'when configuration defaults have been set' do
|
59
|
+
after { Backup::Configuration::Database::Redis.clear_defaults! }
|
60
|
+
|
61
|
+
it 'should use configuration defaults' do
|
62
|
+
Backup::Configuration::Database::Redis.defaults do |db|
|
63
|
+
db.name = 'db_name'
|
64
|
+
db.path = 'db_path'
|
65
|
+
db.password = 'db_password'
|
66
|
+
db.host = 'db_host'
|
67
|
+
db.port = 789
|
68
|
+
db.socket = '/foo.sock'
|
69
|
+
db.invoke_save = true
|
70
|
+
|
71
|
+
db.additional_options = ['--add', '--opts']
|
72
|
+
db.redis_cli_utility = '/default/path/to/redis-cli'
|
73
|
+
end
|
74
|
+
|
75
|
+
db = Backup::Database::Redis.new(model)
|
76
|
+
db.name.should == 'db_name'
|
77
|
+
db.path.should == 'db_path'
|
78
|
+
db.password.should == 'db_password'
|
79
|
+
db.host.should == 'db_host'
|
80
|
+
db.port.should == 789
|
81
|
+
db.socket.should == '/foo.sock'
|
82
|
+
db.invoke_save.should == true
|
83
|
+
|
84
|
+
db.additional_options.should == ['--add', '--opts']
|
85
|
+
db.redis_cli_utility.should == '/default/path/to/redis-cli'
|
86
|
+
end
|
50
87
|
end
|
51
|
-
end
|
88
|
+
end # describe '#initialize'
|
52
89
|
|
53
|
-
describe '#
|
54
|
-
|
55
|
-
|
90
|
+
describe '#perform!' do
|
91
|
+
let(:s) { sequence '' }
|
92
|
+
before do
|
93
|
+
# superclass actions
|
94
|
+
db.expects(:prepare!).in_sequence(s)
|
95
|
+
db.expects(:log!).in_sequence(s)
|
56
96
|
end
|
57
97
|
|
58
|
-
|
59
|
-
db =
|
60
|
-
|
61
|
-
db.
|
98
|
+
context 'when #invoke_save is true' do
|
99
|
+
before { db.invoke_save = true }
|
100
|
+
it 'should copy over after persisting (saving) the most recent updates' do
|
101
|
+
db.expects(:invoke_save!).in_sequence(s)
|
102
|
+
db.expects(:copy!).in_sequence(s)
|
103
|
+
|
104
|
+
db.perform!
|
62
105
|
end
|
106
|
+
end
|
107
|
+
|
108
|
+
context 'when #invoke_save is not true' do
|
109
|
+
before { db.invoke_save = nil }
|
110
|
+
it 'should copy over without persisting (saving) first' do
|
111
|
+
db.expects(:invoke_save!).never
|
112
|
+
db.expects(:copy!).in_sequence(s)
|
63
113
|
|
64
|
-
|
114
|
+
db.perform!
|
115
|
+
end
|
65
116
|
end
|
66
|
-
|
117
|
+
|
118
|
+
end # describe '#perform!'
|
67
119
|
|
68
120
|
describe '#invoke_save!' do
|
121
|
+
before do
|
122
|
+
db.stubs(:credential_options).returns(:credential_options_output)
|
123
|
+
db.stubs(:connectivity_options).returns(:connectivity_options_output)
|
124
|
+
db.stubs(:user_options).returns(:user_options_output)
|
125
|
+
end
|
126
|
+
|
127
|
+
context 'when response is OK' do
|
128
|
+
it 'should run the redis-cli command string' do
|
129
|
+
db.expects(:run).with(
|
130
|
+
'/path/to/redis-cli credential_options_output ' +
|
131
|
+
'connectivity_options_output user_options_output SAVE'
|
132
|
+
).returns('result OK for command')
|
69
133
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
db.stubs(:raise)
|
75
|
-
db.invoke_save!
|
134
|
+
expect do
|
135
|
+
db.send(:invoke_save!)
|
136
|
+
end.not_to raise_error
|
137
|
+
end
|
76
138
|
end
|
77
139
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
140
|
+
context 'when response is not OK' do
|
141
|
+
it 'should raise an error' do
|
142
|
+
db.stubs(:run).returns('result not ok for command')
|
143
|
+
db.stubs(:database).returns('database_filename')
|
144
|
+
|
145
|
+
expect do
|
146
|
+
db.send(:invoke_save!)
|
147
|
+
end.to raise_error {|err|
|
148
|
+
err.should be_an_instance_of Backup::Errors::Database::Redis::CommandError
|
149
|
+
err.message.should match(/Could not invoke the Redis SAVE command/)
|
150
|
+
err.message.should match(/The database_filename file/)
|
151
|
+
err.message.should match(/Redis CLI response: result not ok/)
|
152
|
+
}
|
86
153
|
end
|
87
154
|
end
|
88
155
|
|
89
156
|
end # describe '#invoke_save!'
|
90
157
|
|
91
158
|
describe '#copy!' do
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
db.expects(:run).with("cp '#{ File.join('/var/lib/redis/db/mydatabase.rdb') }' '#{ File.join(Backup::TMP_PATH, Backup::TRIGGER, 'Redis', 'mydatabase.rdb') }'")
|
96
|
-
db.expects(:mkdir).with(File.join(Backup::TMP_PATH, "myapp", "Redis"))
|
97
|
-
db.prepare!
|
98
|
-
db.copy!
|
99
|
-
end
|
159
|
+
let(:src_path) { '/var/lib/redis/db/mydatabase.rdb' }
|
160
|
+
let(:dst_path) { '/dump/path/mydatabase.rdb' }
|
161
|
+
let(:compressor) { mock }
|
100
162
|
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
db.prepare!
|
107
|
-
db.copy!
|
108
|
-
end
|
163
|
+
context 'when the database exists' do
|
164
|
+
before do
|
165
|
+
db.instance_variable_set(:@dump_path, '/dump/path')
|
166
|
+
File.expects(:exist?).with(src_path).returns(true)
|
167
|
+
end
|
109
168
|
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
169
|
+
context 'when no compressor is configured' do
|
170
|
+
it 'should copy the database' do
|
171
|
+
db.expects(:run).never
|
172
|
+
|
173
|
+
FileUtils.expects(:cp).with(src_path, dst_path)
|
174
|
+
db.send(:copy!)
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
context 'when a compressor is configured' do
|
179
|
+
before do
|
180
|
+
model.stubs(:compressor).returns(compressor)
|
181
|
+
compressor.expects(:compress_with).yields('compressor_command', '.gz')
|
182
|
+
end
|
183
|
+
|
184
|
+
it 'should copy the database using the compressor' do
|
185
|
+
FileUtils.expects(:cp).never
|
186
|
+
|
187
|
+
db.expects(:run).with(
|
188
|
+
"compressor_command -c #{ src_path } > #{ dst_path }.gz"
|
189
|
+
)
|
190
|
+
db.send(:copy!)
|
191
|
+
end
|
116
192
|
end
|
117
193
|
end
|
118
|
-
end
|
119
194
|
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
195
|
+
context 'when the database does not exist' do
|
196
|
+
it 'should raise an error if the database dump file is not found' do
|
197
|
+
File.expects(:exist?).returns(false)
|
198
|
+
expect do
|
199
|
+
db.send(:copy!)
|
200
|
+
end.to raise_error do |err|
|
201
|
+
err.should be_an_instance_of Backup::Errors::Database::Redis::NotFoundError
|
202
|
+
err.message.should match(/Redis database dump not found/)
|
203
|
+
err.message.should match(/File path was #{src_path}/)
|
204
|
+
end
|
205
|
+
end
|
127
206
|
end
|
207
|
+
end # describe '#copy!'
|
128
208
|
|
129
|
-
|
130
|
-
|
131
|
-
db.
|
209
|
+
describe '#database' do
|
210
|
+
it 'should return the database name with the extension added' do
|
211
|
+
db.send(:database).should == 'mydatabase.rdb'
|
132
212
|
end
|
213
|
+
end
|
133
214
|
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
215
|
+
describe '#credential_options' do
|
216
|
+
context 'when #password is set' do
|
217
|
+
it 'should return the redis-cli syntax for the credential options' do
|
218
|
+
db.send(:credential_options).should == "-a 'secret'"
|
219
|
+
end
|
220
|
+
end
|
138
221
|
|
139
|
-
|
222
|
+
context 'when password is not set' do
|
223
|
+
it 'should return an empty string' do
|
224
|
+
db.password = nil
|
225
|
+
db.send(:credential_options).should == ''
|
226
|
+
end
|
140
227
|
end
|
228
|
+
end
|
141
229
|
|
142
|
-
|
143
|
-
|
144
|
-
db.
|
145
|
-
|
230
|
+
describe '#connectivity_options' do
|
231
|
+
it 'should return the redis syntax for the connectivity options' do
|
232
|
+
db.send(:connectivity_options).should ==
|
233
|
+
"-h 'localhost' -p '123' -s '/redis.sock'"
|
234
|
+
end
|
146
235
|
|
147
|
-
|
236
|
+
context 'when only the #port is set' do
|
237
|
+
it 'should return only the port' do
|
238
|
+
db.host = nil
|
239
|
+
db.socket = nil
|
240
|
+
db.send(:connectivity_options).should == "-p '123'"
|
241
|
+
end
|
148
242
|
end
|
243
|
+
end
|
149
244
|
|
150
|
-
|
151
|
-
|
152
|
-
|
245
|
+
describe '#user_options' do
|
246
|
+
context 'when #additional_options are set' do
|
247
|
+
it 'should return the options' do
|
248
|
+
db.send(:user_options).should == '--query --foo'
|
249
|
+
end
|
250
|
+
end
|
153
251
|
|
154
|
-
|
252
|
+
context 'when #additional_options is not set' do
|
253
|
+
it 'should return an empty string' do
|
254
|
+
db.additional_options = []
|
255
|
+
db.send(:user_options).should == ''
|
256
|
+
end
|
155
257
|
end
|
156
258
|
end
|
259
|
+
|
157
260
|
end
|
data/spec/database/riak_spec.rb
CHANGED
@@ -3,48 +3,106 @@
|
|
3
3
|
require File.expand_path('../../spec_helper.rb', __FILE__)
|
4
4
|
|
5
5
|
describe Backup::Database::Riak do
|
6
|
-
|
7
|
-
before do
|
8
|
-
Backup::Database::Riak.any_instance.stubs(:load_defaults!)
|
9
|
-
end
|
10
|
-
|
6
|
+
let(:model) { Backup::Model.new('foo', 'foo') }
|
11
7
|
let(:db) do
|
12
|
-
Backup::Database::Riak.new do |db|
|
13
|
-
db.name
|
14
|
-
db.node
|
15
|
-
db.cookie
|
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'
|
16
13
|
end
|
17
14
|
end
|
18
15
|
|
19
|
-
describe '#
|
16
|
+
describe '#initialize' do
|
20
17
|
it 'should read the adapter details correctly' do
|
21
18
|
db.name.should == 'mydatabase'
|
22
19
|
db.node.should == 'riak@localhost'
|
23
20
|
db.cookie.should == 'riak'
|
21
|
+
db.riak_admin_utility.should == '/path/to/riak-admin'
|
24
22
|
end
|
25
|
-
end
|
26
23
|
|
27
|
-
|
28
|
-
|
29
|
-
|
24
|
+
context 'when options are not set' do
|
25
|
+
before do
|
26
|
+
Backup::Database::Riak.any_instance.expects(:utility).
|
27
|
+
with('riak-admin').returns('/real/riak-admin')
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'should use default values' do
|
31
|
+
db = Backup::Database::Riak.new(model)
|
32
|
+
|
33
|
+
db.name.should be_nil
|
34
|
+
db.node.should be_nil
|
35
|
+
db.cookie.should be_nil
|
36
|
+
db.riak_admin_utility.should == '/real/riak-admin'
|
37
|
+
end
|
30
38
|
end
|
31
|
-
|
39
|
+
|
40
|
+
context 'when configuration defaults have been set' do
|
41
|
+
after { Backup::Configuration::Database::Riak.clear_defaults! }
|
42
|
+
|
43
|
+
it 'should use configuration defaults' do
|
44
|
+
Backup::Configuration::Database::Riak.defaults do |db|
|
45
|
+
db.name = 'db_name'
|
46
|
+
db.node = 'db_node'
|
47
|
+
db.cookie = 'db_cookie'
|
48
|
+
db.riak_admin_utility = '/default/path/to/riak-admin'
|
49
|
+
end
|
50
|
+
|
51
|
+
db = Backup::Database::Riak.new(model)
|
52
|
+
db.name.should == 'db_name'
|
53
|
+
db.node.should == 'db_node'
|
54
|
+
db.cookie.should == 'db_cookie'
|
55
|
+
db.riak_admin_utility.should == '/default/path/to/riak-admin'
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end # describe '#initialize'
|
32
59
|
|
33
60
|
describe '#perform!' do
|
61
|
+
let(:compressor) { mock }
|
62
|
+
let(:s) { sequence '' }
|
34
63
|
before do
|
35
|
-
|
36
|
-
db.
|
64
|
+
# superclass actions
|
65
|
+
db.expects(:prepare!).in_sequence(s)
|
66
|
+
db.expects(:log!).in_sequence(s)
|
67
|
+
db.instance_variable_set(:@dump_path, '/dump/path')
|
68
|
+
|
69
|
+
db.stubs(:riakadmin).returns('riakadmin_command')
|
70
|
+
end
|
71
|
+
|
72
|
+
context 'when no compressor is configured' do
|
73
|
+
it 'should only perform the riak-admin backup command' do
|
74
|
+
FileUtils.expects(:chown_R).with('riak', 'riak', '/dump/path')
|
75
|
+
db.expects(:run).in_sequence(s).
|
76
|
+
with('riakadmin_command /dump/path/mydatabase node')
|
77
|
+
|
78
|
+
db.perform!
|
79
|
+
end
|
37
80
|
end
|
38
81
|
|
39
|
-
|
40
|
-
|
41
|
-
|
82
|
+
context 'when a compressor is configured' do
|
83
|
+
before do
|
84
|
+
model.stubs(:compressor).returns(compressor)
|
85
|
+
compressor.expects(:compress_with).yields('compressor_command', '.gz')
|
86
|
+
end
|
87
|
+
|
88
|
+
it 'should compress the backup file and remove the source file' do
|
89
|
+
FileUtils.expects(:chown_R).with('riak', 'riak', '/dump/path')
|
90
|
+
db.expects(:run).in_sequence(s).
|
91
|
+
with('riakadmin_command /dump/path/mydatabase node')
|
92
|
+
db.expects(:run).in_sequence(s).with(
|
93
|
+
"compressor_command -c /dump/path/mydatabase > /dump/path/mydatabase.gz"
|
94
|
+
)
|
95
|
+
FileUtils.expects(:rm_f).in_sequence(s).with('/dump/path/mydatabase')
|
96
|
+
|
97
|
+
db.perform!
|
98
|
+
end
|
42
99
|
end
|
100
|
+
end
|
43
101
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
db.perform!
|
102
|
+
describe '#riakadmin' do
|
103
|
+
it 'should return the full riakadmin string' do
|
104
|
+
db.send(:riakadmin).should == "/path/to/riak-admin backup riak@localhost riak"
|
48
105
|
end
|
49
106
|
end
|
107
|
+
|
50
108
|
end
|