backup 3.0.19 → 3.0.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +4 -0
- data/Gemfile +9 -8
- data/Gemfile.lock +19 -1
- data/Guardfile +13 -9
- data/README.md +93 -31
- data/backup.gemspec +3 -3
- data/bin/backup +6 -283
- data/lib/backup.rb +101 -72
- data/lib/backup/archive.rb +21 -9
- data/lib/backup/binder.rb +22 -0
- data/lib/backup/cleaner.rb +36 -0
- data/lib/backup/cli/helpers.rb +103 -0
- data/lib/backup/cli/utility.rb +308 -0
- data/lib/backup/compressor/base.rb +2 -2
- data/lib/backup/compressor/pbzip2.rb +76 -0
- data/lib/backup/configuration/compressor/pbzip2.rb +28 -0
- data/lib/backup/configuration/database/riak.rb +25 -0
- data/lib/backup/configuration/encryptor/open_ssl.rb +6 -0
- data/lib/backup/configuration/helpers.rb +5 -18
- data/lib/backup/configuration/notifier/base.rb +13 -0
- data/lib/backup/configuration/notifier/hipchat.rb +41 -0
- data/lib/backup/configuration/notifier/mail.rb +38 -0
- data/lib/backup/configuration/notifier/prowl.rb +23 -0
- data/lib/backup/configuration/storage/cloudfiles.rb +4 -0
- data/lib/backup/configuration/storage/dropbox.rb +8 -4
- data/lib/backup/database/base.rb +10 -2
- data/lib/backup/database/mongodb.rb +16 -19
- data/lib/backup/database/mysql.rb +2 -2
- data/lib/backup/database/postgresql.rb +2 -2
- data/lib/backup/database/redis.rb +15 -7
- data/lib/backup/database/riak.rb +45 -0
- data/lib/backup/dependency.rb +21 -7
- data/lib/backup/encryptor/base.rb +1 -1
- data/lib/backup/encryptor/open_ssl.rb +20 -5
- data/lib/backup/errors.rb +124 -0
- data/lib/backup/finder.rb +11 -3
- data/lib/backup/logger.rb +121 -82
- data/lib/backup/model.rb +103 -44
- data/lib/backup/notifier/base.rb +50 -0
- data/lib/backup/notifier/campfire.rb +32 -52
- data/lib/backup/notifier/hipchat.rb +99 -0
- data/lib/backup/notifier/mail.rb +100 -61
- data/lib/backup/notifier/presently.rb +31 -40
- data/lib/backup/notifier/prowl.rb +73 -0
- data/lib/backup/notifier/twitter.rb +29 -39
- data/lib/backup/packager.rb +25 -0
- data/lib/backup/splitter.rb +62 -0
- data/lib/backup/storage/base.rb +178 -18
- data/lib/backup/storage/cloudfiles.rb +34 -28
- data/lib/backup/storage/dropbox.rb +64 -67
- data/lib/backup/storage/ftp.rb +48 -40
- data/lib/backup/storage/local.rb +33 -28
- data/lib/backup/storage/ninefold.rb +40 -26
- data/lib/backup/storage/object.rb +8 -6
- data/lib/backup/storage/rsync.rb +61 -51
- data/lib/backup/storage/s3.rb +29 -27
- data/lib/backup/storage/scp.rb +56 -36
- data/lib/backup/storage/sftp.rb +49 -33
- data/lib/backup/syncer/base.rb +1 -1
- data/lib/backup/syncer/rsync.rb +1 -1
- data/lib/backup/template.rb +46 -0
- data/lib/backup/version.rb +1 -1
- data/spec/archive_spec.rb +34 -9
- data/spec/backup_spec.rb +1 -1
- data/spec/cli/helpers_spec.rb +35 -0
- data/spec/cli/utility_spec.rb +38 -0
- data/spec/compressor/bzip2_spec.rb +1 -1
- data/spec/compressor/gzip_spec.rb +1 -1
- data/spec/compressor/lzma_spec.rb +1 -1
- data/spec/compressor/pbzip2_spec.rb +63 -0
- data/spec/configuration/base_spec.rb +1 -1
- data/spec/configuration/compressor/bzip2_spec.rb +1 -1
- data/spec/configuration/compressor/gzip_spec.rb +1 -1
- data/spec/configuration/compressor/lzma_spec.rb +1 -1
- data/spec/configuration/database/base_spec.rb +1 -1
- data/spec/configuration/database/mongodb_spec.rb +1 -1
- data/spec/configuration/database/mysql_spec.rb +1 -1
- data/spec/configuration/database/postgresql_spec.rb +1 -1
- data/spec/configuration/database/redis_spec.rb +1 -1
- data/spec/configuration/database/riak_spec.rb +31 -0
- data/spec/configuration/encryptor/gpg_spec.rb +1 -1
- data/spec/configuration/encryptor/open_ssl_spec.rb +4 -1
- data/spec/configuration/notifier/campfire_spec.rb +1 -1
- data/spec/configuration/notifier/hipchat_spec.rb +43 -0
- data/spec/configuration/notifier/mail_spec.rb +34 -22
- data/spec/configuration/notifier/presently_spec.rb +1 -1
- data/spec/configuration/notifier/prowl_spec.rb +28 -0
- data/spec/configuration/notifier/twitter_spec.rb +1 -1
- data/spec/configuration/storage/cloudfiles_spec.rb +19 -16
- data/spec/configuration/storage/dropbox_spec.rb +1 -1
- data/spec/configuration/storage/ftp_spec.rb +1 -1
- data/spec/configuration/storage/local_spec.rb +1 -1
- data/spec/configuration/storage/ninefold_spec.rb +1 -1
- data/spec/configuration/storage/rsync_spec.rb +1 -1
- data/spec/configuration/storage/s3_spec.rb +1 -1
- data/spec/configuration/storage/scp_spec.rb +1 -1
- data/spec/configuration/storage/sftp_spec.rb +1 -1
- data/spec/configuration/syncer/rsync_spec.rb +1 -1
- data/spec/configuration/syncer/s3_spec.rb +1 -1
- data/spec/database/base_spec.rb +10 -1
- data/spec/database/mongodb_spec.rb +34 -7
- data/spec/database/mysql_spec.rb +8 -7
- data/spec/database/postgresql_spec.rb +8 -7
- data/spec/database/redis_spec.rb +39 -9
- data/spec/database/riak_spec.rb +50 -0
- data/spec/encryptor/gpg_spec.rb +1 -1
- data/spec/encryptor/open_ssl_spec.rb +77 -20
- data/spec/errors_spec.rb +306 -0
- data/spec/finder_spec.rb +91 -0
- data/spec/logger_spec.rb +254 -33
- data/spec/model_spec.rb +120 -15
- data/spec/notifier/campfire_spec.rb +127 -52
- data/spec/notifier/hipchat_spec.rb +193 -0
- data/spec/notifier/mail_spec.rb +290 -74
- data/spec/notifier/presently_spec.rb +290 -73
- data/spec/notifier/prowl_spec.rb +149 -0
- data/spec/notifier/twitter_spec.rb +106 -41
- data/spec/spec_helper.rb +8 -2
- data/spec/splitter_spec.rb +71 -0
- data/spec/storage/base_spec.rb +280 -19
- data/spec/storage/cloudfiles_spec.rb +38 -22
- data/spec/storage/dropbox_spec.rb +17 -13
- data/spec/storage/ftp_spec.rb +145 -55
- data/spec/storage/local_spec.rb +6 -6
- data/spec/storage/ninefold_spec.rb +70 -29
- data/spec/storage/object_spec.rb +44 -44
- data/spec/storage/rsync_spec.rb +186 -63
- data/spec/storage/s3_spec.rb +23 -24
- data/spec/storage/scp_spec.rb +116 -41
- data/spec/storage/sftp_spec.rb +124 -46
- data/spec/syncer/rsync_spec.rb +3 -3
- data/spec/syncer/s3_spec.rb +1 -1
- data/spec/version_spec.rb +1 -1
- data/templates/cli/utility/archive +13 -0
- data/{lib/templates → templates/cli/utility}/compressor/bzip2 +1 -1
- data/{lib/templates → templates/cli/utility}/compressor/gzip +1 -1
- data/{lib/templates → templates/cli/utility}/compressor/lzma +0 -0
- data/templates/cli/utility/compressor/pbzip2 +7 -0
- data/templates/cli/utility/config +31 -0
- data/{lib/templates → templates/cli/utility}/database/mongodb +1 -1
- data/{lib/templates → templates/cli/utility}/database/mysql +1 -1
- data/{lib/templates → templates/cli/utility}/database/postgresql +1 -1
- data/{lib/templates → templates/cli/utility}/database/redis +1 -1
- data/templates/cli/utility/database/riak +8 -0
- data/{lib/templates → templates/cli/utility}/encryptor/gpg +1 -1
- data/templates/cli/utility/encryptor/openssl +9 -0
- data/templates/cli/utility/model.erb +23 -0
- data/{lib/templates → templates/cli/utility}/notifier/campfire +2 -1
- data/templates/cli/utility/notifier/hipchat +15 -0
- data/{lib/templates → templates/cli/utility}/notifier/mail +6 -1
- data/{lib/templates → templates/cli/utility}/notifier/presently +1 -0
- data/templates/cli/utility/notifier/prowl +11 -0
- data/{lib/templates → templates/cli/utility}/notifier/twitter +2 -1
- data/templates/cli/utility/splitter +7 -0
- data/templates/cli/utility/storage/cloudfiles +12 -0
- data/{lib/templates → templates/cli/utility}/storage/dropbox +1 -1
- data/{lib/templates → templates/cli/utility}/storage/ftp +0 -0
- data/templates/cli/utility/storage/local +7 -0
- data/{lib/templates → templates/cli/utility}/storage/ninefold +1 -1
- data/templates/cli/utility/storage/rsync +11 -0
- data/{lib/templates → templates/cli/utility}/storage/s3 +0 -2
- data/templates/cli/utility/storage/scp +11 -0
- data/templates/cli/utility/storage/sftp +11 -0
- data/{lib/templates → templates/cli/utility}/syncer/rsync +1 -1
- data/{lib/templates → templates/cli/utility}/syncer/s3 +1 -1
- data/templates/general/links +11 -0
- data/templates/general/version.erb +2 -0
- data/templates/notifier/mail/failure.erb +9 -0
- data/templates/notifier/mail/success.erb +7 -0
- data/templates/notifier/mail/warning.erb +9 -0
- data/templates/storage/dropbox/authorization_url.erb +6 -0
- data/templates/storage/dropbox/authorized.erb +4 -0
- data/templates/storage/dropbox/cache_file_written.erb +10 -0
- metadata +81 -45
- data/lib/backup/cli.rb +0 -110
- data/lib/backup/exception/command_failed.rb +0 -8
- data/lib/backup/exception/command_not_found.rb +0 -8
- data/lib/backup/notifier/binder.rb +0 -32
- data/lib/backup/notifier/templates/notify_failure.erb +0 -33
- data/lib/backup/notifier/templates/notify_success.erb +0 -16
- data/lib/templates/archive +0 -7
- data/lib/templates/encryptor/openssl +0 -8
- data/lib/templates/readme +0 -15
- data/lib/templates/storage/cloudfiles +0 -11
- data/lib/templates/storage/local +0 -7
- data/lib/templates/storage/rsync +0 -11
- data/lib/templates/storage/scp +0 -11
- data/lib/templates/storage/sftp +0 -11
|
@@ -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,25 +1,27 @@
|
|
|
1
1
|
# encoding: utf-8
|
|
2
2
|
|
|
3
|
-
require File.
|
|
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
|
|
9
|
-
cf.api_key
|
|
10
|
-
cf.container
|
|
11
|
-
cf.path
|
|
12
|
-
cf.auth_url
|
|
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
|
|
19
|
-
cf.api_key.should
|
|
20
|
-
cf.container.should
|
|
21
|
-
cf.path.should
|
|
22
|
-
cf.auth_url.should
|
|
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
|
|
31
|
-
cf.api_key.should
|
|
32
|
-
cf.container.should
|
|
33
|
-
cf.path.should
|
|
34
|
-
cf.auth_url.should
|
|
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
|
data/spec/database/base_spec.rb
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# encoding: utf-8
|
|
2
2
|
|
|
3
|
-
require File.
|
|
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.
|
|
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).
|
|
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
|
data/spec/database/mysql_spec.rb
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# encoding: utf-8
|
|
2
2
|
|
|
3
|
-
require File.
|
|
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).
|
|
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.
|
|
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).
|
|
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
|
data/spec/database/redis_spec.rb
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# encoding: utf-8
|
|
2
2
|
|
|
3
|
-
require File.
|
|
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'
|
|
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
|
-
|
|
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).
|
|
151
|
+
Backup::Logger.expects(:message).
|
|
152
|
+
with("Backup::Database::Redis started dumping and archiving 'mydatabase'.")
|
|
123
153
|
|
|
124
154
|
db.perform!
|
|
125
155
|
end
|