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.
- data/Gemfile +1 -5
- data/Gemfile.lock +46 -50
- data/README.md +54 -27
- data/lib/backup.rb +16 -39
- data/lib/backup/archive.rb +42 -18
- data/lib/backup/cleaner.rb +110 -25
- data/lib/backup/cli/helpers.rb +17 -32
- data/lib/backup/cli/utility.rb +46 -107
- data/lib/backup/compressor/base.rb +14 -2
- data/lib/backup/compressor/bzip2.rb +10 -24
- data/lib/backup/compressor/gzip.rb +10 -24
- data/lib/backup/compressor/lzma.rb +10 -23
- data/lib/backup/compressor/pbzip2.rb +12 -32
- data/lib/backup/config.rb +171 -0
- data/lib/backup/configuration/compressor/base.rb +1 -2
- data/lib/backup/configuration/compressor/pbzip2.rb +4 -4
- data/lib/backup/configuration/database/base.rb +2 -1
- data/lib/backup/configuration/database/mongodb.rb +8 -0
- data/lib/backup/configuration/database/mysql.rb +4 -0
- data/lib/backup/configuration/database/postgresql.rb +4 -0
- data/lib/backup/configuration/database/redis.rb +4 -0
- data/lib/backup/configuration/database/riak.rb +5 -1
- data/lib/backup/configuration/encryptor/base.rb +1 -2
- data/lib/backup/configuration/encryptor/open_ssl.rb +1 -1
- data/lib/backup/configuration/helpers.rb +7 -2
- data/lib/backup/configuration/notifier/base.rb +4 -28
- data/lib/backup/configuration/storage/base.rb +1 -1
- data/lib/backup/configuration/storage/dropbox.rb +14 -4
- data/lib/backup/configuration/syncer/base.rb +10 -0
- data/lib/backup/configuration/syncer/rsync/base.rb +28 -0
- data/lib/backup/configuration/syncer/rsync/local.rb +11 -0
- data/lib/backup/configuration/syncer/rsync/pull.rb +11 -0
- data/lib/backup/configuration/syncer/rsync/push.rb +31 -0
- data/lib/backup/configuration/syncer/s3.rb +0 -4
- data/lib/backup/database/base.rb +25 -7
- data/lib/backup/database/mongodb.rb +112 -75
- data/lib/backup/database/mysql.rb +54 -29
- data/lib/backup/database/postgresql.rb +60 -42
- data/lib/backup/database/redis.rb +61 -39
- data/lib/backup/database/riak.rb +35 -11
- data/lib/backup/dependency.rb +4 -5
- data/lib/backup/encryptor/base.rb +13 -1
- data/lib/backup/encryptor/gpg.rb +39 -39
- data/lib/backup/encryptor/open_ssl.rb +28 -38
- data/lib/backup/logger.rb +20 -11
- data/lib/backup/model.rb +206 -163
- data/lib/backup/notifier/base.rb +27 -25
- data/lib/backup/notifier/campfire.rb +7 -13
- data/lib/backup/notifier/hipchat.rb +28 -28
- data/lib/backup/notifier/mail.rb +24 -26
- data/lib/backup/notifier/presently.rb +10 -18
- data/lib/backup/notifier/prowl.rb +9 -17
- data/lib/backup/notifier/twitter.rb +11 -18
- data/lib/backup/package.rb +47 -0
- data/lib/backup/packager.rb +81 -16
- data/lib/backup/splitter.rb +48 -35
- data/lib/backup/storage/base.rb +44 -172
- data/lib/backup/storage/cloudfiles.rb +31 -46
- data/lib/backup/storage/cycler.rb +117 -0
- data/lib/backup/storage/dropbox.rb +92 -76
- data/lib/backup/storage/ftp.rb +30 -40
- data/lib/backup/storage/local.rb +44 -45
- data/lib/backup/storage/ninefold.rb +55 -49
- data/lib/backup/storage/rsync.rb +49 -56
- data/lib/backup/storage/s3.rb +33 -44
- data/lib/backup/storage/scp.rb +21 -48
- data/lib/backup/storage/sftp.rb +26 -40
- data/lib/backup/syncer/base.rb +7 -0
- data/lib/backup/syncer/rsync/base.rb +78 -0
- data/lib/backup/syncer/rsync/local.rb +53 -0
- data/lib/backup/syncer/rsync/pull.rb +38 -0
- data/lib/backup/syncer/rsync/push.rb +113 -0
- data/lib/backup/syncer/s3.rb +42 -32
- data/lib/backup/version.rb +1 -1
- data/spec/archive_spec.rb +235 -69
- data/spec/cleaner_spec.rb +304 -0
- data/spec/cli/helpers_spec.rb +142 -1
- data/spec/cli/utility_spec.rb +338 -13
- data/spec/compressor/base_spec.rb +31 -0
- data/spec/compressor/bzip2_spec.rb +60 -35
- data/spec/compressor/gzip_spec.rb +60 -35
- data/spec/compressor/lzma_spec.rb +60 -35
- data/spec/compressor/pbzip2_spec.rb +98 -37
- data/spec/config_spec.rb +321 -0
- data/spec/configuration/base_spec.rb +4 -4
- data/spec/configuration/compressor/bzip2_spec.rb +1 -0
- data/spec/configuration/compressor/gzip_spec.rb +1 -0
- data/spec/configuration/compressor/lzma_spec.rb +1 -0
- data/spec/configuration/compressor/pbzip2_spec.rb +32 -0
- data/spec/configuration/database/base_spec.rb +2 -1
- data/spec/configuration/database/mongodb_spec.rb +26 -16
- data/spec/configuration/database/mysql_spec.rb +4 -0
- data/spec/configuration/database/postgresql_spec.rb +4 -0
- data/spec/configuration/database/redis_spec.rb +4 -0
- data/spec/configuration/database/riak_spec.rb +4 -0
- data/spec/configuration/encryptor/gpg_spec.rb +1 -0
- data/spec/configuration/encryptor/open_ssl_spec.rb +1 -0
- data/spec/configuration/notifier/base_spec.rb +32 -0
- data/spec/configuration/notifier/campfire_spec.rb +1 -0
- data/spec/configuration/notifier/hipchat_spec.rb +1 -0
- data/spec/configuration/notifier/mail_spec.rb +1 -0
- data/spec/configuration/notifier/presently_spec.rb +1 -0
- data/spec/configuration/notifier/prowl_spec.rb +1 -0
- data/spec/configuration/notifier/twitter_spec.rb +1 -0
- data/spec/configuration/storage/cloudfiles_spec.rb +1 -0
- data/spec/configuration/storage/dropbox_spec.rb +4 -3
- data/spec/configuration/storage/ftp_spec.rb +1 -0
- data/spec/configuration/storage/local_spec.rb +1 -0
- data/spec/configuration/storage/ninefold_spec.rb +1 -0
- data/spec/configuration/storage/rsync_spec.rb +3 -1
- data/spec/configuration/storage/s3_spec.rb +1 -0
- data/spec/configuration/storage/scp_spec.rb +1 -0
- data/spec/configuration/storage/sftp_spec.rb +1 -0
- data/spec/configuration/syncer/rsync/base_spec.rb +33 -0
- data/spec/configuration/syncer/rsync/local_spec.rb +10 -0
- data/spec/configuration/syncer/rsync/pull_spec.rb +10 -0
- data/spec/configuration/syncer/{rsync_spec.rb → rsync/push_spec.rb} +12 -15
- data/spec/configuration/syncer/s3_spec.rb +2 -3
- data/spec/database/base_spec.rb +35 -20
- data/spec/database/mongodb_spec.rb +298 -119
- data/spec/database/mysql_spec.rb +147 -72
- data/spec/database/postgresql_spec.rb +155 -100
- data/spec/database/redis_spec.rb +200 -97
- data/spec/database/riak_spec.rb +82 -24
- data/spec/dependency_spec.rb +49 -0
- data/spec/encryptor/base_spec.rb +30 -0
- data/spec/encryptor/gpg_spec.rb +105 -28
- data/spec/encryptor/open_ssl_spec.rb +85 -114
- data/spec/logger_spec.rb +74 -8
- data/spec/model_spec.rb +528 -220
- data/spec/notifier/base_spec.rb +89 -0
- data/spec/notifier/campfire_spec.rb +147 -119
- data/spec/notifier/hipchat_spec.rb +140 -145
- data/spec/notifier/mail_spec.rb +190 -248
- data/spec/notifier/presently_spec.rb +147 -282
- data/spec/notifier/prowl_spec.rb +79 -111
- data/spec/notifier/twitter_spec.rb +87 -106
- data/spec/package_spec.rb +61 -0
- data/spec/packager_spec.rb +154 -0
- data/spec/spec_helper.rb +36 -13
- data/spec/splitter_spec.rb +90 -41
- data/spec/storage/base_spec.rb +95 -239
- data/spec/storage/cloudfiles_spec.rb +185 -75
- data/spec/storage/cycler_spec.rb +239 -0
- data/spec/storage/dropbox_spec.rb +318 -87
- data/spec/storage/ftp_spec.rb +165 -152
- data/spec/storage/local_spec.rb +206 -54
- data/spec/storage/ninefold_spec.rb +264 -128
- data/spec/storage/rsync_spec.rb +244 -163
- data/spec/storage/s3_spec.rb +175 -64
- data/spec/storage/scp_spec.rb +156 -150
- data/spec/storage/sftp_spec.rb +153 -135
- data/spec/syncer/base_spec.rb +22 -0
- data/spec/syncer/rsync/base_spec.rb +118 -0
- data/spec/syncer/rsync/local_spec.rb +121 -0
- data/spec/syncer/rsync/pull_spec.rb +90 -0
- data/spec/syncer/rsync/push_spec.rb +327 -0
- data/spec/syncer/s3_spec.rb +180 -91
- data/templates/cli/utility/config +1 -1
- data/templates/cli/utility/database/mongodb +4 -0
- data/templates/cli/utility/database/mysql +3 -0
- data/templates/cli/utility/database/postgresql +3 -0
- data/templates/cli/utility/database/redis +3 -0
- data/templates/cli/utility/database/riak +3 -0
- data/templates/cli/utility/storage/dropbox +4 -1
- data/templates/cli/utility/syncer/rsync_local +12 -0
- data/templates/cli/utility/syncer/{rsync → rsync_pull} +2 -2
- data/templates/cli/utility/syncer/rsync_push +17 -0
- data/templates/storage/dropbox/authorization_url.erb +1 -1
- metadata +42 -17
- data/lib/backup/configuration/syncer/rsync.rb +0 -45
- data/lib/backup/finder.rb +0 -87
- data/lib/backup/storage/object.rb +0 -47
- data/lib/backup/syncer/rsync.rb +0 -152
- data/spec/backup_spec.rb +0 -11
- data/spec/finder_spec.rb +0 -91
- data/spec/storage/object_spec.rb +0 -74
- data/spec/syncer/rsync_spec.rb +0 -195
data/spec/cli/utility_spec.rb
CHANGED
|
@@ -3,36 +3,361 @@
|
|
|
3
3
|
require File.expand_path('../../spec_helper.rb', __FILE__)
|
|
4
4
|
|
|
5
5
|
describe 'Backup::CLI::Utility' do
|
|
6
|
-
let(:cli)
|
|
6
|
+
let(:cli) { Backup::CLI::Utility }
|
|
7
|
+
let(:utility) { Backup::CLI::Utility.new }
|
|
8
|
+
let(:s) { sequence '' }
|
|
9
|
+
|
|
10
|
+
before { @argv_save = ARGV }
|
|
11
|
+
after { ARGV.replace(@argv_save) }
|
|
7
12
|
|
|
8
13
|
describe '#perform' do
|
|
14
|
+
let(:model_a) { Backup::Model.new(:test_trigger_a, 'test label a') }
|
|
15
|
+
let(:model_b) { Backup::Model.new(:test_trigger_b, 'test label b') }
|
|
9
16
|
|
|
10
|
-
|
|
17
|
+
before { Backup::Model.all.push(model_a, model_b) }
|
|
18
|
+
after { Backup::Model.all.clear }
|
|
11
19
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
20
|
+
it 'should perform the backup for the given trigger' do
|
|
21
|
+
Backup::Logger.expects(:quiet=).in_sequence(s)
|
|
22
|
+
Backup::Config.expects(:update).in_sequence(s)
|
|
23
|
+
Backup::Config.expects(:load_config!).in_sequence(s)
|
|
15
24
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
25
|
+
FileUtils.expects(:mkdir_p).in_sequence(s).with(Backup::Config.log_path)
|
|
26
|
+
FileUtils.expects(:mkdir_p).in_sequence(s).with(Backup::Config.cache_path)
|
|
27
|
+
FileUtils.expects(:mkdir_p).in_sequence(s).with(Backup::Config.tmp_path)
|
|
19
28
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
29
|
+
Backup::Logger.expects(:truncate!)
|
|
30
|
+
|
|
31
|
+
model_a.expects(:prepare!).in_sequence(s)
|
|
32
|
+
model_a.expects(:perform!).in_sequence(s)
|
|
33
|
+
Backup::Logger.expects(:clear!).in_sequence(s)
|
|
34
|
+
|
|
35
|
+
expect do
|
|
36
|
+
ARGV.replace(['perform', '-t', 'test_trigger_a'])
|
|
37
|
+
cli.start
|
|
38
|
+
end.not_to raise_error
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
it 'should perform backups for the multiple triggers' do
|
|
42
|
+
Backup::Logger.expects(:quiet=).in_sequence(s)
|
|
43
|
+
Backup::Config.expects(:update).in_sequence(s)
|
|
44
|
+
Backup::Config.expects(:load_config!).in_sequence(s)
|
|
45
|
+
|
|
46
|
+
FileUtils.expects(:mkdir_p).in_sequence(s).with(Backup::Config.log_path)
|
|
47
|
+
FileUtils.expects(:mkdir_p).in_sequence(s).with(Backup::Config.cache_path)
|
|
48
|
+
FileUtils.expects(:mkdir_p).in_sequence(s).with(Backup::Config.tmp_path)
|
|
23
49
|
|
|
50
|
+
Backup::Logger.expects(:truncate!)
|
|
51
|
+
|
|
52
|
+
model_a.expects(:prepare!).in_sequence(s)
|
|
53
|
+
model_a.expects(:perform!).in_sequence(s)
|
|
54
|
+
Backup::Logger.expects(:clear!).in_sequence(s)
|
|
55
|
+
|
|
56
|
+
model_b.expects(:prepare!).in_sequence(s)
|
|
57
|
+
model_b.expects(:perform!).in_sequence(s)
|
|
58
|
+
Backup::Logger.expects(:clear!).in_sequence(s)
|
|
59
|
+
|
|
60
|
+
expect do
|
|
61
|
+
ARGV.replace(['perform', '-t', 'test_trigger_a,test_trigger_b'])
|
|
62
|
+
cli.start
|
|
63
|
+
end.not_to raise_error
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
context 'when errors occur' do
|
|
67
|
+
it 'should log the error and exit' do
|
|
68
|
+
Backup::Logger.stubs(:quiet=).raises(SystemCallError, 'yikes!')
|
|
24
69
|
Backup::Logger.expects(:error).with do |err|
|
|
25
70
|
err.message.should ==
|
|
26
71
|
"CLIError: SystemCallError: unknown error - yikes!"
|
|
27
72
|
end
|
|
28
73
|
|
|
29
74
|
expect do
|
|
75
|
+
ARGV.replace(['perform', '-t', 'foo'])
|
|
30
76
|
cli.start
|
|
31
|
-
end.to raise_error(SystemExit)
|
|
77
|
+
end.to raise_error(SystemExit) {|exit| exit.status.should == 1 }
|
|
32
78
|
end
|
|
33
|
-
|
|
34
79
|
end # context 'when errors occur'
|
|
35
80
|
|
|
36
81
|
end # describe '#perform'
|
|
37
82
|
|
|
83
|
+
describe '#generate:model' do
|
|
84
|
+
before do
|
|
85
|
+
FileUtils.unstub(:mkdir_p)
|
|
86
|
+
FileUtils.unstub(:touch)
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
context 'when given a config_path' do
|
|
90
|
+
context 'when no config file exists' do
|
|
91
|
+
it 'should create both a config and a model under the given path' do
|
|
92
|
+
Dir.mktmpdir do |path|
|
|
93
|
+
model_file = File.join(path, 'custom', 'models', 'test_trigger.rb')
|
|
94
|
+
config_file = File.join(path, 'custom', 'config.rb')
|
|
95
|
+
|
|
96
|
+
out, err = capture_io do
|
|
97
|
+
ARGV.replace(['generate:model',
|
|
98
|
+
'--config-path', File.join(path, 'custom'),
|
|
99
|
+
'--trigger', 'test_trigger'
|
|
100
|
+
])
|
|
101
|
+
cli.start
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
out.should == "Generated model file: '#{ model_file }'.\n" +
|
|
105
|
+
"Generated configuration file: '#{ config_file }'.\n"
|
|
106
|
+
File.exist?(model_file).should be_true
|
|
107
|
+
File.exist?(config_file).should be_true
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
context 'when a config file already exists' do
|
|
113
|
+
it 'should only create a model under the given path' do
|
|
114
|
+
Dir.mktmpdir do |path|
|
|
115
|
+
model_file = File.join(path, 'custom', 'models', 'test_trigger.rb')
|
|
116
|
+
config_file = File.join(path, 'custom', 'config.rb')
|
|
117
|
+
FileUtils.mkdir_p(File.join(path, 'custom'))
|
|
118
|
+
FileUtils.touch(config_file)
|
|
119
|
+
|
|
120
|
+
out, err = capture_io do
|
|
121
|
+
ARGV.replace(['generate:model',
|
|
122
|
+
'--config-path', File.join(path, 'custom'),
|
|
123
|
+
'--trigger', 'test_trigger'
|
|
124
|
+
])
|
|
125
|
+
cli.start
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
out.should == "Generated model file: '#{ model_file }'.\n"
|
|
129
|
+
File.exist?(model_file).should be_true
|
|
130
|
+
end
|
|
131
|
+
end
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
# These pass, but generate Thor warnings...
|
|
135
|
+
#
|
|
136
|
+
# context 'when a model file already exists' do
|
|
137
|
+
# it 'should prompt to overwrite the model under the given path' do
|
|
138
|
+
# Dir.mktmpdir do |path|
|
|
139
|
+
# model_file = File.join(path, 'models', 'test_trigger.rb')
|
|
140
|
+
# config_file = File.join(path, 'config.rb')
|
|
141
|
+
#
|
|
142
|
+
# cli.any_instance.expects(:overwrite?).with(model_file).returns(false)
|
|
143
|
+
#
|
|
144
|
+
# out, err = capture_io do
|
|
145
|
+
# ARGV.replace(['generate:model',
|
|
146
|
+
# '--config-path', path,
|
|
147
|
+
# '--trigger', 'test_trigger'
|
|
148
|
+
# ])
|
|
149
|
+
# cli.start
|
|
150
|
+
# end
|
|
151
|
+
#
|
|
152
|
+
# out.should == "Generated configuration file: '#{ config_file }'.\n"
|
|
153
|
+
# File.exist?(config_file).should be_true
|
|
154
|
+
# File.exist?(model_file).should be_false
|
|
155
|
+
# end
|
|
156
|
+
# end
|
|
157
|
+
# end
|
|
158
|
+
|
|
159
|
+
end # context 'when given a config_path'
|
|
160
|
+
|
|
161
|
+
context 'when not given a config_path' do
|
|
162
|
+
it 'should create both a config and a model under the root path' do
|
|
163
|
+
Dir.mktmpdir do |path|
|
|
164
|
+
Backup::Config.update(:root_path => path)
|
|
165
|
+
model_file = File.join(path, 'models', 'test_trigger.rb')
|
|
166
|
+
config_file = File.join(path, 'config.rb')
|
|
167
|
+
|
|
168
|
+
out, err = capture_io do
|
|
169
|
+
ARGV.replace(['generate:model', '--trigger', 'test_trigger'])
|
|
170
|
+
cli.start
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
out.should == "Generated model file: '#{ model_file }'.\n" +
|
|
174
|
+
"Generated configuration file: '#{ config_file }'.\n"
|
|
175
|
+
File.exist?(model_file).should be_true
|
|
176
|
+
File.exist?(config_file).should be_true
|
|
177
|
+
end
|
|
178
|
+
end
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
it 'should generate the proper help output' do
|
|
182
|
+
ruby19_output = <<-EOS
|
|
183
|
+
Usage:
|
|
184
|
+
#{ File.basename($0) } generate:model --trigger=TRIGGER
|
|
185
|
+
|
|
186
|
+
Options:
|
|
187
|
+
--trigger=TRIGGER
|
|
188
|
+
[--config-path=CONFIG_PATH] # Path to your Backup configuration directory
|
|
189
|
+
[--databases=DATABASES] # (mongodb, mysql, postgresql, redis, riak)
|
|
190
|
+
[--storages=STORAGES] # (cloudfiles, dropbox, ftp, local, ninefold, rsync, s3, scp, sftp)
|
|
191
|
+
[--syncers=SYNCERS] # (rsync_local, rsync_pull, rsync_push, s3)
|
|
192
|
+
[--encryptors=ENCRYPTORS] # (gpg, openssl)
|
|
193
|
+
[--compressors=COMPRESSORS] # (bzip2, gzip, lzma, pbzip2)
|
|
194
|
+
[--notifiers=NOTIFIERS] # (campfire, hipchat, mail, presently, prowl, twitter)
|
|
195
|
+
[--archives]
|
|
196
|
+
[--splitter] # use `--no-splitter` to disable
|
|
197
|
+
# Default: true
|
|
198
|
+
Generates a Backup model file
|
|
199
|
+
|
|
200
|
+
Note:
|
|
201
|
+
'--config-path' is the path to the directory where 'config.rb' is located.
|
|
202
|
+
The model file will be created as '<config_path>/models/<trigger>.rb'
|
|
203
|
+
Default: #{ Backup::Config.root_path }
|
|
204
|
+
EOS
|
|
205
|
+
|
|
206
|
+
out, err = capture_io do
|
|
207
|
+
ARGV.replace(['help', 'generate:model'])
|
|
208
|
+
cli.start
|
|
209
|
+
end
|
|
210
|
+
|
|
211
|
+
expected_lines = ruby19_output.split("\n").map(&:strip).select {|e| !e.empty? }
|
|
212
|
+
output_lines = out.split("\n").map(&:strip).select {|e| !e.empty? }
|
|
213
|
+
|
|
214
|
+
output_lines.sort.should == expected_lines.sort
|
|
215
|
+
end
|
|
216
|
+
end
|
|
217
|
+
|
|
218
|
+
describe '#generate:config' do
|
|
219
|
+
before do
|
|
220
|
+
FileUtils.unstub(:mkdir_p)
|
|
221
|
+
FileUtils.unstub(:touch)
|
|
222
|
+
end
|
|
223
|
+
|
|
224
|
+
context 'when given a config_path' do
|
|
225
|
+
it 'should create a config file in the given path' do
|
|
226
|
+
Dir.mktmpdir do |path|
|
|
227
|
+
config_file = File.join(path, 'custom', 'config.rb')
|
|
228
|
+
|
|
229
|
+
out, err = capture_io do
|
|
230
|
+
ARGV.replace(['generate:config',
|
|
231
|
+
'--config-path', File.join(path, 'custom'),
|
|
232
|
+
])
|
|
233
|
+
cli.start
|
|
234
|
+
end
|
|
235
|
+
|
|
236
|
+
out.should == "Generated configuration file: '#{ config_file }'.\n"
|
|
237
|
+
File.exist?(config_file).should be_true
|
|
238
|
+
end
|
|
239
|
+
end
|
|
240
|
+
end
|
|
241
|
+
|
|
242
|
+
context 'when not given a config_path' do
|
|
243
|
+
it 'should create a config file in the root path' do
|
|
244
|
+
Dir.mktmpdir do |path|
|
|
245
|
+
Backup::Config.update(:root_path => path)
|
|
246
|
+
config_file = File.join(path, 'config.rb')
|
|
247
|
+
|
|
248
|
+
out, err = capture_io do
|
|
249
|
+
ARGV.replace(['generate:config'])
|
|
250
|
+
cli.start
|
|
251
|
+
end
|
|
252
|
+
|
|
253
|
+
out.should == "Generated configuration file: '#{ config_file }'.\n"
|
|
254
|
+
File.exist?(config_file).should be_true
|
|
255
|
+
end
|
|
256
|
+
end
|
|
257
|
+
end
|
|
258
|
+
|
|
259
|
+
# These pass, but generate Thor warnings...
|
|
260
|
+
#
|
|
261
|
+
# context 'when a config file already exists' do
|
|
262
|
+
# it 'should prompt to overwrite the config file' do
|
|
263
|
+
# Dir.mktmpdir do |path|
|
|
264
|
+
# Backup::Config.update(:root_path => path)
|
|
265
|
+
# config_file = File.join(path, 'config.rb')
|
|
266
|
+
#
|
|
267
|
+
# cli.any_instance.expects(:overwrite?).with(config_file).returns(false)
|
|
268
|
+
#
|
|
269
|
+
# out, err = capture_io do
|
|
270
|
+
# ARGV.replace(['generate:config'])
|
|
271
|
+
# cli.start
|
|
272
|
+
# end
|
|
273
|
+
#
|
|
274
|
+
# out.should be_empty
|
|
275
|
+
# File.exist?(config_file).should be_false
|
|
276
|
+
# end
|
|
277
|
+
# end
|
|
278
|
+
# end
|
|
279
|
+
|
|
280
|
+
end # describe '#generate:config'
|
|
281
|
+
|
|
282
|
+
describe '#decrypt' do
|
|
283
|
+
|
|
284
|
+
# These pass, but generate Thor warnings...
|
|
285
|
+
#
|
|
286
|
+
# it 'should perform OpenSSL decryption' do
|
|
287
|
+
# ARGV.replace(['decrypt', '--encryptor', 'openssl',
|
|
288
|
+
# '--in', 'in_file',
|
|
289
|
+
# '--out', 'out_file',
|
|
290
|
+
# '--base64', '--salt',
|
|
291
|
+
# '--password-file', 'pwd_file'])
|
|
292
|
+
#
|
|
293
|
+
# cli.any_instance.expects(:`).with(
|
|
294
|
+
# "openssl aes-256-cbc -d -base64 -pass file:pwd_file -salt " +
|
|
295
|
+
# "-in 'in_file' -out 'out_file'"
|
|
296
|
+
# )
|
|
297
|
+
# cli.start
|
|
298
|
+
# end
|
|
299
|
+
#
|
|
300
|
+
# it 'should perform GnuPG decryption' do
|
|
301
|
+
# ARGV.replace(['decrypt', '--encryptor', 'gpg',
|
|
302
|
+
# '--in', 'in_file',
|
|
303
|
+
# '--out', 'out_file'])
|
|
304
|
+
#
|
|
305
|
+
# cli.any_instance.expects(:`).with(
|
|
306
|
+
# "gpg -o 'out_file' -d 'in_file'"
|
|
307
|
+
# )
|
|
308
|
+
# cli.start
|
|
309
|
+
# end
|
|
310
|
+
|
|
311
|
+
it 'should show a message if given an invalid encryptor' do
|
|
312
|
+
ARGV.replace(['decrypt', '--encryptor', 'foo',
|
|
313
|
+
'--in', 'in_file',
|
|
314
|
+
'--out', 'out_file'])
|
|
315
|
+
out, err = capture_io do
|
|
316
|
+
cli.start
|
|
317
|
+
end
|
|
318
|
+
err.should == ''
|
|
319
|
+
out.should == "Unknown encryptor: foo\n" +
|
|
320
|
+
"Use either 'openssl' or 'gpg'.\n"
|
|
321
|
+
end
|
|
322
|
+
end
|
|
323
|
+
|
|
324
|
+
# would have the same Thor warnings issues...
|
|
325
|
+
# describe '#dependencies' do
|
|
326
|
+
# end
|
|
327
|
+
|
|
328
|
+
describe '#version' do
|
|
329
|
+
it 'should output the current version' do
|
|
330
|
+
utility.expects(:puts).with("Backup #{ Backup::Version.current }")
|
|
331
|
+
utility.version
|
|
332
|
+
end
|
|
333
|
+
|
|
334
|
+
it 'should output the current version for "-v"' do
|
|
335
|
+
ARGV.replace ['-v']
|
|
336
|
+
out, err = capture_io do
|
|
337
|
+
cli.start
|
|
338
|
+
end
|
|
339
|
+
out.should == "Backup #{ Backup::Version.current }\n"
|
|
340
|
+
end
|
|
341
|
+
end
|
|
342
|
+
|
|
343
|
+
describe '#overwrite?' do
|
|
344
|
+
context 'when the path exists' do
|
|
345
|
+
before { File.expects(:exist?).returns(true) }
|
|
346
|
+
|
|
347
|
+
it 'should prompt user' do
|
|
348
|
+
utility.expects(:yes?).with(
|
|
349
|
+
"A file already exists at 'a/path'. Do you want to overwrite? [y/n]"
|
|
350
|
+
).returns(:response)
|
|
351
|
+
utility.send(:overwrite?, 'a/path').should == :response
|
|
352
|
+
end
|
|
353
|
+
end
|
|
354
|
+
|
|
355
|
+
context 'when the path does not exist' do
|
|
356
|
+
before { File.expects(:exist?).returns(false) }
|
|
357
|
+
it 'should return true' do
|
|
358
|
+
utility.expects(:yes?).never
|
|
359
|
+
utility.send(:overwrite?, 'a/path').should be_true
|
|
360
|
+
end
|
|
361
|
+
end
|
|
362
|
+
end
|
|
38
363
|
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require File.expand_path('../../spec_helper.rb', __FILE__)
|
|
4
|
+
|
|
5
|
+
describe Backup::Compressor::Base do
|
|
6
|
+
let(:base) { Backup::Compressor::Base.new }
|
|
7
|
+
|
|
8
|
+
describe '#initialize' do
|
|
9
|
+
it 'should load defaults' do
|
|
10
|
+
Backup::Compressor::Base.any_instance.expects(:load_defaults!)
|
|
11
|
+
base
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
describe '#compressor_name' do
|
|
16
|
+
it 'should return class name with Backup namespace removed' do
|
|
17
|
+
base.send(:compressor_name).should == 'Compressor::Base'
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
describe '#log!' do
|
|
22
|
+
it 'should log a message' do
|
|
23
|
+
base.expects(:compressor_name).returns('Compressor Name')
|
|
24
|
+
Backup::Logger.expects(:message).with(
|
|
25
|
+
'Using Compressor Name for compression.'
|
|
26
|
+
)
|
|
27
|
+
base.send(:log!)
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
end
|
|
@@ -5,54 +5,79 @@ require File.expand_path('../../spec_helper.rb', __FILE__)
|
|
|
5
5
|
describe Backup::Compressor::Bzip2 do
|
|
6
6
|
let(:compressor) { Backup::Compressor::Bzip2.new }
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
Backup::
|
|
10
|
-
end
|
|
8
|
+
describe 'setting configuration defaults' do
|
|
9
|
+
after { Backup::Configuration::Compressor::Bzip2.clear_defaults! }
|
|
11
10
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
it 'uses and overrides configuration defaults' do
|
|
12
|
+
Backup::Configuration::Compressor::Bzip2.best.should be_false
|
|
13
|
+
Backup::Configuration::Compressor::Bzip2.fast.should be_false
|
|
14
|
+
|
|
15
|
+
compressor = Backup::Compressor::Bzip2.new
|
|
16
|
+
compressor.best.should be_false
|
|
17
|
+
compressor.fast.should be_false
|
|
18
|
+
|
|
19
|
+
Backup::Configuration::Compressor::Bzip2.defaults do |c|
|
|
20
|
+
c.best = true
|
|
21
|
+
c.fast = true
|
|
22
|
+
end
|
|
23
|
+
Backup::Configuration::Compressor::Bzip2.best.should be_true
|
|
24
|
+
Backup::Configuration::Compressor::Bzip2.fast.should be_true
|
|
16
25
|
|
|
17
|
-
|
|
18
|
-
compressor.
|
|
26
|
+
compressor = Backup::Compressor::Bzip2.new
|
|
27
|
+
compressor.best.should be_true
|
|
28
|
+
compressor.fast.should be_true
|
|
29
|
+
|
|
30
|
+
compressor = Backup::Compressor::Bzip2.new do |c|
|
|
31
|
+
c.best = false
|
|
32
|
+
end
|
|
33
|
+
compressor.best.should be_false
|
|
34
|
+
compressor.fast.should be_true
|
|
35
|
+
|
|
36
|
+
compressor = Backup::Compressor::Bzip2.new do |c|
|
|
37
|
+
c.fast = false
|
|
38
|
+
end
|
|
39
|
+
compressor.best.should be_true
|
|
40
|
+
compressor.fast.should be_false
|
|
19
41
|
end
|
|
20
|
-
end
|
|
42
|
+
end # describe 'setting configuration defaults'
|
|
21
43
|
|
|
22
|
-
describe '#
|
|
44
|
+
describe '#compress_with' do
|
|
23
45
|
before do
|
|
24
|
-
|
|
46
|
+
compressor.expects(:log!)
|
|
47
|
+
compressor.expects(:utility).with(:bzip2).returns('bzip2')
|
|
25
48
|
end
|
|
26
49
|
|
|
27
|
-
it 'should
|
|
28
|
-
compressor.
|
|
29
|
-
compressor.
|
|
30
|
-
|
|
50
|
+
it 'should yield with the --best option' do
|
|
51
|
+
compressor.best = true
|
|
52
|
+
compressor.compress_with do |cmd, ext|
|
|
53
|
+
cmd.should == 'bzip2 --best'
|
|
54
|
+
ext.should == '.bz2'
|
|
55
|
+
end
|
|
31
56
|
end
|
|
32
57
|
|
|
33
|
-
it 'should
|
|
34
|
-
compressor =
|
|
35
|
-
|
|
36
|
-
|
|
58
|
+
it 'should yield with the --fast option' do
|
|
59
|
+
compressor.fast = true
|
|
60
|
+
compressor.compress_with do |cmd, ext|
|
|
61
|
+
cmd.should == 'bzip2 --fast'
|
|
62
|
+
ext.should == '.bz2'
|
|
37
63
|
end
|
|
38
|
-
|
|
39
|
-
compressor.stubs(:utility).returns(:bzip2)
|
|
40
|
-
compressor.expects(:run).with("bzip2 --best --fast '#{ File.join(Backup::TMP_PATH, "#{ Backup::TIME }.#{ Backup::TRIGGER }.tar") }'")
|
|
41
|
-
compressor.perform!
|
|
42
64
|
end
|
|
43
65
|
|
|
44
|
-
it 'should
|
|
45
|
-
compressor.
|
|
46
|
-
compressor.
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
66
|
+
it 'should yield with the --best and --fast options' do
|
|
67
|
+
compressor.best = true
|
|
68
|
+
compressor.fast = true
|
|
69
|
+
compressor.compress_with do |cmd, ext|
|
|
70
|
+
cmd.should == 'bzip2 --best --fast'
|
|
71
|
+
ext.should == '.bz2'
|
|
72
|
+
end
|
|
51
73
|
end
|
|
52
74
|
|
|
53
|
-
it 'should
|
|
54
|
-
|
|
55
|
-
|
|
75
|
+
it 'should yield with no options' do
|
|
76
|
+
compressor.compress_with do |cmd, ext|
|
|
77
|
+
cmd.should == 'bzip2'
|
|
78
|
+
ext.should == '.bz2'
|
|
79
|
+
end
|
|
56
80
|
end
|
|
57
|
-
end
|
|
81
|
+
end # describe '#compress_with'
|
|
82
|
+
|
|
58
83
|
end
|