backup 3.0.20 → 3.0.21

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.
Files changed (178) hide show
  1. data/Gemfile +1 -5
  2. data/Gemfile.lock +46 -50
  3. data/README.md +54 -27
  4. data/lib/backup.rb +16 -39
  5. data/lib/backup/archive.rb +42 -18
  6. data/lib/backup/cleaner.rb +110 -25
  7. data/lib/backup/cli/helpers.rb +17 -32
  8. data/lib/backup/cli/utility.rb +46 -107
  9. data/lib/backup/compressor/base.rb +14 -2
  10. data/lib/backup/compressor/bzip2.rb +10 -24
  11. data/lib/backup/compressor/gzip.rb +10 -24
  12. data/lib/backup/compressor/lzma.rb +10 -23
  13. data/lib/backup/compressor/pbzip2.rb +12 -32
  14. data/lib/backup/config.rb +171 -0
  15. data/lib/backup/configuration/compressor/base.rb +1 -2
  16. data/lib/backup/configuration/compressor/pbzip2.rb +4 -4
  17. data/lib/backup/configuration/database/base.rb +2 -1
  18. data/lib/backup/configuration/database/mongodb.rb +8 -0
  19. data/lib/backup/configuration/database/mysql.rb +4 -0
  20. data/lib/backup/configuration/database/postgresql.rb +4 -0
  21. data/lib/backup/configuration/database/redis.rb +4 -0
  22. data/lib/backup/configuration/database/riak.rb +5 -1
  23. data/lib/backup/configuration/encryptor/base.rb +1 -2
  24. data/lib/backup/configuration/encryptor/open_ssl.rb +1 -1
  25. data/lib/backup/configuration/helpers.rb +7 -2
  26. data/lib/backup/configuration/notifier/base.rb +4 -28
  27. data/lib/backup/configuration/storage/base.rb +1 -1
  28. data/lib/backup/configuration/storage/dropbox.rb +14 -4
  29. data/lib/backup/configuration/syncer/base.rb +10 -0
  30. data/lib/backup/configuration/syncer/rsync/base.rb +28 -0
  31. data/lib/backup/configuration/syncer/rsync/local.rb +11 -0
  32. data/lib/backup/configuration/syncer/rsync/pull.rb +11 -0
  33. data/lib/backup/configuration/syncer/rsync/push.rb +31 -0
  34. data/lib/backup/configuration/syncer/s3.rb +0 -4
  35. data/lib/backup/database/base.rb +25 -7
  36. data/lib/backup/database/mongodb.rb +112 -75
  37. data/lib/backup/database/mysql.rb +54 -29
  38. data/lib/backup/database/postgresql.rb +60 -42
  39. data/lib/backup/database/redis.rb +61 -39
  40. data/lib/backup/database/riak.rb +35 -11
  41. data/lib/backup/dependency.rb +4 -5
  42. data/lib/backup/encryptor/base.rb +13 -1
  43. data/lib/backup/encryptor/gpg.rb +39 -39
  44. data/lib/backup/encryptor/open_ssl.rb +28 -38
  45. data/lib/backup/logger.rb +20 -11
  46. data/lib/backup/model.rb +206 -163
  47. data/lib/backup/notifier/base.rb +27 -25
  48. data/lib/backup/notifier/campfire.rb +7 -13
  49. data/lib/backup/notifier/hipchat.rb +28 -28
  50. data/lib/backup/notifier/mail.rb +24 -26
  51. data/lib/backup/notifier/presently.rb +10 -18
  52. data/lib/backup/notifier/prowl.rb +9 -17
  53. data/lib/backup/notifier/twitter.rb +11 -18
  54. data/lib/backup/package.rb +47 -0
  55. data/lib/backup/packager.rb +81 -16
  56. data/lib/backup/splitter.rb +48 -35
  57. data/lib/backup/storage/base.rb +44 -172
  58. data/lib/backup/storage/cloudfiles.rb +31 -46
  59. data/lib/backup/storage/cycler.rb +117 -0
  60. data/lib/backup/storage/dropbox.rb +92 -76
  61. data/lib/backup/storage/ftp.rb +30 -40
  62. data/lib/backup/storage/local.rb +44 -45
  63. data/lib/backup/storage/ninefold.rb +55 -49
  64. data/lib/backup/storage/rsync.rb +49 -56
  65. data/lib/backup/storage/s3.rb +33 -44
  66. data/lib/backup/storage/scp.rb +21 -48
  67. data/lib/backup/storage/sftp.rb +26 -40
  68. data/lib/backup/syncer/base.rb +7 -0
  69. data/lib/backup/syncer/rsync/base.rb +78 -0
  70. data/lib/backup/syncer/rsync/local.rb +53 -0
  71. data/lib/backup/syncer/rsync/pull.rb +38 -0
  72. data/lib/backup/syncer/rsync/push.rb +113 -0
  73. data/lib/backup/syncer/s3.rb +42 -32
  74. data/lib/backup/version.rb +1 -1
  75. data/spec/archive_spec.rb +235 -69
  76. data/spec/cleaner_spec.rb +304 -0
  77. data/spec/cli/helpers_spec.rb +142 -1
  78. data/spec/cli/utility_spec.rb +338 -13
  79. data/spec/compressor/base_spec.rb +31 -0
  80. data/spec/compressor/bzip2_spec.rb +60 -35
  81. data/spec/compressor/gzip_spec.rb +60 -35
  82. data/spec/compressor/lzma_spec.rb +60 -35
  83. data/spec/compressor/pbzip2_spec.rb +98 -37
  84. data/spec/config_spec.rb +321 -0
  85. data/spec/configuration/base_spec.rb +4 -4
  86. data/spec/configuration/compressor/bzip2_spec.rb +1 -0
  87. data/spec/configuration/compressor/gzip_spec.rb +1 -0
  88. data/spec/configuration/compressor/lzma_spec.rb +1 -0
  89. data/spec/configuration/compressor/pbzip2_spec.rb +32 -0
  90. data/spec/configuration/database/base_spec.rb +2 -1
  91. data/spec/configuration/database/mongodb_spec.rb +26 -16
  92. data/spec/configuration/database/mysql_spec.rb +4 -0
  93. data/spec/configuration/database/postgresql_spec.rb +4 -0
  94. data/spec/configuration/database/redis_spec.rb +4 -0
  95. data/spec/configuration/database/riak_spec.rb +4 -0
  96. data/spec/configuration/encryptor/gpg_spec.rb +1 -0
  97. data/spec/configuration/encryptor/open_ssl_spec.rb +1 -0
  98. data/spec/configuration/notifier/base_spec.rb +32 -0
  99. data/spec/configuration/notifier/campfire_spec.rb +1 -0
  100. data/spec/configuration/notifier/hipchat_spec.rb +1 -0
  101. data/spec/configuration/notifier/mail_spec.rb +1 -0
  102. data/spec/configuration/notifier/presently_spec.rb +1 -0
  103. data/spec/configuration/notifier/prowl_spec.rb +1 -0
  104. data/spec/configuration/notifier/twitter_spec.rb +1 -0
  105. data/spec/configuration/storage/cloudfiles_spec.rb +1 -0
  106. data/spec/configuration/storage/dropbox_spec.rb +4 -3
  107. data/spec/configuration/storage/ftp_spec.rb +1 -0
  108. data/spec/configuration/storage/local_spec.rb +1 -0
  109. data/spec/configuration/storage/ninefold_spec.rb +1 -0
  110. data/spec/configuration/storage/rsync_spec.rb +3 -1
  111. data/spec/configuration/storage/s3_spec.rb +1 -0
  112. data/spec/configuration/storage/scp_spec.rb +1 -0
  113. data/spec/configuration/storage/sftp_spec.rb +1 -0
  114. data/spec/configuration/syncer/rsync/base_spec.rb +33 -0
  115. data/spec/configuration/syncer/rsync/local_spec.rb +10 -0
  116. data/spec/configuration/syncer/rsync/pull_spec.rb +10 -0
  117. data/spec/configuration/syncer/{rsync_spec.rb → rsync/push_spec.rb} +12 -15
  118. data/spec/configuration/syncer/s3_spec.rb +2 -3
  119. data/spec/database/base_spec.rb +35 -20
  120. data/spec/database/mongodb_spec.rb +298 -119
  121. data/spec/database/mysql_spec.rb +147 -72
  122. data/spec/database/postgresql_spec.rb +155 -100
  123. data/spec/database/redis_spec.rb +200 -97
  124. data/spec/database/riak_spec.rb +82 -24
  125. data/spec/dependency_spec.rb +49 -0
  126. data/spec/encryptor/base_spec.rb +30 -0
  127. data/spec/encryptor/gpg_spec.rb +105 -28
  128. data/spec/encryptor/open_ssl_spec.rb +85 -114
  129. data/spec/logger_spec.rb +74 -8
  130. data/spec/model_spec.rb +528 -220
  131. data/spec/notifier/base_spec.rb +89 -0
  132. data/spec/notifier/campfire_spec.rb +147 -119
  133. data/spec/notifier/hipchat_spec.rb +140 -145
  134. data/spec/notifier/mail_spec.rb +190 -248
  135. data/spec/notifier/presently_spec.rb +147 -282
  136. data/spec/notifier/prowl_spec.rb +79 -111
  137. data/spec/notifier/twitter_spec.rb +87 -106
  138. data/spec/package_spec.rb +61 -0
  139. data/spec/packager_spec.rb +154 -0
  140. data/spec/spec_helper.rb +36 -13
  141. data/spec/splitter_spec.rb +90 -41
  142. data/spec/storage/base_spec.rb +95 -239
  143. data/spec/storage/cloudfiles_spec.rb +185 -75
  144. data/spec/storage/cycler_spec.rb +239 -0
  145. data/spec/storage/dropbox_spec.rb +318 -87
  146. data/spec/storage/ftp_spec.rb +165 -152
  147. data/spec/storage/local_spec.rb +206 -54
  148. data/spec/storage/ninefold_spec.rb +264 -128
  149. data/spec/storage/rsync_spec.rb +244 -163
  150. data/spec/storage/s3_spec.rb +175 -64
  151. data/spec/storage/scp_spec.rb +156 -150
  152. data/spec/storage/sftp_spec.rb +153 -135
  153. data/spec/syncer/base_spec.rb +22 -0
  154. data/spec/syncer/rsync/base_spec.rb +118 -0
  155. data/spec/syncer/rsync/local_spec.rb +121 -0
  156. data/spec/syncer/rsync/pull_spec.rb +90 -0
  157. data/spec/syncer/rsync/push_spec.rb +327 -0
  158. data/spec/syncer/s3_spec.rb +180 -91
  159. data/templates/cli/utility/config +1 -1
  160. data/templates/cli/utility/database/mongodb +4 -0
  161. data/templates/cli/utility/database/mysql +3 -0
  162. data/templates/cli/utility/database/postgresql +3 -0
  163. data/templates/cli/utility/database/redis +3 -0
  164. data/templates/cli/utility/database/riak +3 -0
  165. data/templates/cli/utility/storage/dropbox +4 -1
  166. data/templates/cli/utility/syncer/rsync_local +12 -0
  167. data/templates/cli/utility/syncer/{rsync → rsync_pull} +2 -2
  168. data/templates/cli/utility/syncer/rsync_push +17 -0
  169. data/templates/storage/dropbox/authorization_url.erb +1 -1
  170. metadata +42 -17
  171. data/lib/backup/configuration/syncer/rsync.rb +0 -45
  172. data/lib/backup/finder.rb +0 -87
  173. data/lib/backup/storage/object.rb +0 -47
  174. data/lib/backup/syncer/rsync.rb +0 -152
  175. data/spec/backup_spec.rb +0 -11
  176. data/spec/finder_spec.rb +0 -91
  177. data/spec/storage/object_spec.rb +0 -74
  178. data/spec/syncer/rsync_spec.rb +0 -195
@@ -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 = 'mydatabase'
14
- db.path = '/var/lib/redis/db/'
15
- db.password = 'secret'
16
- db.host = 'localhost'
17
- db.port = 123
18
- db.socket = '/redis.sock'
19
- db.invoke_save = true
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 '#new' do
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
- it 'arrays should default to empty arrays when not specified' do
38
- db = Backup::Database::Redis.new do |db|
39
- db.name = 'mydatabase'
40
- db.password = 'secret'
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
- db.additional_options.should == ""
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
- describe '#credential_options' do
48
- it 'should return the redis-cli syntax for the credential options' do
49
- db.credential_options.should == "-a 'secret'"
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 '#connectivity_options' do
54
- it 'should return the redis syntax for the connectivity options' do
55
- db.connectivity_options.should == "-h 'localhost' -p '123' -s '/redis.sock'"
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
- it 'should return only the port' do
59
- db = Backup::Database::Redis.new do |db|
60
- db.host = nil
61
- db.port = 123
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
- db.connectivity_options.should == "-p '123'"
114
+ db.perform!
115
+ end
65
116
  end
66
- end
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
- it 'should return the full redis-cli string' do
71
- db.expects(:utility).with('redis-cli').returns('redis-cli')
72
- db.expects(:run).with("redis-cli -a 'secret' -h 'localhost' " +
73
- "-p '123' -s '/redis.sock' --query SAVE")
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
- it 'should raise and error if response is not OK' do
79
- db.stubs(:utility)
80
- db.stubs(:run).returns('BAD')
81
- expect { db.invoke_save! }.to raise_error do |err|
82
- err.should be_an_instance_of Backup::Errors::Database::Redis::CommandError
83
- err.message.should match(/Could not invoke the Redis SAVE command/)
84
- err.message.should match(/The #{db.database} file/)
85
- err.message.should match(/Redis CLI response: BAD/)
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
- it do
93
- File.expects(:exist?).returns(true)
94
- db.stubs(:utility).returns('cp')
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
- it 'should find the cp utility when utility_path is set' do
102
- File.expects(:exist?).returns(true)
103
- db.utility_path = '/usr/local/bin/redis-cli'
104
- db.expects(:run).with { |v| v =~ %r{^/bin/cp .+} }
105
- db.expects(:mkdir).with(File.join(Backup::TMP_PATH, "myapp", "Redis"))
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
- it 'should raise an error if the database dump file is not found' do
111
- File.expects(:exist?).returns(false)
112
- expect { db.copy! }.to raise_error do |err|
113
- err.should be_an_instance_of Backup::Errors::Database::Redis::NotFoundError
114
- err.message.should match(/Redis database dump not found/)
115
- err.message.should match(/File path was #{File.join(db.path, db.database)}/)
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
- describe '#perform!' do
121
- before do
122
- File.stubs(:exist?).returns(true)
123
- db.stubs(:utility).returns('redis-cli')
124
- db.stubs(:mkdir)
125
- db.stubs(:run)
126
- db.stubs(:raise)
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
- it 'should ensure the directory is available' do
130
- db.expects(:mkdir).with(File.join(Backup::TMP_PATH, "myapp", "Redis"))
131
- db.perform!
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
- it 'should copy over without persisting (saving) first' do
135
- db.invoke_save = nil
136
- db.expects(:invoke_save!).never
137
- db.expects(:copy!)
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
- db.perform!
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
- it 'should copy over after persisting (saving) the most recent updates' do
143
- db.invoke_save = true
144
- db.expects(:invoke_save!)
145
- db.expects(:copy!)
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
- db.perform!
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
- it do
151
- Backup::Logger.expects(:message).
152
- with("Backup::Database::Redis started dumping and archiving 'mydatabase'.")
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
- db.perform!
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
@@ -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 = 'mydatabase'
14
- db.node = 'riak@localhost'
15
- db.cookie = 'riak'
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 '#new' do
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
- describe '#riakadmin_string' do
28
- it 'should return the full riakadmin string' do
29
- db.riakadmin.should == "riak-admin backup riak@localhost riak"
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
- end
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
- db.stubs(:mkdir)
36
- db.stubs(:run)
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
- it 'should ensure the directory is available' do
40
- db.expects(:mkdir).with(File.join(Backup::TMP_PATH, "myapp", "Riak"))
41
- db.perform!
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
- it do
45
- Backup::Logger.expects(:message).
46
- with("Backup::Database::Riak started dumping and archiving 'mydatabase'.")
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