backup 3.0.19 → 3.0.20

Sign up to get free protection for your applications and to get access to all the features.
Files changed (188) hide show
  1. data/.gitignore +4 -0
  2. data/Gemfile +9 -8
  3. data/Gemfile.lock +19 -1
  4. data/Guardfile +13 -9
  5. data/README.md +93 -31
  6. data/backup.gemspec +3 -3
  7. data/bin/backup +6 -283
  8. data/lib/backup.rb +101 -72
  9. data/lib/backup/archive.rb +21 -9
  10. data/lib/backup/binder.rb +22 -0
  11. data/lib/backup/cleaner.rb +36 -0
  12. data/lib/backup/cli/helpers.rb +103 -0
  13. data/lib/backup/cli/utility.rb +308 -0
  14. data/lib/backup/compressor/base.rb +2 -2
  15. data/lib/backup/compressor/pbzip2.rb +76 -0
  16. data/lib/backup/configuration/compressor/pbzip2.rb +28 -0
  17. data/lib/backup/configuration/database/riak.rb +25 -0
  18. data/lib/backup/configuration/encryptor/open_ssl.rb +6 -0
  19. data/lib/backup/configuration/helpers.rb +5 -18
  20. data/lib/backup/configuration/notifier/base.rb +13 -0
  21. data/lib/backup/configuration/notifier/hipchat.rb +41 -0
  22. data/lib/backup/configuration/notifier/mail.rb +38 -0
  23. data/lib/backup/configuration/notifier/prowl.rb +23 -0
  24. data/lib/backup/configuration/storage/cloudfiles.rb +4 -0
  25. data/lib/backup/configuration/storage/dropbox.rb +8 -4
  26. data/lib/backup/database/base.rb +10 -2
  27. data/lib/backup/database/mongodb.rb +16 -19
  28. data/lib/backup/database/mysql.rb +2 -2
  29. data/lib/backup/database/postgresql.rb +2 -2
  30. data/lib/backup/database/redis.rb +15 -7
  31. data/lib/backup/database/riak.rb +45 -0
  32. data/lib/backup/dependency.rb +21 -7
  33. data/lib/backup/encryptor/base.rb +1 -1
  34. data/lib/backup/encryptor/open_ssl.rb +20 -5
  35. data/lib/backup/errors.rb +124 -0
  36. data/lib/backup/finder.rb +11 -3
  37. data/lib/backup/logger.rb +121 -82
  38. data/lib/backup/model.rb +103 -44
  39. data/lib/backup/notifier/base.rb +50 -0
  40. data/lib/backup/notifier/campfire.rb +32 -52
  41. data/lib/backup/notifier/hipchat.rb +99 -0
  42. data/lib/backup/notifier/mail.rb +100 -61
  43. data/lib/backup/notifier/presently.rb +31 -40
  44. data/lib/backup/notifier/prowl.rb +73 -0
  45. data/lib/backup/notifier/twitter.rb +29 -39
  46. data/lib/backup/packager.rb +25 -0
  47. data/lib/backup/splitter.rb +62 -0
  48. data/lib/backup/storage/base.rb +178 -18
  49. data/lib/backup/storage/cloudfiles.rb +34 -28
  50. data/lib/backup/storage/dropbox.rb +64 -67
  51. data/lib/backup/storage/ftp.rb +48 -40
  52. data/lib/backup/storage/local.rb +33 -28
  53. data/lib/backup/storage/ninefold.rb +40 -26
  54. data/lib/backup/storage/object.rb +8 -6
  55. data/lib/backup/storage/rsync.rb +61 -51
  56. data/lib/backup/storage/s3.rb +29 -27
  57. data/lib/backup/storage/scp.rb +56 -36
  58. data/lib/backup/storage/sftp.rb +49 -33
  59. data/lib/backup/syncer/base.rb +1 -1
  60. data/lib/backup/syncer/rsync.rb +1 -1
  61. data/lib/backup/template.rb +46 -0
  62. data/lib/backup/version.rb +1 -1
  63. data/spec/archive_spec.rb +34 -9
  64. data/spec/backup_spec.rb +1 -1
  65. data/spec/cli/helpers_spec.rb +35 -0
  66. data/spec/cli/utility_spec.rb +38 -0
  67. data/spec/compressor/bzip2_spec.rb +1 -1
  68. data/spec/compressor/gzip_spec.rb +1 -1
  69. data/spec/compressor/lzma_spec.rb +1 -1
  70. data/spec/compressor/pbzip2_spec.rb +63 -0
  71. data/spec/configuration/base_spec.rb +1 -1
  72. data/spec/configuration/compressor/bzip2_spec.rb +1 -1
  73. data/spec/configuration/compressor/gzip_spec.rb +1 -1
  74. data/spec/configuration/compressor/lzma_spec.rb +1 -1
  75. data/spec/configuration/database/base_spec.rb +1 -1
  76. data/spec/configuration/database/mongodb_spec.rb +1 -1
  77. data/spec/configuration/database/mysql_spec.rb +1 -1
  78. data/spec/configuration/database/postgresql_spec.rb +1 -1
  79. data/spec/configuration/database/redis_spec.rb +1 -1
  80. data/spec/configuration/database/riak_spec.rb +31 -0
  81. data/spec/configuration/encryptor/gpg_spec.rb +1 -1
  82. data/spec/configuration/encryptor/open_ssl_spec.rb +4 -1
  83. data/spec/configuration/notifier/campfire_spec.rb +1 -1
  84. data/spec/configuration/notifier/hipchat_spec.rb +43 -0
  85. data/spec/configuration/notifier/mail_spec.rb +34 -22
  86. data/spec/configuration/notifier/presently_spec.rb +1 -1
  87. data/spec/configuration/notifier/prowl_spec.rb +28 -0
  88. data/spec/configuration/notifier/twitter_spec.rb +1 -1
  89. data/spec/configuration/storage/cloudfiles_spec.rb +19 -16
  90. data/spec/configuration/storage/dropbox_spec.rb +1 -1
  91. data/spec/configuration/storage/ftp_spec.rb +1 -1
  92. data/spec/configuration/storage/local_spec.rb +1 -1
  93. data/spec/configuration/storage/ninefold_spec.rb +1 -1
  94. data/spec/configuration/storage/rsync_spec.rb +1 -1
  95. data/spec/configuration/storage/s3_spec.rb +1 -1
  96. data/spec/configuration/storage/scp_spec.rb +1 -1
  97. data/spec/configuration/storage/sftp_spec.rb +1 -1
  98. data/spec/configuration/syncer/rsync_spec.rb +1 -1
  99. data/spec/configuration/syncer/s3_spec.rb +1 -1
  100. data/spec/database/base_spec.rb +10 -1
  101. data/spec/database/mongodb_spec.rb +34 -7
  102. data/spec/database/mysql_spec.rb +8 -7
  103. data/spec/database/postgresql_spec.rb +8 -7
  104. data/spec/database/redis_spec.rb +39 -9
  105. data/spec/database/riak_spec.rb +50 -0
  106. data/spec/encryptor/gpg_spec.rb +1 -1
  107. data/spec/encryptor/open_ssl_spec.rb +77 -20
  108. data/spec/errors_spec.rb +306 -0
  109. data/spec/finder_spec.rb +91 -0
  110. data/spec/logger_spec.rb +254 -33
  111. data/spec/model_spec.rb +120 -15
  112. data/spec/notifier/campfire_spec.rb +127 -52
  113. data/spec/notifier/hipchat_spec.rb +193 -0
  114. data/spec/notifier/mail_spec.rb +290 -74
  115. data/spec/notifier/presently_spec.rb +290 -73
  116. data/spec/notifier/prowl_spec.rb +149 -0
  117. data/spec/notifier/twitter_spec.rb +106 -41
  118. data/spec/spec_helper.rb +8 -2
  119. data/spec/splitter_spec.rb +71 -0
  120. data/spec/storage/base_spec.rb +280 -19
  121. data/spec/storage/cloudfiles_spec.rb +38 -22
  122. data/spec/storage/dropbox_spec.rb +17 -13
  123. data/spec/storage/ftp_spec.rb +145 -55
  124. data/spec/storage/local_spec.rb +6 -6
  125. data/spec/storage/ninefold_spec.rb +70 -29
  126. data/spec/storage/object_spec.rb +44 -44
  127. data/spec/storage/rsync_spec.rb +186 -63
  128. data/spec/storage/s3_spec.rb +23 -24
  129. data/spec/storage/scp_spec.rb +116 -41
  130. data/spec/storage/sftp_spec.rb +124 -46
  131. data/spec/syncer/rsync_spec.rb +3 -3
  132. data/spec/syncer/s3_spec.rb +1 -1
  133. data/spec/version_spec.rb +1 -1
  134. data/templates/cli/utility/archive +13 -0
  135. data/{lib/templates → templates/cli/utility}/compressor/bzip2 +1 -1
  136. data/{lib/templates → templates/cli/utility}/compressor/gzip +1 -1
  137. data/{lib/templates → templates/cli/utility}/compressor/lzma +0 -0
  138. data/templates/cli/utility/compressor/pbzip2 +7 -0
  139. data/templates/cli/utility/config +31 -0
  140. data/{lib/templates → templates/cli/utility}/database/mongodb +1 -1
  141. data/{lib/templates → templates/cli/utility}/database/mysql +1 -1
  142. data/{lib/templates → templates/cli/utility}/database/postgresql +1 -1
  143. data/{lib/templates → templates/cli/utility}/database/redis +1 -1
  144. data/templates/cli/utility/database/riak +8 -0
  145. data/{lib/templates → templates/cli/utility}/encryptor/gpg +1 -1
  146. data/templates/cli/utility/encryptor/openssl +9 -0
  147. data/templates/cli/utility/model.erb +23 -0
  148. data/{lib/templates → templates/cli/utility}/notifier/campfire +2 -1
  149. data/templates/cli/utility/notifier/hipchat +15 -0
  150. data/{lib/templates → templates/cli/utility}/notifier/mail +6 -1
  151. data/{lib/templates → templates/cli/utility}/notifier/presently +1 -0
  152. data/templates/cli/utility/notifier/prowl +11 -0
  153. data/{lib/templates → templates/cli/utility}/notifier/twitter +2 -1
  154. data/templates/cli/utility/splitter +7 -0
  155. data/templates/cli/utility/storage/cloudfiles +12 -0
  156. data/{lib/templates → templates/cli/utility}/storage/dropbox +1 -1
  157. data/{lib/templates → templates/cli/utility}/storage/ftp +0 -0
  158. data/templates/cli/utility/storage/local +7 -0
  159. data/{lib/templates → templates/cli/utility}/storage/ninefold +1 -1
  160. data/templates/cli/utility/storage/rsync +11 -0
  161. data/{lib/templates → templates/cli/utility}/storage/s3 +0 -2
  162. data/templates/cli/utility/storage/scp +11 -0
  163. data/templates/cli/utility/storage/sftp +11 -0
  164. data/{lib/templates → templates/cli/utility}/syncer/rsync +1 -1
  165. data/{lib/templates → templates/cli/utility}/syncer/s3 +1 -1
  166. data/templates/general/links +11 -0
  167. data/templates/general/version.erb +2 -0
  168. data/templates/notifier/mail/failure.erb +9 -0
  169. data/templates/notifier/mail/success.erb +7 -0
  170. data/templates/notifier/mail/warning.erb +9 -0
  171. data/templates/storage/dropbox/authorization_url.erb +6 -0
  172. data/templates/storage/dropbox/authorized.erb +4 -0
  173. data/templates/storage/dropbox/cache_file_written.erb +10 -0
  174. metadata +81 -45
  175. data/lib/backup/cli.rb +0 -110
  176. data/lib/backup/exception/command_failed.rb +0 -8
  177. data/lib/backup/exception/command_not_found.rb +0 -8
  178. data/lib/backup/notifier/binder.rb +0 -32
  179. data/lib/backup/notifier/templates/notify_failure.erb +0 -33
  180. data/lib/backup/notifier/templates/notify_success.erb +0 -16
  181. data/lib/templates/archive +0 -7
  182. data/lib/templates/encryptor/openssl +0 -8
  183. data/lib/templates/readme +0 -15
  184. data/lib/templates/storage/cloudfiles +0 -11
  185. data/lib/templates/storage/local +0 -7
  186. data/lib/templates/storage/rsync +0 -11
  187. data/lib/templates/storage/scp +0 -11
  188. data/lib/templates/storage/sftp +0 -11
@@ -1,6 +1,6 @@
1
1
  # encoding: utf-8
2
2
 
3
- require File.dirname(__FILE__) + '/../../spec_helper'
3
+ require File.expand_path('../../../spec_helper.rb', __FILE__)
4
4
 
5
5
  describe Backup::Configuration::Notifier::Presently do
6
6
  before do
@@ -0,0 +1,28 @@
1
+ # encoding: utf-8
2
+
3
+ require File.expand_path('../../../spec_helper.rb', __FILE__)
4
+
5
+ describe Backup::Configuration::Notifier::Prowl do
6
+ before do
7
+ Backup::Configuration::Notifier::Prowl.defaults do |prowl|
8
+ prowl.application = 'my_application'
9
+ prowl.api_key = 'my_api_key'
10
+ end
11
+ end
12
+
13
+ it 'should set the default tweet configuration' do
14
+ prowl = Backup::Configuration::Notifier::Prowl
15
+ prowl.application.should == 'my_application'
16
+ prowl.api_key.should == 'my_api_key'
17
+ end
18
+
19
+ describe '#clear_defaults!' do
20
+ it 'should clear all the defaults, resetting them to nil' do
21
+ Backup::Configuration::Notifier::Prowl.clear_defaults!
22
+
23
+ prowl = Backup::Configuration::Notifier::Prowl
24
+ prowl.application.should == nil
25
+ prowl.api_key.should == nil
26
+ end
27
+ end
28
+ end
@@ -1,6 +1,6 @@
1
1
  # encoding: utf-8
2
2
 
3
- require File.dirname(__FILE__) + '/../../spec_helper'
3
+ require File.expand_path('../../../spec_helper.rb', __FILE__)
4
4
 
5
5
  describe Backup::Configuration::Notifier::Twitter do
6
6
  before do
@@ -1,25 +1,27 @@
1
1
  # encoding: utf-8
2
2
 
3
- require File.dirname(__FILE__) + '/../../spec_helper'
3
+ require File.expand_path('../../../spec_helper.rb', __FILE__)
4
4
 
5
5
  describe Backup::Configuration::Storage::CloudFiles do
6
6
  before do
7
7
  Backup::Configuration::Storage::CloudFiles.defaults do |cf|
8
- cf.username = 'my_username'
9
- cf.api_key = 'my_api_key'
10
- cf.container = 'my_container'
11
- cf.path = 'my_backups'
12
- cf.auth_url = 'lon.auth.api.rackspacecloud.com'
8
+ cf.username = 'my_username'
9
+ cf.api_key = 'my_api_key'
10
+ cf.container = 'my_container'
11
+ cf.path = 'my_backups'
12
+ cf.auth_url = 'lon.auth.api.rackspacecloud.com'
13
+ cf.servicenet = true
13
14
  end
14
15
  end
15
16
 
16
17
  it 'should set the default Cloud Files configuration' do
17
18
  cf = Backup::Configuration::Storage::CloudFiles
18
- cf.username.should == 'my_username'
19
- cf.api_key.should == 'my_api_key'
20
- cf.container.should == 'my_container'
21
- cf.path.should == 'my_backups'
22
- cf.auth_url.should == 'lon.auth.api.rackspacecloud.com'
19
+ cf.username.should == 'my_username'
20
+ cf.api_key.should == 'my_api_key'
21
+ cf.container.should == 'my_container'
22
+ cf.path.should == 'my_backups'
23
+ cf.auth_url.should == 'lon.auth.api.rackspacecloud.com'
24
+ cf.servicenet.should == true
23
25
  end
24
26
 
25
27
  describe '#clear_defaults!' do
@@ -27,11 +29,12 @@ describe Backup::Configuration::Storage::CloudFiles do
27
29
  Backup::Configuration::Storage::CloudFiles.clear_defaults!
28
30
 
29
31
  cf = Backup::Configuration::Storage::CloudFiles
30
- cf.username.should == nil
31
- cf.api_key.should == nil
32
- cf.container.should == nil
33
- cf.path.should == nil
34
- cf.auth_url.should == nil
32
+ cf.username.should == nil
33
+ cf.api_key.should == nil
34
+ cf.container.should == nil
35
+ cf.path.should == nil
36
+ cf.auth_url.should == nil
37
+ cf.servicenet.should == nil
35
38
  end
36
39
  end
37
40
  end
@@ -1,6 +1,6 @@
1
1
  # encoding: utf-8
2
2
 
3
- require File.dirname(__FILE__) + '/../../spec_helper'
3
+ require File.expand_path('../../../spec_helper.rb', __FILE__)
4
4
 
5
5
  describe Backup::Configuration::Storage::Dropbox do
6
6
  before do
@@ -1,6 +1,6 @@
1
1
  # encoding: utf-8
2
2
 
3
- require File.dirname(__FILE__) + '/../../spec_helper'
3
+ require File.expand_path('../../../spec_helper.rb', __FILE__)
4
4
 
5
5
  describe Backup::Configuration::Storage::FTP do
6
6
  before do
@@ -1,6 +1,6 @@
1
1
  # encoding: utf-8
2
2
 
3
- require File.dirname(__FILE__) + '/../../spec_helper'
3
+ require File.expand_path('../../../spec_helper.rb', __FILE__)
4
4
 
5
5
  describe Backup::Configuration::Storage::Local do
6
6
  before do
@@ -1,6 +1,6 @@
1
1
  # encoding: utf-8
2
2
 
3
- require File.dirname(__FILE__) + '/../../spec_helper'
3
+ require File.expand_path('../../../spec_helper.rb', __FILE__)
4
4
 
5
5
  describe Backup::Configuration::Storage::Ninefold do
6
6
  before do
@@ -1,6 +1,6 @@
1
1
  # encoding: utf-8
2
2
 
3
- require File.dirname(__FILE__) + '/../../spec_helper'
3
+ require File.expand_path('../../../spec_helper.rb', __FILE__)
4
4
 
5
5
  describe Backup::Configuration::Storage::RSync do
6
6
  before do
@@ -1,6 +1,6 @@
1
1
  # encoding: utf-8
2
2
 
3
- require File.dirname(__FILE__) + '/../../spec_helper'
3
+ require File.expand_path('../../../spec_helper.rb', __FILE__)
4
4
 
5
5
  describe Backup::Configuration::Storage::S3 do
6
6
  before do
@@ -1,6 +1,6 @@
1
1
  # encoding: utf-8
2
2
 
3
- require File.dirname(__FILE__) + '/../../spec_helper'
3
+ require File.expand_path('../../../spec_helper.rb', __FILE__)
4
4
 
5
5
  describe Backup::Configuration::Storage::SCP do
6
6
  before do
@@ -1,6 +1,6 @@
1
1
  # encoding: utf-8
2
2
 
3
- require File.dirname(__FILE__) + '/../../spec_helper'
3
+ require File.expand_path('../../../spec_helper.rb', __FILE__)
4
4
 
5
5
  describe Backup::Configuration::Storage::SFTP do
6
6
  before do
@@ -1,6 +1,6 @@
1
1
  # encoding: utf-8
2
2
 
3
- require File.dirname(__FILE__) + '/../../spec_helper'
3
+ require File.expand_path('../../../spec_helper.rb', __FILE__)
4
4
 
5
5
  describe Backup::Configuration::Syncer::RSync do
6
6
  before do
@@ -1,6 +1,6 @@
1
1
  # encoding: utf-8
2
2
 
3
- require File.dirname(__FILE__) + '/../../spec_helper'
3
+ require File.expand_path('../../../spec_helper.rb', __FILE__)
4
4
 
5
5
  describe Backup::Configuration::Syncer::S3 do
6
6
  before do
@@ -1,6 +1,6 @@
1
1
  # encoding: utf-8
2
2
 
3
- require File.dirname(__FILE__) + '/../spec_helper'
3
+ require File.expand_path('../../spec_helper.rb', __FILE__)
4
4
 
5
5
  describe Backup::Database::Base do
6
6
 
@@ -27,4 +27,13 @@ describe Backup::Database::Base do
27
27
  db.utility(:my_database_util).should == :my_database_util
28
28
  end
29
29
 
30
+ describe '#perform!' do
31
+ it 'should invoke prepare! and log!' do
32
+ db.expects(:prepare!)
33
+ db.expects(:log!)
34
+
35
+ db.perform!
36
+ end
37
+ end
38
+
30
39
  end
@@ -1,6 +1,6 @@
1
1
  # encoding: utf-8
2
2
 
3
- require File.dirname(__FILE__) + '/../spec_helper'
3
+ require File.expand_path('../../spec_helper.rb', __FILE__)
4
4
 
5
5
  describe Backup::Database::MongoDB do
6
6
 
@@ -44,11 +44,6 @@ describe Backup::Database::MongoDB do
44
44
  db.only_collections.should == []
45
45
  db.additional_options.should == ""
46
46
  end
47
-
48
- it 'should ensure the directory is available' do
49
- Backup::Database::MongoDB.any_instance.expects(:mkdir).with("#{Backup::TMP_PATH}/myapp/MongoDB")
50
- Backup::Database::MongoDB.new {}
51
- end
52
47
  end
53
48
 
54
49
  describe '#only_collections' do
@@ -101,6 +96,7 @@ describe Backup::Database::MongoDB do
101
96
  describe '#mongodump_string' do
102
97
  it 'should return the full mongodump string' do
103
98
  db.expects(:utility).with(:mongodump).returns('mongodump')
99
+ db.prepare!
104
100
  db.mongodump.should ==
105
101
  "mongodump --db='mydatabase' --username='someuser' --password='secret' " +
106
102
  "--host='localhost' --port='123' --ipv6 --query --out='#{ File.join(Backup::TMP_PATH, Backup::TRIGGER, 'MongoDB') }'"
@@ -114,6 +110,11 @@ describe Backup::Database::MongoDB do
114
110
  db.stubs(:run)
115
111
  end
116
112
 
113
+ it 'should ensure the directory is available' do
114
+ db.expects(:mkdir).with(File.join(Backup::TMP_PATH, "myapp", "MongoDB"))
115
+ db.perform!
116
+ end
117
+
117
118
  it 'should run the mongodump command and dump all collections' do
118
119
  db.only_collections = []
119
120
  db.expects(:dump!)
@@ -173,8 +174,34 @@ describe Backup::Database::MongoDB do
173
174
  end
174
175
 
175
176
  it do
176
- Backup::Logger.expects(:message).with("Backup::Database::MongoDB started dumping and archiving \"mydatabase\".")
177
+ Backup::Logger.expects(:message).
178
+ with("Backup::Database::MongoDB started dumping and archiving 'mydatabase'.")
177
179
  db.perform!
178
180
  end
179
181
  end
182
+
183
+ describe "#mongo_uri" do
184
+ before do
185
+ db.host = "flame.mongohq.com"
186
+ db.port = 12345
187
+ db.username = "sample_username"
188
+ db.password = "sample_password"
189
+ db.ipv6 = nil
190
+ end
191
+
192
+ it "should return URI without database" do
193
+ db.name = nil
194
+ db.mongo_uri.should == "flame.mongohq.com:12345 --username='sample_username' --password='sample_password'"
195
+ end
196
+
197
+ it "should return URI without database" do
198
+ db.name = ""
199
+ db.mongo_uri.should == "flame.mongohq.com:12345 --username='sample_username' --password='sample_password'"
200
+ end
201
+
202
+ it "should return URI without database" do
203
+ db.name = "sample_db"
204
+ db.mongo_uri.should == "flame.mongohq.com:12345/sample_db --username='sample_username' --password='sample_password'"
205
+ end
206
+ end
180
207
  end
@@ -1,6 +1,6 @@
1
1
  # encoding: utf-8
2
2
 
3
- require File.dirname(__FILE__) + '/../spec_helper'
3
+ require File.expand_path('../../spec_helper.rb', __FILE__)
4
4
 
5
5
  describe Backup::Database::MySQL do
6
6
 
@@ -48,11 +48,6 @@ describe Backup::Database::MySQL do
48
48
  db.only_tables.should == []
49
49
  db.additional_options.should == []
50
50
  end
51
-
52
- it 'should ensure the directory is available' do
53
- Backup::Database::MySQL.any_instance.expects(:mkdir).with("#{Backup::TMP_PATH}/myapp/MySQL")
54
- Backup::Database::MySQL.new {}
55
- end
56
51
  end
57
52
 
58
53
  describe '#skip_tables' do
@@ -136,13 +131,19 @@ describe Backup::Database::MySQL do
136
131
  db.stubs(:run)
137
132
  end
138
133
 
134
+ it 'should ensure the directory is available' do
135
+ db.expects(:mkdir).with(File.join(Backup::TMP_PATH, "myapp", "MySQL"))
136
+ db.perform!
137
+ end
138
+
139
139
  it 'should run the mysqldump command and dump it to the specified path' do
140
140
  db.expects(:run).with("#{db.mysqldump} > '#{Backup::TMP_PATH}/myapp/MySQL/mydatabase.sql'")
141
141
  db.perform!
142
142
  end
143
143
 
144
144
  it do
145
- Backup::Logger.expects(:message).with("Backup::Database::MySQL started dumping and archiving \"mydatabase\".")
145
+ Backup::Logger.expects(:message).
146
+ with("Backup::Database::MySQL started dumping and archiving 'mydatabase'.")
146
147
  db.perform!
147
148
  end
148
149
  end
@@ -1,6 +1,6 @@
1
1
  # encoding: utf-8
2
2
 
3
- require File.dirname(__FILE__) + '/../spec_helper'
3
+ require File.expand_path('../../spec_helper.rb', __FILE__)
4
4
 
5
5
  describe Backup::Database::PostgreSQL do
6
6
 
@@ -64,11 +64,6 @@ describe Backup::Database::PostgreSQL do
64
64
  db.username_options.should == ''
65
65
  db.password_options.should == ''
66
66
  end
67
-
68
- it 'should ensure the directory is available' do
69
- Backup::Database::PostgreSQL.any_instance.expects(:mkdir).with("#{Backup::TMP_PATH}/myapp/PostgreSQL")
70
- Backup::Database::PostgreSQL.new {}
71
- end
72
67
  end
73
68
 
74
69
  describe '#skip_tables' do
@@ -171,13 +166,19 @@ describe Backup::Database::PostgreSQL do
171
166
  db.stubs(:run)
172
167
  end
173
168
 
169
+ it 'should ensure the directory is available' do
170
+ db.expects(:mkdir).with(File.join(Backup::TMP_PATH, "myapp", "PostgreSQL"))
171
+ db.perform!
172
+ end
173
+
174
174
  it 'should run the pg_dump command and dump it to the specified path' do
175
175
  db.expects(:run).with("#{db.pgdump} > '#{Backup::TMP_PATH}/myapp/PostgreSQL/mydatabase.sql'")
176
176
  db.perform!
177
177
  end
178
178
 
179
179
  it do
180
- Backup::Logger.expects(:message).with("Backup::Database::PostgreSQL started dumping and archiving \"mydatabase\".")
180
+ Backup::Logger.expects(:message).
181
+ with("Backup::Database::PostgreSQL started dumping and archiving 'mydatabase'.")
181
182
  db.perform!
182
183
  end
183
184
  end
@@ -1,6 +1,6 @@
1
1
  # encoding: utf-8
2
2
 
3
- require File.dirname(__FILE__) + '/../spec_helper'
3
+ require File.expand_path('../../spec_helper.rb', __FILE__)
4
4
 
5
5
  describe Backup::Database::Redis do
6
6
 
@@ -42,11 +42,6 @@ describe Backup::Database::Redis do
42
42
 
43
43
  db.additional_options.should == ""
44
44
  end
45
-
46
- it 'should ensure the directory is available' do
47
- Backup::Database::Redis.any_instance.expects(:mkdir).with("#{Backup::TMP_PATH}/myapp/Redis")
48
- Backup::Database::Redis.new {}
49
- end
50
45
  end
51
46
 
52
47
  describe '#credential_options' do
@@ -71,18 +66,35 @@ describe Backup::Database::Redis do
71
66
  end
72
67
 
73
68
  describe '#invoke_save!' do
69
+
74
70
  it 'should return the full redis-cli string' do
75
71
  db.expects(:utility).with('redis-cli').returns('redis-cli')
76
- db.expects(:run).with("redis-cli -a 'secret' -h 'localhost' -p '123' -s '/redis.sock' --query SAVE")
72
+ db.expects(:run).with("redis-cli -a 'secret' -h 'localhost' " +
73
+ "-p '123' -s '/redis.sock' --query SAVE")
74
+ db.stubs(:raise)
77
75
  db.invoke_save!
78
76
  end
79
- end
77
+
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/)
86
+ end
87
+ end
88
+
89
+ end # describe '#invoke_save!'
80
90
 
81
91
  describe '#copy!' do
82
92
  it do
83
93
  File.expects(:exist?).returns(true)
84
94
  db.stubs(:utility).returns('cp')
85
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!
86
98
  db.copy!
87
99
  end
88
100
 
@@ -90,8 +102,19 @@ describe Backup::Database::Redis do
90
102
  File.expects(:exist?).returns(true)
91
103
  db.utility_path = '/usr/local/bin/redis-cli'
92
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!
93
107
  db.copy!
94
108
  end
109
+
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)}/)
116
+ end
117
+ end
95
118
  end
96
119
 
97
120
  describe '#perform!' do
@@ -100,6 +123,12 @@ describe Backup::Database::Redis do
100
123
  db.stubs(:utility).returns('redis-cli')
101
124
  db.stubs(:mkdir)
102
125
  db.stubs(:run)
126
+ db.stubs(:raise)
127
+ end
128
+
129
+ it 'should ensure the directory is available' do
130
+ db.expects(:mkdir).with(File.join(Backup::TMP_PATH, "myapp", "Redis"))
131
+ db.perform!
103
132
  end
104
133
 
105
134
  it 'should copy over without persisting (saving) first' do
@@ -119,7 +148,8 @@ describe Backup::Database::Redis do
119
148
  end
120
149
 
121
150
  it do
122
- Backup::Logger.expects(:message).with("Backup::Database::Redis started dumping and archiving \"mydatabase\".")
151
+ Backup::Logger.expects(:message).
152
+ with("Backup::Database::Redis started dumping and archiving 'mydatabase'.")
123
153
 
124
154
  db.perform!
125
155
  end