backup 3.0.27 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (166) hide show
  1. data/LICENSE.md +1 -1
  2. data/README.md +139 -386
  3. data/bin/backup +1 -7
  4. data/lib/backup.rb +3 -9
  5. data/lib/backup/archive.rb +26 -20
  6. data/lib/backup/cleaner.rb +2 -2
  7. data/lib/backup/cli.rb +366 -0
  8. data/lib/backup/compressor/base.rb +2 -2
  9. data/lib/backup/compressor/gzip.rb +35 -1
  10. data/lib/backup/config.rb +1 -2
  11. data/lib/backup/database/base.rb +2 -2
  12. data/lib/backup/database/mongodb.rb +3 -3
  13. data/lib/backup/database/mysql.rb +3 -2
  14. data/lib/backup/database/postgresql.rb +3 -2
  15. data/lib/backup/database/riak.rb +18 -5
  16. data/lib/backup/dependency.rb +144 -93
  17. data/lib/backup/encryptor/base.rb +2 -2
  18. data/lib/backup/logger.rb +108 -110
  19. data/lib/backup/logger/console.rb +51 -0
  20. data/lib/backup/logger/logfile.rb +113 -0
  21. data/lib/backup/logger/syslog.rb +116 -0
  22. data/lib/backup/model.rb +67 -65
  23. data/lib/backup/notifier/base.rb +1 -1
  24. data/lib/backup/notifier/hipchat.rb +1 -1
  25. data/lib/backup/notifier/mail.rb +1 -1
  26. data/lib/backup/notifier/pushover.rb +6 -3
  27. data/lib/backup/packager.rb +4 -4
  28. data/lib/backup/pipeline.rb +17 -3
  29. data/lib/backup/splitter.rb +2 -2
  30. data/lib/backup/storage/base.rb +2 -2
  31. data/lib/backup/storage/cloudfiles.rb +2 -2
  32. data/lib/backup/storage/dropbox.rb +4 -4
  33. data/lib/backup/storage/ftp.rb +2 -2
  34. data/lib/backup/storage/local.rb +2 -2
  35. data/lib/backup/storage/ninefold.rb +2 -2
  36. data/lib/backup/storage/rsync.rb +3 -3
  37. data/lib/backup/storage/s3.rb +2 -2
  38. data/lib/backup/storage/scp.rb +2 -6
  39. data/lib/backup/storage/sftp.rb +2 -5
  40. data/lib/backup/syncer/base.rb +1 -1
  41. data/lib/backup/syncer/cloud/base.rb +15 -8
  42. data/lib/backup/syncer/rsync/local.rb +1 -1
  43. data/lib/backup/syncer/rsync/pull.rb +1 -1
  44. data/lib/backup/syncer/rsync/push.rb +1 -1
  45. data/lib/backup/utilities.rb +211 -0
  46. data/lib/backup/version.rb +1 -1
  47. data/templates/cli/{utility/archive → archive} +4 -8
  48. data/templates/cli/{utility/compressor → compressor}/bzip2 +0 -0
  49. data/templates/cli/{utility/compressor → compressor}/custom +0 -0
  50. data/templates/cli/{utility/compressor → compressor}/gzip +0 -0
  51. data/templates/cli/{utility/compressor → compressor}/lzma +0 -0
  52. data/templates/cli/{utility/compressor → compressor}/pbzip2 +0 -0
  53. data/templates/cli/config +68 -0
  54. data/templates/cli/{utility/database → database}/mongodb +1 -1
  55. data/templates/cli/{utility/database → database}/mysql +1 -1
  56. data/templates/cli/{utility/database → database}/postgresql +1 -1
  57. data/templates/cli/{utility/database → database}/redis +0 -0
  58. data/templates/cli/database/riak +20 -0
  59. data/templates/cli/{utility/encryptor → encryptor}/gpg +0 -0
  60. data/templates/cli/{utility/encryptor → encryptor}/openssl +0 -0
  61. data/templates/cli/{utility/model.erb → model.erb} +4 -4
  62. data/templates/cli/{utility/notifier → notifier}/campfire +0 -0
  63. data/templates/cli/{utility/notifier → notifier}/hipchat +0 -0
  64. data/templates/cli/{utility/notifier → notifier}/mail +0 -0
  65. data/templates/cli/{utility/notifier → notifier}/prowl +0 -0
  66. data/templates/cli/{utility/notifier → notifier}/pushover +0 -0
  67. data/templates/cli/{utility/notifier → notifier}/twitter +0 -0
  68. data/templates/cli/{utility/splitter → splitter} +0 -0
  69. data/templates/cli/{utility/storage → storage}/cloud_files +0 -0
  70. data/templates/cli/{utility/storage → storage}/dropbox +0 -0
  71. data/templates/cli/{utility/storage → storage}/ftp +0 -0
  72. data/templates/cli/{utility/storage → storage}/local +0 -0
  73. data/templates/cli/{utility/storage → storage}/ninefold +0 -0
  74. data/templates/cli/{utility/storage → storage}/rsync +0 -0
  75. data/templates/cli/{utility/storage → storage}/s3 +0 -0
  76. data/templates/cli/{utility/storage → storage}/scp +0 -0
  77. data/templates/cli/{utility/storage → storage}/sftp +0 -0
  78. data/templates/cli/{utility/syncer → syncer}/cloud_files +0 -0
  79. data/templates/cli/{utility/syncer → syncer}/rsync_local +0 -0
  80. data/templates/cli/{utility/syncer → syncer}/rsync_pull +0 -0
  81. data/templates/cli/{utility/syncer → syncer}/rsync_push +0 -0
  82. data/templates/cli/{utility/syncer → syncer}/s3 +0 -0
  83. metadata +55 -131
  84. data/.gitignore +0 -8
  85. data/.travis.yml +0 -10
  86. data/Gemfile +0 -28
  87. data/Guardfile +0 -23
  88. data/backup.gemspec +0 -32
  89. data/lib/backup/cli/helpers.rb +0 -93
  90. data/lib/backup/cli/utility.rb +0 -255
  91. data/spec-live/.gitignore +0 -6
  92. data/spec-live/README +0 -7
  93. data/spec-live/backups/config.rb +0 -83
  94. data/spec-live/backups/config.yml.template +0 -46
  95. data/spec-live/backups/models.rb +0 -184
  96. data/spec-live/compressor/custom_spec.rb +0 -30
  97. data/spec-live/compressor/gzip_spec.rb +0 -30
  98. data/spec-live/encryptor/gpg_keys.rb +0 -239
  99. data/spec-live/encryptor/gpg_spec.rb +0 -287
  100. data/spec-live/notifier/mail_spec.rb +0 -121
  101. data/spec-live/spec_helper.rb +0 -151
  102. data/spec-live/storage/dropbox_spec.rb +0 -151
  103. data/spec-live/storage/local_spec.rb +0 -83
  104. data/spec-live/storage/scp_spec.rb +0 -193
  105. data/spec-live/syncer/cloud/s3_spec.rb +0 -124
  106. data/spec/archive_spec.rb +0 -335
  107. data/spec/cleaner_spec.rb +0 -312
  108. data/spec/cli/helpers_spec.rb +0 -301
  109. data/spec/cli/utility_spec.rb +0 -411
  110. data/spec/compressor/base_spec.rb +0 -52
  111. data/spec/compressor/bzip2_spec.rb +0 -217
  112. data/spec/compressor/custom_spec.rb +0 -106
  113. data/spec/compressor/gzip_spec.rb +0 -217
  114. data/spec/compressor/lzma_spec.rb +0 -123
  115. data/spec/compressor/pbzip2_spec.rb +0 -165
  116. data/spec/config_spec.rb +0 -321
  117. data/spec/configuration/helpers_spec.rb +0 -247
  118. data/spec/configuration/store_spec.rb +0 -39
  119. data/spec/configuration_spec.rb +0 -62
  120. data/spec/database/base_spec.rb +0 -63
  121. data/spec/database/mongodb_spec.rb +0 -510
  122. data/spec/database/mysql_spec.rb +0 -411
  123. data/spec/database/postgresql_spec.rb +0 -353
  124. data/spec/database/redis_spec.rb +0 -334
  125. data/spec/database/riak_spec.rb +0 -176
  126. data/spec/dependency_spec.rb +0 -51
  127. data/spec/encryptor/base_spec.rb +0 -40
  128. data/spec/encryptor/gpg_spec.rb +0 -909
  129. data/spec/encryptor/open_ssl_spec.rb +0 -148
  130. data/spec/errors_spec.rb +0 -306
  131. data/spec/logger_spec.rb +0 -367
  132. data/spec/model_spec.rb +0 -666
  133. data/spec/notifier/base_spec.rb +0 -104
  134. data/spec/notifier/campfire_spec.rb +0 -217
  135. data/spec/notifier/hipchat_spec.rb +0 -211
  136. data/spec/notifier/mail_spec.rb +0 -316
  137. data/spec/notifier/prowl_spec.rb +0 -138
  138. data/spec/notifier/pushover_spec.rb +0 -123
  139. data/spec/notifier/twitter_spec.rb +0 -153
  140. data/spec/package_spec.rb +0 -61
  141. data/spec/packager_spec.rb +0 -213
  142. data/spec/pipeline_spec.rb +0 -259
  143. data/spec/spec_helper.rb +0 -60
  144. data/spec/splitter_spec.rb +0 -120
  145. data/spec/storage/base_spec.rb +0 -166
  146. data/spec/storage/cloudfiles_spec.rb +0 -254
  147. data/spec/storage/cycler_spec.rb +0 -247
  148. data/spec/storage/dropbox_spec.rb +0 -480
  149. data/spec/storage/ftp_spec.rb +0 -271
  150. data/spec/storage/local_spec.rb +0 -259
  151. data/spec/storage/ninefold_spec.rb +0 -343
  152. data/spec/storage/rsync_spec.rb +0 -362
  153. data/spec/storage/s3_spec.rb +0 -245
  154. data/spec/storage/scp_spec.rb +0 -233
  155. data/spec/storage/sftp_spec.rb +0 -244
  156. data/spec/syncer/base_spec.rb +0 -109
  157. data/spec/syncer/cloud/base_spec.rb +0 -515
  158. data/spec/syncer/cloud/cloud_files_spec.rb +0 -181
  159. data/spec/syncer/cloud/s3_spec.rb +0 -174
  160. data/spec/syncer/rsync/base_spec.rb +0 -98
  161. data/spec/syncer/rsync/local_spec.rb +0 -149
  162. data/spec/syncer/rsync/pull_spec.rb +0 -98
  163. data/spec/syncer/rsync/push_spec.rb +0 -333
  164. data/spec/version_spec.rb +0 -21
  165. data/templates/cli/utility/config +0 -32
  166. data/templates/cli/utility/database/riak +0 -11
@@ -1,254 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require File.expand_path('../../spec_helper.rb', __FILE__)
4
-
5
- describe Backup::Storage::CloudFiles do
6
- let(:model) { Backup::Model.new(:test_trigger, 'test label') }
7
- let(:storage) do
8
- Backup::Storage::CloudFiles.new(model) do |cf|
9
- cf.username = 'my_username'
10
- cf.api_key = 'my_api_key'
11
- cf.auth_url = 'lon.auth.api.rackspacecloud.com'
12
- cf.container = 'my_container'
13
- cf.keep = 5
14
- end
15
- end
16
-
17
- it 'should be a subclass of Storage::Base' do
18
- Backup::Storage::CloudFiles.
19
- superclass.should == Backup::Storage::Base
20
- end
21
-
22
- describe '#initialize' do
23
- after { Backup::Storage::CloudFiles.clear_defaults! }
24
-
25
- it 'should load pre-configured defaults through Base' do
26
- Backup::Storage::CloudFiles.any_instance.expects(:load_defaults!)
27
- storage
28
- end
29
-
30
- it 'should pass the model reference to Base' do
31
- storage.instance_variable_get(:@model).should == model
32
- end
33
-
34
- it 'should pass the storage_id to Base' do
35
- storage = Backup::Storage::CloudFiles.new(model, 'my_storage_id')
36
- storage.storage_id.should == 'my_storage_id'
37
- end
38
-
39
- context 'when no pre-configured defaults have been set' do
40
- it 'should use the values given' do
41
- storage.username.should == 'my_username'
42
- storage.api_key.should == 'my_api_key'
43
- storage.auth_url.should == 'lon.auth.api.rackspacecloud.com'
44
- storage.container.should == 'my_container'
45
- storage.servicenet.should == false
46
- storage.path.should == 'backups'
47
-
48
- storage.storage_id.should be_nil
49
- storage.keep.should == 5
50
- end
51
-
52
- it 'should use default values if none are given' do
53
- storage = Backup::Storage::CloudFiles.new(model)
54
-
55
- storage.username.should be_nil
56
- storage.api_key.should be_nil
57
- storage.auth_url.should be_nil
58
- storage.container.should be_nil
59
- storage.servicenet.should == false
60
- storage.path.should == 'backups'
61
-
62
- storage.storage_id.should be_nil
63
- storage.keep.should be_nil
64
- end
65
- end # context 'when no pre-configured defaults have been set'
66
-
67
- context 'when pre-configured defaults have been set' do
68
- before do
69
- Backup::Storage::CloudFiles.defaults do |s|
70
- s.username = 'some_username'
71
- s.api_key = 'some_api_key'
72
- s.auth_url = 'some_auth_url'
73
- s.container = 'some_container'
74
- s.servicenet = true
75
- s.path = 'some_path'
76
- s.keep = 15
77
- end
78
- end
79
-
80
- it 'should use pre-configured defaults' do
81
- storage = Backup::Storage::CloudFiles.new(model)
82
-
83
- storage.username.should == 'some_username'
84
- storage.api_key.should == 'some_api_key'
85
- storage.auth_url.should == 'some_auth_url'
86
- storage.container.should == 'some_container'
87
- storage.servicenet.should == true
88
- storage.path.should == 'some_path'
89
-
90
- storage.storage_id.should be_nil
91
- storage.keep.should == 15
92
- end
93
-
94
- it 'should override pre-configured defaults' do
95
- storage = Backup::Storage::CloudFiles.new(model) do |s|
96
- s.username = 'new_username'
97
- s.api_key = 'new_api_key'
98
- s.auth_url = 'new_auth_url'
99
- s.container = 'new_container'
100
- s.servicenet = false
101
- s.path = 'new_path'
102
- s.keep = 10
103
- end
104
-
105
- storage.username.should == 'new_username'
106
- storage.api_key.should == 'new_api_key'
107
- storage.auth_url.should == 'new_auth_url'
108
- storage.container.should == 'new_container'
109
- storage.servicenet.should == false
110
- storage.path.should == 'new_path'
111
-
112
- storage.storage_id.should be_nil
113
- storage.keep.should == 10
114
- end
115
- end # context 'when pre-configured defaults have been set'
116
- end # describe '#initialize'
117
-
118
- describe '#provider' do
119
- it 'should set the Fog provider' do
120
- storage.send(:provider).should == 'Rackspace'
121
- end
122
- end
123
-
124
- describe '#connection' do
125
- let(:connection) { mock }
126
-
127
- context 'when @servicenet is set to false' do
128
- it 'should create a new standard connection' do
129
- Fog::Storage.expects(:new).once.with(
130
- :provider => 'Rackspace',
131
- :rackspace_username => 'my_username',
132
- :rackspace_api_key => 'my_api_key',
133
- :rackspace_auth_url => 'lon.auth.api.rackspacecloud.com',
134
- :rackspace_servicenet => false
135
- ).returns(connection)
136
- storage.send(:connection).should == connection
137
- end
138
- end
139
-
140
- context 'when @servicenet is set to true' do
141
- before do
142
- storage.servicenet = true
143
- end
144
-
145
- it 'should create a new servicenet connection' do
146
- Fog::Storage.expects(:new).once.with(
147
- :provider => 'Rackspace',
148
- :rackspace_username => 'my_username',
149
- :rackspace_api_key => 'my_api_key',
150
- :rackspace_auth_url => 'lon.auth.api.rackspacecloud.com',
151
- :rackspace_servicenet => true
152
- ).returns(connection)
153
- storage.send(:connection).should == connection
154
- end
155
- end
156
-
157
- it 'should return an existing connection' do
158
- Fog::Storage.expects(:new).once.returns(connection)
159
- storage.send(:connection).should == connection
160
- storage.send(:connection).should == connection
161
- end
162
-
163
- end # describe '#connection'
164
-
165
- describe '#transfer!' do
166
- let(:connection) { mock }
167
- let(:package) { mock }
168
- let(:file) { mock }
169
- let(:s) { sequence '' }
170
-
171
- before do
172
- storage.instance_variable_set(:@package, package)
173
- storage.stubs(:storage_name).returns('Storage::CloudFiles')
174
- storage.stubs(:local_path).returns('/local/path')
175
- storage.stubs(:connection).returns(connection)
176
- end
177
-
178
- it 'should transfer the package files' do
179
- storage.expects(:remote_path_for).in_sequence(s).with(package).
180
- returns('remote/path')
181
- storage.expects(:files_to_transfer_for).in_sequence(s).with(package).
182
- multiple_yields(
183
- ['2011.12.31.11.00.02.backup.tar.enc-aa', 'backup.tar.enc-aa'],
184
- ['2011.12.31.11.00.02.backup.tar.enc-ab', 'backup.tar.enc-ab']
185
- )
186
- # first yield
187
- Backup::Logger.expects(:message).in_sequence(s).with(
188
- "Storage::CloudFiles started transferring " +
189
- "'2011.12.31.11.00.02.backup.tar.enc-aa'."
190
- )
191
- File.expects(:open).in_sequence(s).with(
192
- File.join('/local/path', '2011.12.31.11.00.02.backup.tar.enc-aa'), 'r'
193
- ).yields(file)
194
- connection.expects(:put_object).in_sequence(s).with(
195
- 'my_container', File.join('remote/path', 'backup.tar.enc-aa'), file
196
- )
197
- # second yield
198
- Backup::Logger.expects(:message).in_sequence(s).with(
199
- "Storage::CloudFiles started transferring " +
200
- "'2011.12.31.11.00.02.backup.tar.enc-ab'."
201
- )
202
- File.expects(:open).in_sequence(s).with(
203
- File.join('/local/path', '2011.12.31.11.00.02.backup.tar.enc-ab'), 'r'
204
- ).yields(file)
205
- connection.expects(:put_object).in_sequence(s).with(
206
- 'my_container', File.join('remote/path', 'backup.tar.enc-ab'), file
207
- )
208
-
209
- storage.send(:transfer!)
210
- end
211
- end # describe '#transfer!'
212
-
213
- describe '#remove!' do
214
- let(:package) { mock }
215
- let(:connection) { mock }
216
- let(:s) { sequence '' }
217
-
218
- before do
219
- storage.stubs(:storage_name).returns('Storage::CloudFiles')
220
- storage.stubs(:connection).returns(connection)
221
- end
222
-
223
- it 'should remove the package files' do
224
- storage.expects(:remote_path_for).in_sequence(s).with(package).
225
- returns('remote/path')
226
- storage.expects(:transferred_files_for).in_sequence(s).with(package).
227
- multiple_yields(
228
- ['2011.12.31.11.00.02.backup.tar.enc-aa', 'backup.tar.enc-aa'],
229
- ['2011.12.31.11.00.02.backup.tar.enc-ab', 'backup.tar.enc-ab']
230
- )
231
- # first yield
232
- Backup::Logger.expects(:message).in_sequence(s).with(
233
- "Storage::CloudFiles started removing " +
234
- "'2011.12.31.11.00.02.backup.tar.enc-aa' " +
235
- "from container 'my_container'."
236
- )
237
- connection.expects(:delete_object).in_sequence(s).with(
238
- 'my_container', File.join('remote/path', 'backup.tar.enc-aa')
239
- )
240
- # second yield
241
- Backup::Logger.expects(:message).in_sequence(s).with(
242
- "Storage::CloudFiles started removing " +
243
- "'2011.12.31.11.00.02.backup.tar.enc-ab' " +
244
- "from container 'my_container'."
245
- )
246
- connection.expects(:delete_object).in_sequence(s).with(
247
- 'my_container', File.join('remote/path', 'backup.tar.enc-ab')
248
- )
249
-
250
- storage.send(:remove!, package)
251
- end
252
- end # describe '#remove!'
253
-
254
- end
@@ -1,247 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require File.expand_path('../../spec_helper.rb', __FILE__)
4
-
5
- describe 'Backup::Storage::Cycler' do
6
- let(:cycler) { Backup::Storage::Cycler }
7
- let(:storage) { mock }
8
- let(:package) { mock }
9
- let(:storage_file) { mock }
10
- let(:pkg_a) { mock }
11
- let(:pkg_b) { mock }
12
- let(:pkg_c) { mock }
13
- let(:s) { sequence '' }
14
-
15
- describe '#cycle!' do
16
- it 'should setup variables and initiate cycling' do
17
- cycler.expects(:storage_file).in_sequence(s).returns(storage_file)
18
- cycler.expects(:update_storage_file!).in_sequence(s)
19
- cycler.expects(:remove_packages!).in_sequence(s)
20
- cycler.cycle!(storage, package)
21
- cycler.instance_variable_get(:@storage).should be(storage)
22
- cycler.instance_variable_get(:@package).should be(package)
23
- cycler.instance_variable_get(:@storage_file).should be(storage_file)
24
- end
25
- end
26
-
27
- describe 'update_storage_file!' do
28
- before do
29
- cycler.instance_variable_set(:@storage, storage)
30
- cycler.instance_variable_set(:@package, package)
31
- cycler.instance_variable_set(:@storage_file, storage_file)
32
- end
33
-
34
- it 'should remove entries and set @packages_to_remove' do
35
- storage.stubs(:keep).returns(2)
36
- cycler.expects(:yaml_load).in_sequence(s).returns([pkg_a, pkg_b, pkg_c])
37
- cycler.expects(:yaml_save).in_sequence(s).with([package, pkg_a])
38
- cycler.send(:update_storage_file!)
39
- cycler.instance_variable_get(:@packages_to_remove).should == [pkg_b, pkg_c]
40
- end
41
-
42
- it 'should typecast the value of keep' do
43
- storage.stubs(:keep).returns('2')
44
- cycler.expects(:yaml_load).in_sequence(s).returns([pkg_a, pkg_b, pkg_c])
45
- cycler.expects(:yaml_save).in_sequence(s).with([package, pkg_a])
46
- cycler.send(:update_storage_file!)
47
- cycler.instance_variable_get(:@packages_to_remove).should == [pkg_b, pkg_c]
48
- end
49
- end
50
-
51
- describe '#remove_packages!' do
52
- before do
53
- cycler.instance_variable_set(:@storage, storage)
54
- cycler.instance_variable_set(:@packages_to_remove, [pkg_a, pkg_b, pkg_c])
55
- end
56
-
57
- it 'should call the @storage to remove the old packages' do
58
- storage.expects(:remove!).in_sequence(s).with(pkg_a)
59
- storage.expects(:remove!).in_sequence(s).with(pkg_b)
60
- storage.expects(:remove!).in_sequence(s).with(pkg_c)
61
- cycler.send(:remove_packages!)
62
- end
63
-
64
- context 'when errors occur removing packages' do
65
- before do
66
- pkg_b.stubs(:trigger).returns('pkg_trigger')
67
- pkg_b.stubs(:time).returns('pkg_time')
68
- pkg_b.stubs(:filenames).returns(['file1', 'file2'])
69
- end
70
-
71
- it 'should warn and continue' do
72
- storage.expects(:remove!).in_sequence(s).with(pkg_a)
73
- storage.expects(:remove!).in_sequence(s).with(pkg_b).raises('error message')
74
- Backup::Logger.expects(:warn).with do |err|
75
- err.should be_an_instance_of Backup::Errors::Storage::CyclerError
76
- err.message.should == 'Storage::CyclerError: ' +
77
- "There was a problem removing the following package:\n" +
78
- " Trigger: pkg_trigger :: Dated: pkg_time\n" +
79
- " Package included the following 2 file(s):\n" +
80
- " file1\n" +
81
- " file2\n" +
82
- " Reason: RuntimeError\n" +
83
- " error message"
84
- end
85
- storage.expects(:remove!).in_sequence(s).with(pkg_c)
86
-
87
- expect do
88
- cycler.send(:remove_packages!)
89
- end.not_to raise_error
90
- end
91
- end
92
-
93
- end # describe '#remove_packages!'
94
-
95
- describe '#storage_file' do
96
- before do
97
- cycler.instance_variable_set(:@storage, storage)
98
- storage.stubs(:class).returns('Backup::Storage::S3')
99
- cycler.instance_variable_set(:@package, package)
100
- package.stubs(:trigger).returns('pkg_trigger')
101
- end
102
-
103
- context 'when the @storage.storage_id is not set' do
104
- before { storage.stubs(:storage_id).returns(nil) }
105
- it 'should return the path to the YAML storage file with no suffix' do
106
- cycler.send(:storage_file).should ==
107
- File.join(Backup::Config.data_path, 'pkg_trigger', 'S3.yml')
108
- end
109
- end
110
-
111
- context 'when the @storage.storage_id is set' do
112
- before { storage.stubs(:storage_id).returns('Storage #1') }
113
- it 'should sanitize the storage_id to use as a filename suffix' do
114
- cycler.send(:storage_file).should ==
115
- File.join(Backup::Config.data_path, 'pkg_trigger', 'S3-Storage__1.yml')
116
- end
117
- end
118
-
119
- end # describe '#storage_file'
120
-
121
- describe '#yaml_load' do
122
- let(:obj_a) { mock }
123
- let(:obj_b) { mock }
124
- let(:obj_c) { mock }
125
- let(:unsorted_objects) { [obj_a, obj_c, obj_b] }
126
- let(:sorted_objects) { [obj_c, obj_b, obj_a] }
127
-
128
- before do
129
- cycler.instance_variable_set(:@storage_file, storage_file)
130
- obj_a.instance_variable_set(:@time, '2012.01.01.07.00.00')
131
- obj_b.instance_variable_set(:@time, '2012.01.01.08.00.00')
132
- obj_c.instance_variable_set(:@time, '2012.01.01.09.00.00')
133
- end
134
-
135
- context 'when the storage file exists' do
136
- before { File.expects(:exist?).with(storage_file).returns(true) }
137
- context 'when the file is not empty' do
138
- before { File.expects(:zero?).with(storage_file).returns(false) }
139
- it 'should return YAML deserialized objects in an array, sorted by time DESC' do
140
- YAML.expects(:load_file).with(storage_file).returns(unsorted_objects)
141
- cycler.expects(:check_upgrade).with(sorted_objects).returns(sorted_objects)
142
- cycler.send(:yaml_load).should be(sorted_objects)
143
- end
144
- end
145
- context 'when the file is empty' do
146
- before { File.expects(:zero?).with(storage_file).returns(true) }
147
- it 'should return an empty array' do
148
- cycler.send(:yaml_load).should == []
149
- end
150
- end
151
- end
152
-
153
- context 'when the storage file does not exist' do
154
- before { File.expects(:exist?).with(storage_file).returns(false) }
155
- it 'should return an empty array' do
156
- cycler.send(:yaml_load).should == []
157
- end
158
- end
159
- end # describe '#yaml_load'
160
-
161
- describe '#yaml_save' do
162
- let(:file) { mock }
163
- let(:pkgs) { [ [1, 2, 3], [4, 5, 6] ] }
164
- let(:pkgs_to_yaml) { pkgs.to_yaml }
165
-
166
- it 'should save the given packages to the storage file in YAML format' do
167
- cycler.instance_variable_set(:@storage_file, storage_file)
168
- File.expects(:open).with(storage_file, 'w').yields(file)
169
- file.expects(:write).with(pkgs_to_yaml)
170
- cycler.send(:yaml_save, pkgs)
171
- end
172
- end # describe '#yaml_save'
173
-
174
- describe '#check_upgrade' do
175
- let(:yaml_v3_0_19) do
176
- <<-EOF.gsub(/^ +/,' ').gsub(/^ (-\W\W)/, "\\1")
177
- ---
178
- - !ruby/object:Backup::Storage::Local
179
- time: 2011.11.01.12.01.00
180
- remote_file: 2011.11.01.12.01.00.backup.tar.gz
181
- - !ruby/object:Backup::Storage::Local
182
- time: 2011.11.01.12.02.00
183
- remote_file: 2011.11.01.12.02.00.backup.tar.gz
184
- - !ruby/object:Backup::Storage::Local
185
- time: 2011.11.01.12.03.00
186
- remote_file: 2011.11.01.12.03.00.backup.tar.gz
187
- EOF
188
- end
189
- let(:yaml_v3_0_20) do
190
- <<-EOF.gsub(/^ +/,' ').gsub(/^ (-\W\W)/, "\\1")
191
- ---
192
- - !ruby/object:Backup::Storage::Local
193
- time: 2011.12.01.12.01.00
194
- chunk_suffixes: []
195
- filename: 2011.12.01.12.01.00.backup.tar.gz
196
- version: 3.0.20
197
- - !ruby/object:Backup::Storage::Local
198
- time: 2011.12.01.12.02.00
199
- chunk_suffixes: []
200
- filename: 2011.12.01.12.02.00.backup.tar.gz
201
- version: 3.0.20
202
- - !ruby/object:Backup::Storage::Local
203
- time: 2011.12.01.12.03.00
204
- chunk_suffixes:
205
- - aa
206
- - ab
207
- filename: 2011.12.01.12.03.00.backup.tar.gz
208
- version: 3.0.20
209
- EOF
210
- end
211
-
212
- before do
213
- model = Backup::Model.new('foo', 'foo')
214
- cycler.instance_variable_set(:@storage, storage)
215
- storage.instance_variable_set(:@model, model)
216
- end
217
-
218
- it 'should upgrade v3.0.20 objects' do
219
- objects = YAML.load(yaml_v3_0_20)
220
- packages = cycler.send(:check_upgrade, objects)
221
-
222
- packages.all? {|pkg| pkg.is_a? Backup::Package }.should be_true
223
- packages.all? {|pkg| pkg.extension == 'tar.gz' }.should be_true
224
-
225
- packages[0].time.should == '2011.12.01.12.01.00'
226
- packages[0].chunk_suffixes.should == []
227
- packages[1].time.should == '2011.12.01.12.02.00'
228
- packages[1].chunk_suffixes.should == []
229
- packages[2].time.should == '2011.12.01.12.03.00'
230
- packages[2].chunk_suffixes.should == ['aa', 'ab']
231
- end
232
-
233
- it 'should upgrade v3.0.19 objects' do
234
- objects = YAML.load(yaml_v3_0_19)
235
- packages = cycler.send(:check_upgrade, objects)
236
-
237
- packages.all? {|pkg| pkg.is_a? Backup::Package }.should be_true
238
- packages.all? {|pkg| pkg.extension == 'tar.gz' }.should be_true
239
- packages.all? {|pkg| pkg.chunk_suffixes == [] }.should be_true
240
-
241
- packages[0].time.should == '2011.11.01.12.01.00'
242
- packages[1].time.should == '2011.11.01.12.02.00'
243
- packages[2].time.should == '2011.11.01.12.03.00'
244
- end
245
- end # describe '#check_upgrade'
246
-
247
- end