backup-agoddard 3.0.27
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of backup-agoddard might be problematic. Click here for more details.
- data/.gitignore +8 -0
- data/.travis.yml +10 -0
- data/Gemfile +28 -0
- data/Guardfile +23 -0
- data/LICENSE.md +24 -0
- data/README.md +478 -0
- data/backup.gemspec +32 -0
- data/bin/backup +11 -0
- data/lib/backup.rb +133 -0
- data/lib/backup/archive.rb +117 -0
- data/lib/backup/binder.rb +22 -0
- data/lib/backup/cleaner.rb +121 -0
- data/lib/backup/cli/helpers.rb +93 -0
- data/lib/backup/cli/utility.rb +255 -0
- data/lib/backup/compressor/base.rb +35 -0
- data/lib/backup/compressor/bzip2.rb +50 -0
- data/lib/backup/compressor/custom.rb +53 -0
- data/lib/backup/compressor/gzip.rb +50 -0
- data/lib/backup/compressor/lzma.rb +52 -0
- data/lib/backup/compressor/pbzip2.rb +59 -0
- data/lib/backup/config.rb +174 -0
- data/lib/backup/configuration.rb +33 -0
- data/lib/backup/configuration/helpers.rb +130 -0
- data/lib/backup/configuration/store.rb +24 -0
- data/lib/backup/database/base.rb +53 -0
- data/lib/backup/database/mongodb.rb +230 -0
- data/lib/backup/database/mysql.rb +160 -0
- data/lib/backup/database/postgresql.rb +144 -0
- data/lib/backup/database/redis.rb +136 -0
- data/lib/backup/database/riak.rb +67 -0
- data/lib/backup/dependency.rb +108 -0
- data/lib/backup/encryptor/base.rb +29 -0
- data/lib/backup/encryptor/gpg.rb +760 -0
- data/lib/backup/encryptor/open_ssl.rb +72 -0
- data/lib/backup/errors.rb +124 -0
- data/lib/backup/hooks.rb +68 -0
- data/lib/backup/logger.rb +152 -0
- data/lib/backup/model.rb +409 -0
- data/lib/backup/notifier/base.rb +81 -0
- data/lib/backup/notifier/campfire.rb +155 -0
- data/lib/backup/notifier/hipchat.rb +93 -0
- data/lib/backup/notifier/mail.rb +206 -0
- data/lib/backup/notifier/prowl.rb +65 -0
- data/lib/backup/notifier/pushover.rb +88 -0
- data/lib/backup/notifier/twitter.rb +70 -0
- data/lib/backup/package.rb +47 -0
- data/lib/backup/packager.rb +100 -0
- data/lib/backup/pipeline.rb +110 -0
- data/lib/backup/splitter.rb +75 -0
- data/lib/backup/storage/base.rb +99 -0
- data/lib/backup/storage/cloudfiles.rb +87 -0
- data/lib/backup/storage/cycler.rb +117 -0
- data/lib/backup/storage/dropbox.rb +178 -0
- data/lib/backup/storage/ftp.rb +119 -0
- data/lib/backup/storage/local.rb +82 -0
- data/lib/backup/storage/ninefold.rb +116 -0
- data/lib/backup/storage/rsync.rb +149 -0
- data/lib/backup/storage/s3.rb +94 -0
- data/lib/backup/storage/scp.rb +99 -0
- data/lib/backup/storage/sftp.rb +108 -0
- data/lib/backup/syncer/base.rb +46 -0
- data/lib/backup/syncer/cloud/base.rb +247 -0
- data/lib/backup/syncer/cloud/cloud_files.rb +78 -0
- data/lib/backup/syncer/cloud/s3.rb +68 -0
- data/lib/backup/syncer/rsync/base.rb +49 -0
- data/lib/backup/syncer/rsync/local.rb +55 -0
- data/lib/backup/syncer/rsync/pull.rb +36 -0
- data/lib/backup/syncer/rsync/push.rb +116 -0
- data/lib/backup/template.rb +46 -0
- data/lib/backup/version.rb +43 -0
- data/spec-live/.gitignore +6 -0
- data/spec-live/README +7 -0
- data/spec-live/backups/config.rb +83 -0
- data/spec-live/backups/config.yml.template +46 -0
- data/spec-live/backups/models.rb +184 -0
- data/spec-live/compressor/custom_spec.rb +30 -0
- data/spec-live/compressor/gzip_spec.rb +30 -0
- data/spec-live/encryptor/gpg_keys.rb +239 -0
- data/spec-live/encryptor/gpg_spec.rb +287 -0
- data/spec-live/notifier/mail_spec.rb +121 -0
- data/spec-live/spec_helper.rb +151 -0
- data/spec-live/storage/dropbox_spec.rb +151 -0
- data/spec-live/storage/local_spec.rb +83 -0
- data/spec-live/storage/scp_spec.rb +193 -0
- data/spec-live/syncer/cloud/s3_spec.rb +124 -0
- data/spec/archive_spec.rb +335 -0
- data/spec/cleaner_spec.rb +312 -0
- data/spec/cli/helpers_spec.rb +301 -0
- data/spec/cli/utility_spec.rb +411 -0
- data/spec/compressor/base_spec.rb +52 -0
- data/spec/compressor/bzip2_spec.rb +217 -0
- data/spec/compressor/custom_spec.rb +106 -0
- data/spec/compressor/gzip_spec.rb +217 -0
- data/spec/compressor/lzma_spec.rb +123 -0
- data/spec/compressor/pbzip2_spec.rb +165 -0
- data/spec/config_spec.rb +321 -0
- data/spec/configuration/helpers_spec.rb +247 -0
- data/spec/configuration/store_spec.rb +39 -0
- data/spec/configuration_spec.rb +62 -0
- data/spec/database/base_spec.rb +63 -0
- data/spec/database/mongodb_spec.rb +510 -0
- data/spec/database/mysql_spec.rb +411 -0
- data/spec/database/postgresql_spec.rb +353 -0
- data/spec/database/redis_spec.rb +334 -0
- data/spec/database/riak_spec.rb +176 -0
- data/spec/dependency_spec.rb +51 -0
- data/spec/encryptor/base_spec.rb +40 -0
- data/spec/encryptor/gpg_spec.rb +909 -0
- data/spec/encryptor/open_ssl_spec.rb +148 -0
- data/spec/errors_spec.rb +306 -0
- data/spec/hooks_spec.rb +35 -0
- data/spec/logger_spec.rb +367 -0
- data/spec/model_spec.rb +694 -0
- data/spec/notifier/base_spec.rb +104 -0
- data/spec/notifier/campfire_spec.rb +217 -0
- data/spec/notifier/hipchat_spec.rb +211 -0
- data/spec/notifier/mail_spec.rb +316 -0
- data/spec/notifier/prowl_spec.rb +138 -0
- data/spec/notifier/pushover_spec.rb +123 -0
- data/spec/notifier/twitter_spec.rb +153 -0
- data/spec/package_spec.rb +61 -0
- data/spec/packager_spec.rb +213 -0
- data/spec/pipeline_spec.rb +259 -0
- data/spec/spec_helper.rb +60 -0
- data/spec/splitter_spec.rb +120 -0
- data/spec/storage/base_spec.rb +166 -0
- data/spec/storage/cloudfiles_spec.rb +254 -0
- data/spec/storage/cycler_spec.rb +247 -0
- data/spec/storage/dropbox_spec.rb +480 -0
- data/spec/storage/ftp_spec.rb +271 -0
- data/spec/storage/local_spec.rb +259 -0
- data/spec/storage/ninefold_spec.rb +343 -0
- data/spec/storage/rsync_spec.rb +362 -0
- data/spec/storage/s3_spec.rb +245 -0
- data/spec/storage/scp_spec.rb +233 -0
- data/spec/storage/sftp_spec.rb +244 -0
- data/spec/syncer/base_spec.rb +109 -0
- data/spec/syncer/cloud/base_spec.rb +515 -0
- data/spec/syncer/cloud/cloud_files_spec.rb +181 -0
- data/spec/syncer/cloud/s3_spec.rb +174 -0
- data/spec/syncer/rsync/base_spec.rb +98 -0
- data/spec/syncer/rsync/local_spec.rb +149 -0
- data/spec/syncer/rsync/pull_spec.rb +98 -0
- data/spec/syncer/rsync/push_spec.rb +333 -0
- data/spec/version_spec.rb +21 -0
- data/templates/cli/utility/archive +25 -0
- data/templates/cli/utility/compressor/bzip2 +4 -0
- data/templates/cli/utility/compressor/custom +11 -0
- data/templates/cli/utility/compressor/gzip +4 -0
- data/templates/cli/utility/compressor/lzma +10 -0
- data/templates/cli/utility/compressor/pbzip2 +10 -0
- data/templates/cli/utility/config +32 -0
- data/templates/cli/utility/database/mongodb +18 -0
- data/templates/cli/utility/database/mysql +21 -0
- data/templates/cli/utility/database/postgresql +17 -0
- data/templates/cli/utility/database/redis +16 -0
- data/templates/cli/utility/database/riak +11 -0
- data/templates/cli/utility/encryptor/gpg +27 -0
- data/templates/cli/utility/encryptor/openssl +9 -0
- data/templates/cli/utility/model.erb +23 -0
- data/templates/cli/utility/notifier/campfire +12 -0
- data/templates/cli/utility/notifier/hipchat +15 -0
- data/templates/cli/utility/notifier/mail +22 -0
- data/templates/cli/utility/notifier/prowl +11 -0
- data/templates/cli/utility/notifier/pushover +11 -0
- data/templates/cli/utility/notifier/twitter +13 -0
- data/templates/cli/utility/splitter +7 -0
- data/templates/cli/utility/storage/cloud_files +22 -0
- data/templates/cli/utility/storage/dropbox +20 -0
- data/templates/cli/utility/storage/ftp +12 -0
- data/templates/cli/utility/storage/local +7 -0
- data/templates/cli/utility/storage/ninefold +9 -0
- data/templates/cli/utility/storage/rsync +11 -0
- data/templates/cli/utility/storage/s3 +19 -0
- data/templates/cli/utility/storage/scp +11 -0
- data/templates/cli/utility/storage/sftp +11 -0
- data/templates/cli/utility/syncer/cloud_files +46 -0
- data/templates/cli/utility/syncer/rsync_local +12 -0
- data/templates/cli/utility/syncer/rsync_pull +17 -0
- data/templates/cli/utility/syncer/rsync_push +17 -0
- data/templates/cli/utility/syncer/s3 +43 -0
- 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 +277 -0
@@ -0,0 +1,151 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require File.expand_path('../../spec_helper.rb', __FILE__)
|
4
|
+
|
5
|
+
describe 'Storage::Dropbox',
|
6
|
+
:if => Backup::SpecLive::CONFIG['storage']['dropbox']['specs_enabled'] do
|
7
|
+
let(:trigger) { 'archive_dropbox' }
|
8
|
+
|
9
|
+
def remote_files_for(storage, package)
|
10
|
+
remote_path = storage.send(:remote_path_for, package)
|
11
|
+
|
12
|
+
files = []
|
13
|
+
storage.send(:transferred_files_for, package) do |local_file, remote_file|
|
14
|
+
files << File.join(remote_path, remote_file)
|
15
|
+
end
|
16
|
+
files
|
17
|
+
end
|
18
|
+
|
19
|
+
def check_remote_for(storage, package, expectation = true)
|
20
|
+
remote_path = storage.send(:remote_path_for, package)
|
21
|
+
|
22
|
+
# search the remote_path folder for the trigger (base file name)
|
23
|
+
metadata = storage.send(:connection).search(
|
24
|
+
remote_path, package.trigger
|
25
|
+
)
|
26
|
+
files_found = metadata.map {|entry| File.basename(entry['path']) }
|
27
|
+
|
28
|
+
files = remote_files_for(storage, package).map {|file| File.basename(file) }
|
29
|
+
|
30
|
+
if expectation
|
31
|
+
files_found.sort.should == files.sort
|
32
|
+
else
|
33
|
+
files_found.should be_empty
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def clean_remote!(storage, package)
|
38
|
+
storage.send(:remove!, package)
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'should store the archive on the remote', :init => true do
|
42
|
+
model = h_set_trigger(trigger)
|
43
|
+
|
44
|
+
model.perform!
|
45
|
+
|
46
|
+
storage = model.storages.first
|
47
|
+
package = model.package
|
48
|
+
files = remote_files_for(storage, package)
|
49
|
+
files.count.should == 1
|
50
|
+
|
51
|
+
check_remote_for(storage, package)
|
52
|
+
|
53
|
+
clean_remote!(storage, package)
|
54
|
+
end
|
55
|
+
|
56
|
+
describe 'Storage::Dropbox Cycling' do
|
57
|
+
context 'when archives exceed `keep` setting' do
|
58
|
+
it 'should remove the oldest archive' do
|
59
|
+
packages = []
|
60
|
+
|
61
|
+
model = h_set_trigger(trigger)
|
62
|
+
storage = model.storages.first
|
63
|
+
model.perform!
|
64
|
+
package = model.package
|
65
|
+
package.filenames.count.should == 1
|
66
|
+
packages << package
|
67
|
+
sleep 1
|
68
|
+
|
69
|
+
check_remote_for(storage, packages[0])
|
70
|
+
|
71
|
+
model = h_set_trigger(trigger)
|
72
|
+
storage = model.storages.first
|
73
|
+
model.perform!
|
74
|
+
package = model.package
|
75
|
+
package.filenames.count.should == 1
|
76
|
+
packages << package
|
77
|
+
sleep 1
|
78
|
+
|
79
|
+
check_remote_for(storage, packages[1])
|
80
|
+
|
81
|
+
model = h_set_trigger(trigger)
|
82
|
+
storage = model.storages.first
|
83
|
+
model.perform!
|
84
|
+
package = model.package
|
85
|
+
package.filenames.count.should == 1
|
86
|
+
packages << package
|
87
|
+
|
88
|
+
check_remote_for(storage, packages[2])
|
89
|
+
clean_remote!(storage, packages[2])
|
90
|
+
|
91
|
+
check_remote_for(storage, packages[1])
|
92
|
+
clean_remote!(storage, packages[1])
|
93
|
+
|
94
|
+
check_remote_for(storage, packages[0], false)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
context 'when an archive to be removed does not exist' do
|
99
|
+
it 'should log a warning and continue' do
|
100
|
+
packages = []
|
101
|
+
|
102
|
+
model = h_set_trigger(trigger)
|
103
|
+
storage = model.storages.first
|
104
|
+
model.perform!
|
105
|
+
package = model.package
|
106
|
+
package.filenames.count.should == 1
|
107
|
+
packages << package
|
108
|
+
sleep 1
|
109
|
+
|
110
|
+
check_remote_for(storage, packages[0])
|
111
|
+
|
112
|
+
model = h_set_trigger(trigger)
|
113
|
+
storage = model.storages.first
|
114
|
+
model.perform!
|
115
|
+
package = model.package
|
116
|
+
package.filenames.count.should == 1
|
117
|
+
packages << package
|
118
|
+
|
119
|
+
check_remote_for(storage, packages[1])
|
120
|
+
|
121
|
+
# remove archive directory cycle! will attempt to remove
|
122
|
+
clean_remote!(storage, packages[0])
|
123
|
+
|
124
|
+
check_remote_for(storage, packages[0], false)
|
125
|
+
|
126
|
+
check_remote_for(storage, packages[1])
|
127
|
+
|
128
|
+
|
129
|
+
model = h_set_trigger(trigger)
|
130
|
+
storage = model.storages.first
|
131
|
+
expect do
|
132
|
+
model.perform!
|
133
|
+
end.not_to raise_error
|
134
|
+
|
135
|
+
Backup::Logger.has_warnings?.should be_true
|
136
|
+
|
137
|
+
package = model.package
|
138
|
+
package.filenames.count.should == 1
|
139
|
+
packages << package
|
140
|
+
|
141
|
+
check_remote_for(storage, packages[1])
|
142
|
+
clean_remote!(storage, packages[1])
|
143
|
+
|
144
|
+
check_remote_for(storage, packages[2])
|
145
|
+
clean_remote!(storage, packages[2])
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
end # describe 'Storage::SCP Cycling'
|
150
|
+
|
151
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require File.expand_path('../../spec_helper.rb', __FILE__)
|
4
|
+
|
5
|
+
describe 'Storage::Local' do
|
6
|
+
let(:trigger) { 'archive_local' }
|
7
|
+
|
8
|
+
def archive_file_for(model)
|
9
|
+
File.join(
|
10
|
+
Backup::SpecLive::TMP_PATH,
|
11
|
+
"#{model.trigger}", model.time, "#{model.trigger}.tar"
|
12
|
+
)
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should store a local archive' do
|
16
|
+
model = h_set_trigger(trigger)
|
17
|
+
model.perform!
|
18
|
+
File.exist?(archive_file_for(model)).should be_true
|
19
|
+
end
|
20
|
+
|
21
|
+
describe 'Storage::Local Cycling' do
|
22
|
+
|
23
|
+
context 'when archives exceed `keep` setting' do
|
24
|
+
it 'should remove the oldest archive' do
|
25
|
+
archives = []
|
26
|
+
|
27
|
+
model = h_set_trigger(trigger)
|
28
|
+
model.perform!
|
29
|
+
archives << archive_file_for(model)
|
30
|
+
sleep 1
|
31
|
+
|
32
|
+
model = h_set_trigger(trigger)
|
33
|
+
model.perform!
|
34
|
+
archives << archive_file_for(model)
|
35
|
+
sleep 1
|
36
|
+
|
37
|
+
model = h_set_trigger(trigger)
|
38
|
+
model.perform!
|
39
|
+
archives << archive_file_for(model)
|
40
|
+
|
41
|
+
File.exist?(archives[0]).should be_false
|
42
|
+
File.exist?(archives[1]).should be_true
|
43
|
+
File.exist?(archives[2]).should be_true
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
context 'when an archive to be removed does not exist' do
|
48
|
+
it 'should log a warning and continue' do
|
49
|
+
archives = []
|
50
|
+
|
51
|
+
model = h_set_trigger(trigger)
|
52
|
+
model.perform!
|
53
|
+
archives << archive_file_for(model)
|
54
|
+
sleep 1
|
55
|
+
|
56
|
+
model = h_set_trigger(trigger)
|
57
|
+
model.perform!
|
58
|
+
archives << archive_file_for(model)
|
59
|
+
sleep 1
|
60
|
+
|
61
|
+
File.exist?(archives[0]).should be_true
|
62
|
+
File.exist?(archives[1]).should be_true
|
63
|
+
# remove archive directory cycle! will attempt to remove
|
64
|
+
dir = archives[0].split('/')[0...-1].join('/')
|
65
|
+
h_safety_check(dir)
|
66
|
+
FileUtils.rm_r(dir)
|
67
|
+
File.exist?(archives[0]).should be_false
|
68
|
+
|
69
|
+
expect do
|
70
|
+
model = h_set_trigger(trigger)
|
71
|
+
model.perform!
|
72
|
+
archives << archive_file_for(model)
|
73
|
+
end.not_to raise_error
|
74
|
+
|
75
|
+
Backup::Logger.has_warnings?.should be_true
|
76
|
+
|
77
|
+
File.exist?(archives[1]).should be_true
|
78
|
+
File.exist?(archives[2]).should be_true
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
end # describe 'Storage::Local Cycling'
|
83
|
+
end
|
@@ -0,0 +1,193 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require File.expand_path('../../spec_helper.rb', __FILE__)
|
4
|
+
|
5
|
+
describe 'Storage::SCP',
|
6
|
+
:if => Backup::SpecLive::CONFIG['storage']['scp']['specs_enabled'] do
|
7
|
+
let(:trigger) { 'archive_scp' }
|
8
|
+
|
9
|
+
def remote_files_for(storage, package)
|
10
|
+
remote_path = storage.send(:remote_path_for, package)
|
11
|
+
|
12
|
+
files = []
|
13
|
+
storage.send(:transferred_files_for, package) do |local_file, remote_file|
|
14
|
+
files << File.join(remote_path, remote_file)
|
15
|
+
end
|
16
|
+
files
|
17
|
+
end
|
18
|
+
|
19
|
+
def check_remote_for(storage, files)
|
20
|
+
if (storage.username == Backup::Config.user) &&
|
21
|
+
(storage.ip == 'localhost')
|
22
|
+
files.each do |file|
|
23
|
+
if !File.exist?(file)
|
24
|
+
return false
|
25
|
+
end
|
26
|
+
end
|
27
|
+
true
|
28
|
+
else
|
29
|
+
errors = []
|
30
|
+
storage.send(:connection) do |ssh|
|
31
|
+
files.each do |file|
|
32
|
+
ssh.exec!("ls '#{file}'") do |ch, stream, data|
|
33
|
+
errors << data if stream == :stderr
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
errors.empty?
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def clean_remote!(storage, package)
|
42
|
+
return if (storage.username == Backup::Config.user) &&
|
43
|
+
(storage.ip == 'localhost') &&
|
44
|
+
(storage.path == Backup::SpecLive::TMP_PATH)
|
45
|
+
|
46
|
+
remote_path = storage.send(:remote_path_for, package)
|
47
|
+
h_safety_check(remote_path)
|
48
|
+
storage.send(:connection) do |ssh|
|
49
|
+
ssh.exec!("rm -r '#{remote_path}'")
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'should store the archive on the remote' do
|
54
|
+
model = h_set_trigger(trigger)
|
55
|
+
|
56
|
+
model.perform!
|
57
|
+
|
58
|
+
storage = model.storages.first
|
59
|
+
package = model.package
|
60
|
+
files = remote_files_for(storage, package)
|
61
|
+
files.count.should == 1
|
62
|
+
|
63
|
+
check_remote_for(storage, files).should be_true
|
64
|
+
|
65
|
+
clean_remote!(storage, package)
|
66
|
+
end
|
67
|
+
|
68
|
+
describe 'Storage::SCP Cycling' do
|
69
|
+
context 'when archives exceed `keep` setting' do
|
70
|
+
it 'should remove the oldest archive' do
|
71
|
+
packages = []
|
72
|
+
|
73
|
+
model = h_set_trigger(trigger)
|
74
|
+
storage = model.storages.first
|
75
|
+
model.perform!
|
76
|
+
package = model.package
|
77
|
+
package.filenames.count.should == 1
|
78
|
+
packages << package
|
79
|
+
sleep 1
|
80
|
+
|
81
|
+
check_remote_for(
|
82
|
+
storage, remote_files_for(storage, packages[0])
|
83
|
+
).should be_true
|
84
|
+
|
85
|
+
model = h_set_trigger(trigger)
|
86
|
+
storage = model.storages.first
|
87
|
+
model.perform!
|
88
|
+
package = model.package
|
89
|
+
package.filenames.count.should == 1
|
90
|
+
packages << package
|
91
|
+
sleep 1
|
92
|
+
|
93
|
+
check_remote_for(
|
94
|
+
storage, remote_files_for(storage, packages[1])
|
95
|
+
).should be_true
|
96
|
+
|
97
|
+
model = h_set_trigger(trigger)
|
98
|
+
storage = model.storages.first
|
99
|
+
model.perform!
|
100
|
+
package = model.package
|
101
|
+
package.filenames.count.should == 1
|
102
|
+
packages << package
|
103
|
+
|
104
|
+
check_remote_for(
|
105
|
+
storage, remote_files_for(storage, packages[2])
|
106
|
+
).should be_true
|
107
|
+
clean_remote!(storage, packages[2])
|
108
|
+
|
109
|
+
check_remote_for(
|
110
|
+
storage, remote_files_for(storage, packages[1])
|
111
|
+
).should be_true
|
112
|
+
clean_remote!(storage, packages[1])
|
113
|
+
|
114
|
+
check_remote_for(
|
115
|
+
storage, remote_files_for(storage, packages[0])
|
116
|
+
).should be_false
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
context 'when an archive to be removed does not exist' do
|
121
|
+
it 'should log a warning and continue' do
|
122
|
+
packages = []
|
123
|
+
|
124
|
+
model = h_set_trigger(trigger)
|
125
|
+
storage = model.storages.first
|
126
|
+
model.perform!
|
127
|
+
package = model.package
|
128
|
+
package.filenames.count.should == 1
|
129
|
+
packages << package
|
130
|
+
sleep 1
|
131
|
+
|
132
|
+
check_remote_for(
|
133
|
+
storage, remote_files_for(storage, packages[0])
|
134
|
+
).should be_true
|
135
|
+
|
136
|
+
model = h_set_trigger(trigger)
|
137
|
+
storage = model.storages.first
|
138
|
+
model.perform!
|
139
|
+
package = model.package
|
140
|
+
package.filenames.count.should == 1
|
141
|
+
packages << package
|
142
|
+
|
143
|
+
check_remote_for(
|
144
|
+
storage, remote_files_for(storage, packages[1])
|
145
|
+
).should be_true
|
146
|
+
|
147
|
+
# remove archive directory cycle! will attempt to remove
|
148
|
+
|
149
|
+
if (storage.username == Backup::Config.user) &&
|
150
|
+
(storage.ip == 'localhost')
|
151
|
+
remote_path = storage.send(:remote_path_for, packages[0])
|
152
|
+
h_safety_check(remote_path)
|
153
|
+
FileUtils.rm_r(remote_path)
|
154
|
+
else
|
155
|
+
clean_remote!(storage, packages[0])
|
156
|
+
end
|
157
|
+
|
158
|
+
check_remote_for(
|
159
|
+
storage, remote_files_for(storage, packages[0])
|
160
|
+
).should be_false
|
161
|
+
|
162
|
+
check_remote_for(
|
163
|
+
storage, remote_files_for(storage, packages[1])
|
164
|
+
).should be_true
|
165
|
+
|
166
|
+
|
167
|
+
model = h_set_trigger(trigger)
|
168
|
+
storage = model.storages.first
|
169
|
+
expect do
|
170
|
+
model.perform!
|
171
|
+
end.not_to raise_error
|
172
|
+
|
173
|
+
Backup::Logger.has_warnings?.should be_true
|
174
|
+
|
175
|
+
package = model.package
|
176
|
+
package.filenames.count.should == 1
|
177
|
+
packages << package
|
178
|
+
|
179
|
+
check_remote_for(
|
180
|
+
storage, remote_files_for(storage, packages[1])
|
181
|
+
).should be_true
|
182
|
+
clean_remote!(storage, packages[1])
|
183
|
+
|
184
|
+
check_remote_for(
|
185
|
+
storage, remote_files_for(storage, packages[2])
|
186
|
+
).should be_true
|
187
|
+
clean_remote!(storage, packages[2])
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
end # describe 'Storage::SCP Cycling'
|
192
|
+
|
193
|
+
end
|
@@ -0,0 +1,124 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require File.expand_path('../../../spec_helper.rb', __FILE__)
|
4
|
+
|
5
|
+
describe 'Syncer::Cloud::S3 - No Concurrency',
|
6
|
+
:if => Backup::SpecLive::CONFIG['syncer']['cloud']['s3']['specs_enabled'] do
|
7
|
+
let(:trigger) { 'syncer_cloud_s3' }
|
8
|
+
let(:model) { h_set_trigger(trigger) }
|
9
|
+
|
10
|
+
before do
|
11
|
+
model # trigger model initialization so Fog is available
|
12
|
+
create_sync_files
|
13
|
+
clean_remote
|
14
|
+
end
|
15
|
+
|
16
|
+
after do
|
17
|
+
clean_sync_dir
|
18
|
+
clean_remote
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'should work' do
|
22
|
+
model.perform!
|
23
|
+
remote_files.map {|file| [file.key, file.etag] }.sort.should == [
|
24
|
+
["backups/dir_a/one.file", "d3b07384d113edec49eaa6238ad5ff00"],
|
25
|
+
["backups/dir_b/dir_c/three.file", "d3b07384d113edec49eaa6238ad5ff00"],
|
26
|
+
["backups/dir_b/two.file", "d3b07384d113edec49eaa6238ad5ff00"]
|
27
|
+
]
|
28
|
+
|
29
|
+
update_sync_files
|
30
|
+
|
31
|
+
model.perform!
|
32
|
+
remote_files.map {|file| [file.key, file.etag] }.sort.should == [
|
33
|
+
["backups/dir_a/dir_d/two.new", "14758f1afd44c09b7992073ccf00b43d"],
|
34
|
+
["backups/dir_a/one.file", "14758f1afd44c09b7992073ccf00b43d"],
|
35
|
+
["backups/dir_b/dir_c/three.file", "d3b07384d113edec49eaa6238ad5ff00"],
|
36
|
+
["backups/dir_b/one.new", "14758f1afd44c09b7992073ccf00b43d"]
|
37
|
+
]
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
##
|
43
|
+
# Initial Files are MD5: d3b07384d113edec49eaa6238ad5ff00
|
44
|
+
#
|
45
|
+
# ├── dir_a
|
46
|
+
# │ └── one.file
|
47
|
+
# └── dir_b
|
48
|
+
# ├── dir_c
|
49
|
+
# │ └── three.file
|
50
|
+
# ├── bad\xFFfile
|
51
|
+
# └── two.file
|
52
|
+
def create_sync_files
|
53
|
+
clean_sync_dir
|
54
|
+
|
55
|
+
%w{ dir_a dir_b/dir_c }.each do |dir|
|
56
|
+
path = File.join(Backup::SpecLive::SYNC_PATH, dir)
|
57
|
+
FileUtils.mkdir_p(path)
|
58
|
+
end
|
59
|
+
|
60
|
+
%W{ dir_a/one.file
|
61
|
+
dir_b/two.file
|
62
|
+
dir_b/bad\xFFfile
|
63
|
+
dir_b/dir_c/three.file }.each do |file|
|
64
|
+
path = File.join(Backup::SpecLive::SYNC_PATH, file)
|
65
|
+
File.open(path, 'w') {|file| file.puts 'foo' }
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
##
|
70
|
+
# Added/Updated Files are MD5: 14758f1afd44c09b7992073ccf00b43d
|
71
|
+
#
|
72
|
+
# ├── dir_a
|
73
|
+
# │ ├── dir_d (add)
|
74
|
+
# │ │ └── two.new (add)
|
75
|
+
# │ └── one.file (update)
|
76
|
+
# └── dir_b
|
77
|
+
# ├── dir_c
|
78
|
+
# │ └── three.file
|
79
|
+
# ├── bad\377file
|
80
|
+
# ├── one.new (add)
|
81
|
+
# └── two.file (remove)
|
82
|
+
def update_sync_files
|
83
|
+
FileUtils.mkdir_p(File.join(Backup::SpecLive::SYNC_PATH, 'dir_a/dir_d'))
|
84
|
+
%w{ dir_a/one.file
|
85
|
+
dir_b/one.new
|
86
|
+
dir_a/dir_d/two.new }.each do |file|
|
87
|
+
path = File.join(Backup::SpecLive::SYNC_PATH, file)
|
88
|
+
File.open(path, 'w') {|file| file.puts 'foobar' }
|
89
|
+
end
|
90
|
+
|
91
|
+
path = File.join(Backup::SpecLive::SYNC_PATH, 'dir_b/two.file')
|
92
|
+
h_safety_check(path)
|
93
|
+
FileUtils.rm(path)
|
94
|
+
end
|
95
|
+
|
96
|
+
def clean_sync_dir
|
97
|
+
path = Backup::SpecLive::SYNC_PATH
|
98
|
+
if File.directory?(path)
|
99
|
+
h_safety_check(path)
|
100
|
+
FileUtils.rm_r(path)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
# use a new connection for each request
|
105
|
+
def connection
|
106
|
+
@opts = Backup::SpecLive::CONFIG['syncer']['cloud']['s3']
|
107
|
+
Fog::Storage.new(
|
108
|
+
:provider => 'AWS',
|
109
|
+
:aws_access_key_id => @opts['access_key_id'],
|
110
|
+
:aws_secret_access_key => @opts['secret_access_key'],
|
111
|
+
:region => @opts['region']
|
112
|
+
)
|
113
|
+
end
|
114
|
+
|
115
|
+
def remote_files
|
116
|
+
bucket = connection.directories.get(@opts['bucket'])
|
117
|
+
bucket.files.all(:prefix => 'backups')
|
118
|
+
end
|
119
|
+
|
120
|
+
def clean_remote
|
121
|
+
remote_files.each {|file| file.destroy }
|
122
|
+
end
|
123
|
+
|
124
|
+
end
|