backup 3.0.27 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE.md +1 -1
- data/README.md +139 -386
- data/bin/backup +1 -7
- data/lib/backup.rb +3 -9
- data/lib/backup/archive.rb +26 -20
- data/lib/backup/cleaner.rb +2 -2
- data/lib/backup/cli.rb +366 -0
- data/lib/backup/compressor/base.rb +2 -2
- data/lib/backup/compressor/gzip.rb +35 -1
- data/lib/backup/config.rb +1 -2
- data/lib/backup/database/base.rb +2 -2
- data/lib/backup/database/mongodb.rb +3 -3
- data/lib/backup/database/mysql.rb +3 -2
- data/lib/backup/database/postgresql.rb +3 -2
- data/lib/backup/database/riak.rb +18 -5
- data/lib/backup/dependency.rb +144 -93
- data/lib/backup/encryptor/base.rb +2 -2
- data/lib/backup/logger.rb +108 -110
- data/lib/backup/logger/console.rb +51 -0
- data/lib/backup/logger/logfile.rb +113 -0
- data/lib/backup/logger/syslog.rb +116 -0
- data/lib/backup/model.rb +67 -65
- data/lib/backup/notifier/base.rb +1 -1
- data/lib/backup/notifier/hipchat.rb +1 -1
- data/lib/backup/notifier/mail.rb +1 -1
- data/lib/backup/notifier/pushover.rb +6 -3
- data/lib/backup/packager.rb +4 -4
- data/lib/backup/pipeline.rb +17 -3
- data/lib/backup/splitter.rb +2 -2
- data/lib/backup/storage/base.rb +2 -2
- data/lib/backup/storage/cloudfiles.rb +2 -2
- data/lib/backup/storage/dropbox.rb +4 -4
- data/lib/backup/storage/ftp.rb +2 -2
- data/lib/backup/storage/local.rb +2 -2
- data/lib/backup/storage/ninefold.rb +2 -2
- data/lib/backup/storage/rsync.rb +3 -3
- data/lib/backup/storage/s3.rb +2 -2
- data/lib/backup/storage/scp.rb +2 -6
- data/lib/backup/storage/sftp.rb +2 -5
- data/lib/backup/syncer/base.rb +1 -1
- data/lib/backup/syncer/cloud/base.rb +15 -8
- data/lib/backup/syncer/rsync/local.rb +1 -1
- data/lib/backup/syncer/rsync/pull.rb +1 -1
- data/lib/backup/syncer/rsync/push.rb +1 -1
- data/lib/backup/utilities.rb +211 -0
- data/lib/backup/version.rb +1 -1
- data/templates/cli/{utility/archive → archive} +4 -8
- data/templates/cli/{utility/compressor → compressor}/bzip2 +0 -0
- data/templates/cli/{utility/compressor → compressor}/custom +0 -0
- data/templates/cli/{utility/compressor → compressor}/gzip +0 -0
- data/templates/cli/{utility/compressor → compressor}/lzma +0 -0
- data/templates/cli/{utility/compressor → compressor}/pbzip2 +0 -0
- data/templates/cli/config +68 -0
- data/templates/cli/{utility/database → database}/mongodb +1 -1
- data/templates/cli/{utility/database → database}/mysql +1 -1
- data/templates/cli/{utility/database → database}/postgresql +1 -1
- data/templates/cli/{utility/database → database}/redis +0 -0
- data/templates/cli/database/riak +20 -0
- data/templates/cli/{utility/encryptor → encryptor}/gpg +0 -0
- data/templates/cli/{utility/encryptor → encryptor}/openssl +0 -0
- data/templates/cli/{utility/model.erb → model.erb} +4 -4
- data/templates/cli/{utility/notifier → notifier}/campfire +0 -0
- data/templates/cli/{utility/notifier → notifier}/hipchat +0 -0
- data/templates/cli/{utility/notifier → notifier}/mail +0 -0
- data/templates/cli/{utility/notifier → notifier}/prowl +0 -0
- data/templates/cli/{utility/notifier → notifier}/pushover +0 -0
- data/templates/cli/{utility/notifier → notifier}/twitter +0 -0
- data/templates/cli/{utility/splitter → splitter} +0 -0
- data/templates/cli/{utility/storage → storage}/cloud_files +0 -0
- data/templates/cli/{utility/storage → storage}/dropbox +0 -0
- data/templates/cli/{utility/storage → storage}/ftp +0 -0
- data/templates/cli/{utility/storage → storage}/local +0 -0
- data/templates/cli/{utility/storage → storage}/ninefold +0 -0
- data/templates/cli/{utility/storage → storage}/rsync +0 -0
- data/templates/cli/{utility/storage → storage}/s3 +0 -0
- data/templates/cli/{utility/storage → storage}/scp +0 -0
- data/templates/cli/{utility/storage → storage}/sftp +0 -0
- data/templates/cli/{utility/syncer → syncer}/cloud_files +0 -0
- data/templates/cli/{utility/syncer → syncer}/rsync_local +0 -0
- data/templates/cli/{utility/syncer → syncer}/rsync_pull +0 -0
- data/templates/cli/{utility/syncer → syncer}/rsync_push +0 -0
- data/templates/cli/{utility/syncer → syncer}/s3 +0 -0
- metadata +55 -131
- data/.gitignore +0 -8
- data/.travis.yml +0 -10
- data/Gemfile +0 -28
- data/Guardfile +0 -23
- data/backup.gemspec +0 -32
- data/lib/backup/cli/helpers.rb +0 -93
- data/lib/backup/cli/utility.rb +0 -255
- data/spec-live/.gitignore +0 -6
- data/spec-live/README +0 -7
- data/spec-live/backups/config.rb +0 -83
- data/spec-live/backups/config.yml.template +0 -46
- data/spec-live/backups/models.rb +0 -184
- data/spec-live/compressor/custom_spec.rb +0 -30
- data/spec-live/compressor/gzip_spec.rb +0 -30
- data/spec-live/encryptor/gpg_keys.rb +0 -239
- data/spec-live/encryptor/gpg_spec.rb +0 -287
- data/spec-live/notifier/mail_spec.rb +0 -121
- data/spec-live/spec_helper.rb +0 -151
- data/spec-live/storage/dropbox_spec.rb +0 -151
- data/spec-live/storage/local_spec.rb +0 -83
- data/spec-live/storage/scp_spec.rb +0 -193
- data/spec-live/syncer/cloud/s3_spec.rb +0 -124
- data/spec/archive_spec.rb +0 -335
- data/spec/cleaner_spec.rb +0 -312
- data/spec/cli/helpers_spec.rb +0 -301
- data/spec/cli/utility_spec.rb +0 -411
- data/spec/compressor/base_spec.rb +0 -52
- data/spec/compressor/bzip2_spec.rb +0 -217
- data/spec/compressor/custom_spec.rb +0 -106
- data/spec/compressor/gzip_spec.rb +0 -217
- data/spec/compressor/lzma_spec.rb +0 -123
- data/spec/compressor/pbzip2_spec.rb +0 -165
- data/spec/config_spec.rb +0 -321
- data/spec/configuration/helpers_spec.rb +0 -247
- data/spec/configuration/store_spec.rb +0 -39
- data/spec/configuration_spec.rb +0 -62
- data/spec/database/base_spec.rb +0 -63
- data/spec/database/mongodb_spec.rb +0 -510
- data/spec/database/mysql_spec.rb +0 -411
- data/spec/database/postgresql_spec.rb +0 -353
- data/spec/database/redis_spec.rb +0 -334
- data/spec/database/riak_spec.rb +0 -176
- data/spec/dependency_spec.rb +0 -51
- data/spec/encryptor/base_spec.rb +0 -40
- data/spec/encryptor/gpg_spec.rb +0 -909
- data/spec/encryptor/open_ssl_spec.rb +0 -148
- data/spec/errors_spec.rb +0 -306
- data/spec/logger_spec.rb +0 -367
- data/spec/model_spec.rb +0 -666
- data/spec/notifier/base_spec.rb +0 -104
- data/spec/notifier/campfire_spec.rb +0 -217
- data/spec/notifier/hipchat_spec.rb +0 -211
- data/spec/notifier/mail_spec.rb +0 -316
- data/spec/notifier/prowl_spec.rb +0 -138
- data/spec/notifier/pushover_spec.rb +0 -123
- data/spec/notifier/twitter_spec.rb +0 -153
- data/spec/package_spec.rb +0 -61
- data/spec/packager_spec.rb +0 -213
- data/spec/pipeline_spec.rb +0 -259
- data/spec/spec_helper.rb +0 -60
- data/spec/splitter_spec.rb +0 -120
- data/spec/storage/base_spec.rb +0 -166
- data/spec/storage/cloudfiles_spec.rb +0 -254
- data/spec/storage/cycler_spec.rb +0 -247
- data/spec/storage/dropbox_spec.rb +0 -480
- data/spec/storage/ftp_spec.rb +0 -271
- data/spec/storage/local_spec.rb +0 -259
- data/spec/storage/ninefold_spec.rb +0 -343
- data/spec/storage/rsync_spec.rb +0 -362
- data/spec/storage/s3_spec.rb +0 -245
- data/spec/storage/scp_spec.rb +0 -233
- data/spec/storage/sftp_spec.rb +0 -244
- data/spec/syncer/base_spec.rb +0 -109
- data/spec/syncer/cloud/base_spec.rb +0 -515
- data/spec/syncer/cloud/cloud_files_spec.rb +0 -181
- data/spec/syncer/cloud/s3_spec.rb +0 -174
- data/spec/syncer/rsync/base_spec.rb +0 -98
- data/spec/syncer/rsync/local_spec.rb +0 -149
- data/spec/syncer/rsync/pull_spec.rb +0 -98
- data/spec/syncer/rsync/push_spec.rb +0 -333
- data/spec/version_spec.rb +0 -21
- data/templates/cli/utility/config +0 -32
- data/templates/cli/utility/database/riak +0 -11
@@ -1,123 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require File.expand_path('../../spec_helper.rb', __FILE__)
|
4
|
-
|
5
|
-
describe Backup::Notifier::Pushover do
|
6
|
-
let(:model) { Backup::Model.new(:test_trigger, 'test label') }
|
7
|
-
let(:notifier) do
|
8
|
-
Backup::Notifier::Pushover.new(model) do |notifier|
|
9
|
-
notifier.user = 'user_token'
|
10
|
-
notifier.token = 'app_token'
|
11
|
-
notifier.title = 'title'
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'should be a subclass of Notifier::Base' do
|
16
|
-
Backup::Notifier::Pushover.
|
17
|
-
superclass.should == Backup::Notifier::Base
|
18
|
-
end
|
19
|
-
|
20
|
-
describe '#initialize' do
|
21
|
-
after { Backup::Notifier::Pushover.clear_defaults! }
|
22
|
-
|
23
|
-
it 'should load pre-configured defaults through Base' do
|
24
|
-
Backup::Notifier::Pushover.any_instance.expects(:load_defaults!)
|
25
|
-
notifier
|
26
|
-
end
|
27
|
-
|
28
|
-
it 'should pass the model reference to Base' do
|
29
|
-
notifier.instance_variable_get(:@model).should == model
|
30
|
-
end
|
31
|
-
|
32
|
-
context 'when no pre-configured defaults have been set' do
|
33
|
-
it 'should use the values given' do
|
34
|
-
notifier.user.should == 'user_token'
|
35
|
-
notifier.token.should == 'app_token'
|
36
|
-
notifier.device.should be_nil
|
37
|
-
notifier.priority.should be_nil
|
38
|
-
|
39
|
-
notifier.on_success.should == true
|
40
|
-
notifier.on_warning.should == true
|
41
|
-
notifier.on_failure.should == true
|
42
|
-
end
|
43
|
-
|
44
|
-
it 'should use default values if none are given' do
|
45
|
-
notifier = Backup::Notifier::Pushover.new(model)
|
46
|
-
notifier.token.should be_nil
|
47
|
-
notifier.user.should be_nil
|
48
|
-
notifier.device.should be_nil
|
49
|
-
notifier.priority.should be_nil
|
50
|
-
|
51
|
-
notifier.on_success.should == true
|
52
|
-
notifier.on_warning.should == true
|
53
|
-
notifier.on_failure.should == true
|
54
|
-
end
|
55
|
-
end # context 'when no pre-configured defaults have been set'
|
56
|
-
|
57
|
-
context 'when pre-configured defaults have been set' do
|
58
|
-
before do
|
59
|
-
Backup::Notifier::Pushover.defaults do |n|
|
60
|
-
n.token = 'the_token'
|
61
|
-
n.user = 'the_user'
|
62
|
-
n.on_failure = false
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
it 'should use pre-configured defaults' do
|
67
|
-
notifier = Backup::Notifier::Pushover.new(model)
|
68
|
-
|
69
|
-
notifier.token.should == 'the_token'
|
70
|
-
notifier.user.should == 'the_user'
|
71
|
-
|
72
|
-
notifier.on_success.should == true
|
73
|
-
notifier.on_warning.should == true
|
74
|
-
notifier.on_failure.should == false
|
75
|
-
end
|
76
|
-
|
77
|
-
it 'should override pre-configured defaults' do
|
78
|
-
notifier = Backup::Notifier::Pushover.new(model) do |n|
|
79
|
-
n.token = 'new_token'
|
80
|
-
n.user = 'new_user'
|
81
|
-
n.on_success = false
|
82
|
-
n.on_failure = true
|
83
|
-
end
|
84
|
-
|
85
|
-
notifier.token.should == 'new_token'
|
86
|
-
notifier.user.should == 'new_user'
|
87
|
-
|
88
|
-
notifier.on_success.should == false
|
89
|
-
notifier.on_warning.should == true
|
90
|
-
notifier.on_failure.should == true
|
91
|
-
end
|
92
|
-
end # context 'when pre-configured defaults have been set'
|
93
|
-
end # describe '#initialize'
|
94
|
-
|
95
|
-
describe '#notify!' do
|
96
|
-
context 'when status is :success' do
|
97
|
-
it 'should send Success message' do
|
98
|
-
notifier.expects(:send_message).with(
|
99
|
-
'[Backup::Success] test label (test_trigger)'
|
100
|
-
)
|
101
|
-
notifier.send(:notify!, :success)
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
context 'when status is :warning' do
|
106
|
-
it 'should send Warning message' do
|
107
|
-
notifier.expects(:send_message).with(
|
108
|
-
'[Backup::Warning] test label (test_trigger)'
|
109
|
-
)
|
110
|
-
notifier.send(:notify!, :warning)
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
context 'when status is :failure' do
|
115
|
-
it 'should send Failure message' do
|
116
|
-
notifier.expects(:send_message).with(
|
117
|
-
'[Backup::Failure] test label (test_trigger)'
|
118
|
-
)
|
119
|
-
notifier.send(:notify!, :failure)
|
120
|
-
end
|
121
|
-
end
|
122
|
-
end # describe '#notify!'
|
123
|
-
end
|
@@ -1,153 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require File.expand_path('../../spec_helper.rb', __FILE__)
|
4
|
-
|
5
|
-
describe Backup::Notifier::Twitter do
|
6
|
-
let(:model) { Backup::Model.new(:test_trigger, 'test label') }
|
7
|
-
let(:notifier) do
|
8
|
-
Backup::Notifier::Twitter.new(model) do |twitter|
|
9
|
-
twitter.consumer_key = 'consumer_key'
|
10
|
-
twitter.consumer_secret = 'consumer_secret'
|
11
|
-
twitter.oauth_token = 'oauth_token'
|
12
|
-
twitter.oauth_token_secret = 'oauth_token_secret'
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
it 'should be a subclass of Notifier::Base' do
|
17
|
-
Backup::Notifier::Twitter.
|
18
|
-
superclass.should == Backup::Notifier::Base
|
19
|
-
end
|
20
|
-
|
21
|
-
describe '#initialize' do
|
22
|
-
after { Backup::Notifier::Twitter.clear_defaults! }
|
23
|
-
|
24
|
-
it 'should load pre-configured defaults through Base' do
|
25
|
-
Backup::Notifier::Twitter.any_instance.expects(:load_defaults!)
|
26
|
-
notifier
|
27
|
-
end
|
28
|
-
|
29
|
-
it 'should pass the model reference to Base' do
|
30
|
-
notifier.instance_variable_get(:@model).should == model
|
31
|
-
end
|
32
|
-
|
33
|
-
context 'when no pre-configured defaults have been set' do
|
34
|
-
it 'should use the values given' do
|
35
|
-
notifier.consumer_key.should == 'consumer_key'
|
36
|
-
notifier.consumer_secret.should == 'consumer_secret'
|
37
|
-
notifier.oauth_token.should == 'oauth_token'
|
38
|
-
notifier.oauth_token_secret.should == 'oauth_token_secret'
|
39
|
-
|
40
|
-
notifier.on_success.should == true
|
41
|
-
notifier.on_warning.should == true
|
42
|
-
notifier.on_failure.should == true
|
43
|
-
end
|
44
|
-
|
45
|
-
it 'should use default values if none are given' do
|
46
|
-
notifier = Backup::Notifier::Twitter.new(model)
|
47
|
-
notifier.consumer_key.should be_nil
|
48
|
-
notifier.consumer_secret.should be_nil
|
49
|
-
notifier.oauth_token.should be_nil
|
50
|
-
notifier.oauth_token_secret.should be_nil
|
51
|
-
|
52
|
-
notifier.on_success.should == true
|
53
|
-
notifier.on_warning.should == true
|
54
|
-
notifier.on_failure.should == true
|
55
|
-
end
|
56
|
-
end # context 'when no pre-configured defaults have been set'
|
57
|
-
|
58
|
-
context 'when pre-configured defaults have been set' do
|
59
|
-
before do
|
60
|
-
Backup::Notifier::Twitter.defaults do |n|
|
61
|
-
n.consumer_key = 'some_consumer_key'
|
62
|
-
n.consumer_secret = 'some_consumer_secret'
|
63
|
-
n.oauth_token = 'some_oauth_token'
|
64
|
-
n.oauth_token_secret = 'some_oauth_token_secret'
|
65
|
-
|
66
|
-
n.on_success = false
|
67
|
-
n.on_warning = false
|
68
|
-
n.on_failure = false
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
it 'should use pre-configured defaults' do
|
73
|
-
notifier = Backup::Notifier::Twitter.new(model)
|
74
|
-
notifier.consumer_key.should == 'some_consumer_key'
|
75
|
-
notifier.consumer_secret.should == 'some_consumer_secret'
|
76
|
-
notifier.oauth_token.should == 'some_oauth_token'
|
77
|
-
notifier.oauth_token_secret.should == 'some_oauth_token_secret'
|
78
|
-
|
79
|
-
notifier.on_success.should == false
|
80
|
-
notifier.on_warning.should == false
|
81
|
-
notifier.on_failure.should == false
|
82
|
-
end
|
83
|
-
|
84
|
-
it 'should override pre-configured defaults' do
|
85
|
-
notifier = Backup::Notifier::Twitter.new(model) do |n|
|
86
|
-
n.consumer_key = 'new_consumer_key'
|
87
|
-
n.consumer_secret = 'new_consumer_secret'
|
88
|
-
n.oauth_token = 'new_oauth_token'
|
89
|
-
n.oauth_token_secret = 'new_oauth_token_secret'
|
90
|
-
|
91
|
-
n.on_success = false
|
92
|
-
n.on_warning = true
|
93
|
-
n.on_failure = true
|
94
|
-
end
|
95
|
-
|
96
|
-
notifier.consumer_key.should == 'new_consumer_key'
|
97
|
-
notifier.consumer_secret.should == 'new_consumer_secret'
|
98
|
-
notifier.oauth_token.should == 'new_oauth_token'
|
99
|
-
notifier.oauth_token_secret.should == 'new_oauth_token_secret'
|
100
|
-
|
101
|
-
notifier.on_success.should == false
|
102
|
-
notifier.on_warning.should == true
|
103
|
-
notifier.on_failure.should == true
|
104
|
-
end
|
105
|
-
end # context 'when pre-configured defaults have been set'
|
106
|
-
end # describe '#initialize'
|
107
|
-
|
108
|
-
describe '#notify!' do
|
109
|
-
context 'when status is :success' do
|
110
|
-
it 'should send Success message' do
|
111
|
-
notifier.expects(:send_message).with(
|
112
|
-
"[Backup::Success] test label (test_trigger) (@ #{notifier.instance_variable_get("@model").time})"
|
113
|
-
)
|
114
|
-
notifier.send(:notify!, :success)
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
context 'when status is :warning' do
|
119
|
-
it 'should send Warning message' do
|
120
|
-
notifier.expects(:send_message).with(
|
121
|
-
"[Backup::Warning] test label (test_trigger) (@ #{notifier.instance_variable_get("@model").time})"
|
122
|
-
)
|
123
|
-
notifier.send(:notify!, :warning)
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
|
-
context 'when status is :failure' do
|
128
|
-
it 'should send Failure message' do
|
129
|
-
notifier.expects(:send_message).with(
|
130
|
-
"[Backup::Failure] test label (test_trigger) (@ #{notifier.instance_variable_get("@model").time})"
|
131
|
-
)
|
132
|
-
notifier.send(:notify!, :failure)
|
133
|
-
end
|
134
|
-
end
|
135
|
-
end # describe '#notify!'
|
136
|
-
|
137
|
-
describe '#send_message' do
|
138
|
-
it 'should send a message' do
|
139
|
-
client, config = mock, mock
|
140
|
-
|
141
|
-
::Twitter.expects(:configure).yields(config)
|
142
|
-
config.expects(:consumer_key=).with('consumer_key')
|
143
|
-
config.expects(:consumer_secret=).with('consumer_secret')
|
144
|
-
config.expects(:oauth_token=).with('oauth_token')
|
145
|
-
config.expects(:oauth_token_secret=).with('oauth_token_secret')
|
146
|
-
|
147
|
-
::Twitter::Client.expects(:new).returns(client)
|
148
|
-
client.expects(:update).with('a message')
|
149
|
-
|
150
|
-
notifier.send(:send_message, 'a message')
|
151
|
-
end
|
152
|
-
end
|
153
|
-
end
|
data/spec/package_spec.rb
DELETED
@@ -1,61 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require File.expand_path('../spec_helper.rb', __FILE__)
|
4
|
-
|
5
|
-
describe Backup::Package do
|
6
|
-
let(:model) { Backup::Model.new(:test_trigger, 'test label') }
|
7
|
-
let(:package) { Backup::Package.new(model) }
|
8
|
-
|
9
|
-
before do
|
10
|
-
model.instance_variable_set(:@time, 'model_time')
|
11
|
-
end
|
12
|
-
|
13
|
-
describe '#initialize' do
|
14
|
-
it 'should set all variables' do
|
15
|
-
package.time.should == 'model_time'
|
16
|
-
package.trigger.should == 'test_trigger'
|
17
|
-
package.extension.should == 'tar'
|
18
|
-
package.chunk_suffixes.should == []
|
19
|
-
package.version.should == Backup::Version.current
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
describe '#filenames' do
|
24
|
-
context 'when the package files were not split' do
|
25
|
-
it 'should return an array with the single package filename' do
|
26
|
-
package.filenames.should == ['model_time.test_trigger.tar']
|
27
|
-
end
|
28
|
-
|
29
|
-
it 'should reflect changes in the extension' do
|
30
|
-
package.extension << '.enc'
|
31
|
-
package.filenames.should == ['model_time.test_trigger.tar.enc']
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
context 'when the package files were split' do
|
36
|
-
before { package.chunk_suffixes = ['aa', 'ab'] }
|
37
|
-
it 'should return an array of the package filenames' do
|
38
|
-
package.filenames.should == ['model_time.test_trigger.tar-aa',
|
39
|
-
'model_time.test_trigger.tar-ab']
|
40
|
-
end
|
41
|
-
|
42
|
-
it 'should reflect changes in the extension' do
|
43
|
-
package.extension << '.enc'
|
44
|
-
package.filenames.should == ['model_time.test_trigger.tar.enc-aa',
|
45
|
-
'model_time.test_trigger.tar.enc-ab']
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
describe '#basename' do
|
51
|
-
it 'should return the base filename for the package' do
|
52
|
-
package.basename.should == 'model_time.test_trigger.tar'
|
53
|
-
end
|
54
|
-
|
55
|
-
it 'should reflect changes in the extension' do
|
56
|
-
package.extension << '.enc'
|
57
|
-
package.basename.should == 'model_time.test_trigger.tar.enc'
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
end
|
data/spec/packager_spec.rb
DELETED
@@ -1,213 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require File.expand_path('../spec_helper.rb', __FILE__)
|
4
|
-
|
5
|
-
describe 'Backup::Packager' do
|
6
|
-
let(:packager) { Backup::Packager }
|
7
|
-
|
8
|
-
describe '#package!' do
|
9
|
-
let(:model) { mock }
|
10
|
-
let(:package) { mock }
|
11
|
-
let(:encryptor) { mock }
|
12
|
-
let(:splitter) { mock }
|
13
|
-
let(:pipeline) { mock }
|
14
|
-
let(:procedure) { mock }
|
15
|
-
let(:s) { sequence '' }
|
16
|
-
|
17
|
-
context 'when pipeline command is successful' do
|
18
|
-
it 'should setup variables and perform packaging procedures' do
|
19
|
-
model.expects(:package).in_sequence(s).returns(package)
|
20
|
-
model.expects(:encryptor).in_sequence(s).returns(encryptor)
|
21
|
-
model.expects(:splitter).in_sequence(s).returns(splitter)
|
22
|
-
Backup::Pipeline.expects(:new).in_sequence(s).returns(pipeline)
|
23
|
-
|
24
|
-
Backup::Logger.expects(:message).in_sequence(s).with(
|
25
|
-
'Packaging the backup files...'
|
26
|
-
)
|
27
|
-
packager.expects(:procedure).in_sequence(s).returns(procedure)
|
28
|
-
procedure.expects(:call).in_sequence(s)
|
29
|
-
|
30
|
-
pipeline.expects(:success?).in_sequence(s).returns(true)
|
31
|
-
Backup::Logger.expects(:message).in_sequence(s).with(
|
32
|
-
'Packaging Complete!'
|
33
|
-
)
|
34
|
-
|
35
|
-
packager.package!(model)
|
36
|
-
|
37
|
-
packager.instance_variable_get(:@package).should be(package)
|
38
|
-
packager.instance_variable_get(:@encryptor).should be(encryptor)
|
39
|
-
packager.instance_variable_get(:@splitter).should be(splitter)
|
40
|
-
packager.instance_variable_get(:@pipeline).should be(pipeline)
|
41
|
-
end
|
42
|
-
end #context 'when pipeline command is successful'
|
43
|
-
|
44
|
-
context 'when pipeline command is not successful' do
|
45
|
-
it 'should raise an error' do
|
46
|
-
model.expects(:package).in_sequence(s).returns(package)
|
47
|
-
model.expects(:encryptor).in_sequence(s).returns(encryptor)
|
48
|
-
model.expects(:splitter).in_sequence(s).returns(splitter)
|
49
|
-
Backup::Pipeline.expects(:new).in_sequence(s).returns(pipeline)
|
50
|
-
|
51
|
-
Backup::Logger.expects(:message).in_sequence(s).with(
|
52
|
-
'Packaging the backup files...'
|
53
|
-
)
|
54
|
-
packager.expects(:procedure).in_sequence(s).returns(procedure)
|
55
|
-
procedure.expects(:call).in_sequence(s)
|
56
|
-
|
57
|
-
pipeline.expects(:success?).in_sequence(s).returns(false)
|
58
|
-
pipeline.expects(:error_messages).in_sequence(s).returns('pipeline_errors')
|
59
|
-
|
60
|
-
expect do
|
61
|
-
packager.package!(model)
|
62
|
-
end.to raise_error(
|
63
|
-
Backup::Errors::Packager::PipelineError,
|
64
|
-
"Packager::PipelineError: Failed to Create Backup Package\n" +
|
65
|
-
" pipeline_errors"
|
66
|
-
)
|
67
|
-
|
68
|
-
packager.instance_variable_get(:@package).should be(package)
|
69
|
-
packager.instance_variable_get(:@encryptor).should be(encryptor)
|
70
|
-
packager.instance_variable_get(:@splitter).should be(splitter)
|
71
|
-
packager.instance_variable_get(:@pipeline).should be(pipeline)
|
72
|
-
end
|
73
|
-
end #context 'when pipeline command is successful'
|
74
|
-
end # describe '#package!'
|
75
|
-
|
76
|
-
describe '#procedure' do
|
77
|
-
|
78
|
-
module Fake
|
79
|
-
def self.stack_trace
|
80
|
-
@stack ||= []
|
81
|
-
end
|
82
|
-
class Encryptor
|
83
|
-
def encrypt_with
|
84
|
-
Fake.stack_trace << :encryptor_before
|
85
|
-
yield 'encryption_command', '.enc'
|
86
|
-
Fake.stack_trace << :encryptor_after
|
87
|
-
end
|
88
|
-
end
|
89
|
-
class Splitter
|
90
|
-
def split_with
|
91
|
-
Fake.stack_trace << :splitter_before
|
92
|
-
yield 'splitter_command'
|
93
|
-
Fake.stack_trace << :splitter_after
|
94
|
-
end
|
95
|
-
end
|
96
|
-
class Package
|
97
|
-
attr_accessor :trigger, :extension
|
98
|
-
def basename
|
99
|
-
'base_filename.' + extension
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
let(:package) { Fake::Package.new }
|
105
|
-
let(:encryptor) { Fake::Encryptor.new }
|
106
|
-
let(:splitter) { Fake::Splitter.new }
|
107
|
-
let(:pipeline) { mock }
|
108
|
-
let(:s) { sequence '' }
|
109
|
-
|
110
|
-
before do
|
111
|
-
Fake.stack_trace.clear
|
112
|
-
packager.expects(:utility).with(:tar).returns('tar')
|
113
|
-
packager.instance_variable_set(:@package, package)
|
114
|
-
packager.instance_variable_set(:@pipeline, pipeline)
|
115
|
-
package.trigger = 'model_trigger'
|
116
|
-
package.extension = 'tar'
|
117
|
-
end
|
118
|
-
|
119
|
-
context 'when no encryptor or splitter are defined' do
|
120
|
-
it 'should package the backup without encryption into a single file' do
|
121
|
-
packager.instance_variable_set(:@encryptor, nil)
|
122
|
-
packager.instance_variable_set(:@splitter, nil)
|
123
|
-
|
124
|
-
pipeline.expects(:<<).in_sequence(s).with(
|
125
|
-
"tar -cf - -C '#{ Backup::Config.tmp_path }' 'model_trigger'"
|
126
|
-
)
|
127
|
-
pipeline.expects(:<<).in_sequence(s).with(
|
128
|
-
"cat > #{ File.join(Backup::Config.tmp_path, 'base_filename.tar') }"
|
129
|
-
)
|
130
|
-
pipeline.expects(:run).in_sequence(s)
|
131
|
-
|
132
|
-
packager.send(:procedure).call
|
133
|
-
end
|
134
|
-
end
|
135
|
-
|
136
|
-
context 'when only an encryptor is configured' do
|
137
|
-
it 'should package the backup with encryption' do
|
138
|
-
packager.instance_variable_set(:@encryptor, encryptor)
|
139
|
-
packager.instance_variable_set(:@splitter, nil)
|
140
|
-
|
141
|
-
pipeline.expects(:<<).in_sequence(s).with(
|
142
|
-
"tar -cf - -C '#{ Backup::Config.tmp_path }' 'model_trigger'"
|
143
|
-
)
|
144
|
-
pipeline.expects(:<<).in_sequence(s).with('encryption_command')
|
145
|
-
pipeline.expects(:<<).in_sequence(s).with(
|
146
|
-
"cat > #{ File.join(Backup::Config.tmp_path, 'base_filename.tar.enc') }"
|
147
|
-
)
|
148
|
-
pipeline.expects(:run).in_sequence(s).with do
|
149
|
-
Fake.stack_trace << :command_executed
|
150
|
-
true
|
151
|
-
end
|
152
|
-
|
153
|
-
packager.send(:procedure).call
|
154
|
-
|
155
|
-
Fake.stack_trace.should == [
|
156
|
-
:encryptor_before, :command_executed, :encryptor_after
|
157
|
-
]
|
158
|
-
end
|
159
|
-
end
|
160
|
-
|
161
|
-
context 'when only a splitter is configured' do
|
162
|
-
it 'should package the backup without encryption through the splitter' do
|
163
|
-
packager.instance_variable_set(:@encryptor, nil)
|
164
|
-
packager.instance_variable_set(:@splitter, splitter)
|
165
|
-
|
166
|
-
pipeline.expects(:<<).in_sequence(s).with(
|
167
|
-
"tar -cf - -C '#{ Backup::Config.tmp_path }' 'model_trigger'"
|
168
|
-
)
|
169
|
-
pipeline.expects(:<<).in_sequence(s).with('splitter_command')
|
170
|
-
|
171
|
-
pipeline.expects(:run).in_sequence(s).with do
|
172
|
-
Fake.stack_trace << :command_executed
|
173
|
-
true
|
174
|
-
end
|
175
|
-
|
176
|
-
packager.send(:procedure).call
|
177
|
-
|
178
|
-
Fake.stack_trace.should == [
|
179
|
-
:splitter_before, :command_executed, :splitter_after
|
180
|
-
]
|
181
|
-
end
|
182
|
-
end
|
183
|
-
|
184
|
-
context 'when both an encryptor and a splitter are configured' do
|
185
|
-
it 'should package the backup with encryption through the splitter' do
|
186
|
-
packager.instance_variable_set(:@encryptor, encryptor)
|
187
|
-
packager.instance_variable_set(:@splitter, splitter)
|
188
|
-
|
189
|
-
pipeline.expects(:<<).in_sequence(s).with(
|
190
|
-
"tar -cf - -C '#{ Backup::Config.tmp_path }' 'model_trigger'"
|
191
|
-
)
|
192
|
-
pipeline.expects(:<<).in_sequence(s).with('encryption_command')
|
193
|
-
pipeline.expects(:<<).in_sequence(s).with('splitter_command')
|
194
|
-
|
195
|
-
pipeline.expects(:run).in_sequence(s).with do
|
196
|
-
Fake.stack_trace << :command_executed
|
197
|
-
true
|
198
|
-
end
|
199
|
-
|
200
|
-
packager.send(:procedure).call
|
201
|
-
|
202
|
-
Fake.stack_trace.should == [
|
203
|
-
:encryptor_before, :splitter_before,
|
204
|
-
:command_executed,
|
205
|
-
:splitter_after, :encryptor_after
|
206
|
-
]
|
207
|
-
package.extension.should == 'tar.enc'
|
208
|
-
end
|
209
|
-
end
|
210
|
-
|
211
|
-
end # describe '#procedure'
|
212
|
-
|
213
|
-
end
|