backup 3.0.27 → 3.1.0

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.
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,271 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require File.expand_path('../../spec_helper.rb', __FILE__)
4
-
5
- describe Backup::Storage::FTP do
6
- let(:model) { Backup::Model.new(:test_trigger, 'test label') }
7
- let(:storage) do
8
- Backup::Storage::FTP.new(model) do |ftp|
9
- ftp.username = 'my_username'
10
- ftp.password = 'my_password'
11
- ftp.ip = '123.45.678.90'
12
- ftp.keep = 5
13
- end
14
- end
15
-
16
- it 'should be a subclass of Storage::Base' do
17
- Backup::Storage::FTP.
18
- superclass.should == Backup::Storage::Base
19
- end
20
-
21
- describe '#initialize' do
22
- after { Backup::Storage::FTP.clear_defaults! }
23
-
24
- it 'should load pre-configured defaults through Base' do
25
- Backup::Storage::FTP.any_instance.expects(:load_defaults!)
26
- storage
27
- end
28
-
29
- it 'should pass the model reference to Base' do
30
- storage.instance_variable_get(:@model).should == model
31
- end
32
-
33
- it 'should pass the storage_id to Base' do
34
- storage = Backup::Storage::FTP.new(model, 'my_storage_id')
35
- storage.storage_id.should == 'my_storage_id'
36
- end
37
-
38
- it 'should remove any preceeding tilde and slash from the path' do
39
- storage = Backup::Storage::FTP.new(model) do |ftp|
40
- ftp.path = '~/my_backups/path'
41
- end
42
- storage.path.should == 'my_backups/path'
43
- end
44
-
45
- context 'when no pre-configured defaults have been set' do
46
- it 'should use the values given' do
47
- storage.username.should == 'my_username'
48
- storage.password.should == 'my_password'
49
- storage.ip.should == '123.45.678.90'
50
- storage.port.should == 21
51
- storage.path.should == 'backups'
52
- storage.passive_mode.should == false
53
-
54
- storage.storage_id.should be_nil
55
- storage.keep.should == 5
56
- end
57
-
58
- it 'should use default values if none are given' do
59
- storage = Backup::Storage::FTP.new(model)
60
-
61
- storage.username.should be_nil
62
- storage.password.should be_nil
63
- storage.ip.should be_nil
64
- storage.port.should == 21
65
- storage.path.should == 'backups'
66
- storage.passive_mode.should == false
67
-
68
- storage.storage_id.should be_nil
69
- storage.keep.should be_nil
70
- end
71
- end # context 'when no pre-configured defaults have been set'
72
-
73
- context 'when pre-configured defaults have been set' do
74
- before do
75
- Backup::Storage::FTP.defaults do |s|
76
- s.username = 'some_username'
77
- s.password = 'some_password'
78
- s.ip = 'some_ip'
79
- s.port = 'some_port'
80
- s.path = 'some_path'
81
- s.passive_mode = 'some_passive_mode'
82
- s.keep = 'some_keep'
83
- end
84
- end
85
-
86
- it 'should use pre-configured defaults' do
87
- storage = Backup::Storage::FTP.new(model)
88
-
89
- storage.username.should == 'some_username'
90
- storage.password.should == 'some_password'
91
- storage.ip.should == 'some_ip'
92
- storage.port.should == 'some_port'
93
- storage.path.should == 'some_path'
94
- storage.passive_mode.should == 'some_passive_mode'
95
-
96
- storage.storage_id.should be_nil
97
- storage.keep.should == 'some_keep'
98
- end
99
-
100
- it 'should override pre-configured defaults' do
101
- storage = Backup::Storage::FTP.new(model) do |s|
102
- s.username = 'new_username'
103
- s.password = 'new_password'
104
- s.ip = 'new_ip'
105
- s.port = 'new_port'
106
- s.path = 'new_path'
107
- s.passive_mode = 'new_passive_mode'
108
- s.keep = 'new_keep'
109
- end
110
-
111
- storage.username.should == 'new_username'
112
- storage.password.should == 'new_password'
113
- storage.ip.should == 'new_ip'
114
- storage.port.should == 'new_port'
115
- storage.path.should == 'new_path'
116
- storage.passive_mode.should == 'new_passive_mode'
117
-
118
- storage.storage_id.should be_nil
119
- storage.keep.should == 'new_keep'
120
- end
121
- end # context 'when pre-configured defaults have been set'
122
- end # describe '#initialize'
123
-
124
- describe '#connection' do
125
- let(:connection) { mock }
126
-
127
- it 'should yield a connection to the remote server' do
128
- Net::FTP.expects(:open).with(
129
- '123.45.678.90', 'my_username', 'my_password'
130
- ).yields(connection)
131
-
132
- storage.send(:connection) do |ftp|
133
- ftp.should be(connection)
134
- end
135
- end
136
-
137
- it 'should set passive mode if @passive_mode is true' do
138
- storage.passive_mode = true
139
- Net::FTP.expects(:open).with(
140
- '123.45.678.90', 'my_username', 'my_password'
141
- ).yields(connection)
142
- connection.expects(:passive=).with(true)
143
-
144
- storage.send(:connection) do |ftp|
145
- ftp.should be(connection)
146
- end
147
- end
148
-
149
- it 'should set the Net::FTP_PORT constant' do
150
- storage.port = 40
151
- Net::FTP.expects(:const_defined?).with(:FTP_PORT).returns(true)
152
- Net::FTP.expects(:send).with(:remove_const, :FTP_PORT)
153
- Net::FTP.expects(:send).with(:const_set, :FTP_PORT, 40)
154
-
155
- Net::FTP.expects(:open)
156
- storage.send(:connection)
157
- end
158
-
159
- end # describe '#connection'
160
-
161
- describe '#transfer!' do
162
- let(:connection) { mock }
163
- let(:package) { mock }
164
- let(:s) { sequence '' }
165
-
166
- before do
167
- storage.instance_variable_set(:@package, package)
168
- storage.stubs(:storage_name).returns('Storage::FTP')
169
- storage.stubs(:local_path).returns('/local/path')
170
- storage.stubs(:connection).yields(connection)
171
- end
172
-
173
- it 'should transfer the package files' do
174
- storage.expects(:remote_path_for).in_sequence(s).with(package).
175
- returns('remote/path')
176
- storage.expects(:create_remote_path).in_sequence(s).with(
177
- 'remote/path', connection
178
- )
179
-
180
- storage.expects(:files_to_transfer_for).in_sequence(s).with(package).
181
- multiple_yields(
182
- ['2011.12.31.11.00.02.backup.tar.enc-aa', 'backup.tar.enc-aa'],
183
- ['2011.12.31.11.00.02.backup.tar.enc-ab', 'backup.tar.enc-ab']
184
- )
185
- # first yield
186
- Backup::Logger.expects(:message).in_sequence(s).with(
187
- "Storage::FTP started transferring " +
188
- "'2011.12.31.11.00.02.backup.tar.enc-aa' to '123.45.678.90'."
189
- )
190
- connection.expects(:put).in_sequence(s).with(
191
- File.join('/local/path', '2011.12.31.11.00.02.backup.tar.enc-aa'),
192
- File.join('remote/path', 'backup.tar.enc-aa')
193
- )
194
- # second yield
195
- Backup::Logger.expects(:message).in_sequence(s).with(
196
- "Storage::FTP started transferring " +
197
- "'2011.12.31.11.00.02.backup.tar.enc-ab' to '123.45.678.90'."
198
- )
199
- connection.expects(:put).in_sequence(s).with(
200
- File.join('/local/path', '2011.12.31.11.00.02.backup.tar.enc-ab'),
201
- File.join('remote/path', 'backup.tar.enc-ab')
202
- )
203
-
204
- storage.send(:transfer!)
205
- end
206
- end # describe '#transfer!'
207
-
208
- describe '#remove!' do
209
- let(:package) { mock }
210
- let(:connection) { mock }
211
- let(:s) { sequence '' }
212
-
213
- before do
214
- storage.stubs(:storage_name).returns('Storage::FTP')
215
- storage.stubs(:connection).yields(connection)
216
- end
217
-
218
- it 'should remove the package files' do
219
- storage.expects(:remote_path_for).in_sequence(s).with(package).
220
- returns('remote/path')
221
-
222
- storage.expects(:transferred_files_for).in_sequence(s).with(package).
223
- multiple_yields(
224
- ['2011.12.31.11.00.02.backup.tar.enc-aa', 'backup.tar.enc-aa'],
225
- ['2011.12.31.11.00.02.backup.tar.enc-ab', 'backup.tar.enc-ab']
226
- )
227
- # first yield
228
- Backup::Logger.expects(:message).in_sequence(s).with(
229
- "Storage::FTP started removing " +
230
- "'2011.12.31.11.00.02.backup.tar.enc-aa' from '123.45.678.90'."
231
- )
232
- connection.expects(:delete).in_sequence(s).with(
233
- File.join('remote/path', 'backup.tar.enc-aa')
234
- )
235
- # second yield
236
- Backup::Logger.expects(:message).in_sequence(s).with(
237
- "Storage::FTP started removing " +
238
- "'2011.12.31.11.00.02.backup.tar.enc-ab' from '123.45.678.90'."
239
- )
240
- connection.expects(:delete).in_sequence(s).with(
241
- File.join('remote/path', 'backup.tar.enc-ab')
242
- )
243
-
244
- connection.expects(:rmdir).with('remote/path').in_sequence(s)
245
-
246
- storage.send(:remove!, package)
247
- end
248
- end # describe '#remove!'
249
-
250
- describe '#create_remote_path' do
251
- let(:connection) { mock }
252
- let(:remote_path) { 'backups/folder/another_folder' }
253
- let(:s) { sequence '' }
254
-
255
- context 'while properly creating remote directories one by one' do
256
- it 'should rescue any FTPPermErrors and continue' do
257
- connection.expects(:mkdir).in_sequence(s).
258
- with("backups").raises(Net::FTPPermError)
259
- connection.expects(:mkdir).in_sequence(s).
260
- with("backups/folder")
261
- connection.expects(:mkdir).in_sequence(s).
262
- with("backups/folder/another_folder")
263
-
264
- expect do
265
- storage.send(:create_remote_path, remote_path, connection)
266
- end.not_to raise_error
267
- end
268
- end
269
- end
270
-
271
- end
@@ -1,259 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require File.expand_path('../../spec_helper.rb', __FILE__)
4
-
5
- describe Backup::Storage::Local do
6
- let(:model) { Backup::Model.new(:test_trigger, 'test label') }
7
- let(:storage_path) do
8
- File.join(File.expand_path(ENV['HOME'] || ''), 'backups')
9
- end
10
- let(:storage) do
11
- Backup::Storage::Local.new(model) do |local|
12
- local.keep = 5
13
- end
14
- end
15
-
16
- it 'should be a subclass of Storage::Base' do
17
- Backup::Storage::Local.
18
- superclass.should == Backup::Storage::Base
19
- end
20
-
21
- describe '#initialize' do
22
- after { Backup::Storage::Local.clear_defaults! }
23
-
24
- it 'should load pre-configured defaults through Base' do
25
- Backup::Storage::Local.any_instance.expects(:load_defaults!)
26
- storage
27
- end
28
-
29
- it 'should pass the model reference to Base' do
30
- storage.instance_variable_get(:@model).should == model
31
- end
32
-
33
- it 'should pass the storage_id to Base' do
34
- storage = Backup::Storage::Local.new(model, 'my_storage_id')
35
- storage.storage_id.should == 'my_storage_id'
36
- end
37
-
38
- it 'should expand any path given' do
39
- storage = Backup::Storage::Local.new(model) do |local|
40
- local.path = 'my_backups/path'
41
- end
42
- storage.path.should == File.expand_path('my_backups/path')
43
- end
44
-
45
- context 'when no pre-configured defaults have been set' do
46
- it 'should use the values given' do
47
- storage.path.should == storage_path
48
-
49
- storage.storage_id.should be_nil
50
- storage.keep.should == 5
51
- end
52
-
53
- it 'should use default values if none are given' do
54
- storage = Backup::Storage::Local.new(model)
55
-
56
- storage.path.should == storage_path
57
-
58
- storage.storage_id.should be_nil
59
- storage.keep.should be_nil
60
- end
61
- end # context 'when no pre-configured defaults have been set'
62
-
63
- context 'when pre-configured defaults have been set' do
64
- before do
65
- Backup::Storage::Local.defaults do |s|
66
- s.path = 'some_path'
67
- s.keep = 'some_keep'
68
- end
69
- end
70
-
71
- it 'should use pre-configured defaults' do
72
- storage = Backup::Storage::Local.new(model)
73
-
74
- storage.path.should == File.expand_path('some_path')
75
-
76
- storage.storage_id.should be_nil
77
- storage.keep.should == 'some_keep'
78
- end
79
-
80
- it 'should override pre-configured defaults' do
81
- storage = Backup::Storage::Local.new(model) do |s|
82
- s.path = 'new_path'
83
- s.keep = 'new_keep'
84
- end
85
-
86
- storage.path.should == File.expand_path('new_path')
87
-
88
- storage.storage_id.should be_nil
89
- storage.keep.should == 'new_keep'
90
- end
91
- end # context 'when pre-configured defaults have been set'
92
- end # describe '#initialize'
93
-
94
- describe '#transfer!' do
95
- let(:package) { mock }
96
- let(:s) { sequence '' }
97
-
98
- before do
99
- storage.instance_variable_set(:@package, package)
100
- storage.stubs(:storage_name).returns('Storage::Local')
101
- storage.stubs(:local_path).returns('/local/path')
102
- end
103
-
104
- context 'when transfer_method is :mv' do
105
- before { storage.stubs(:transfer_method).returns(:mv) }
106
- it 'should move the package files to their destination' do
107
- storage.expects(:remote_path_for).in_sequence(s).with(package).
108
- returns('remote/path')
109
- FileUtils.expects(:mkdir_p).in_sequence(s).with('remote/path')
110
-
111
- storage.expects(:files_to_transfer_for).in_sequence(s).with(package).
112
- multiple_yields(
113
- ['2011.12.31.11.00.02.backup.tar.enc-aa', 'backup.tar.enc-aa'],
114
- ['2011.12.31.11.00.02.backup.tar.enc-ab', 'backup.tar.enc-ab']
115
- )
116
- # first yield
117
- Backup::Logger.expects(:message).in_sequence(s).with(
118
- "Storage::Local started transferring " +
119
- "'2011.12.31.11.00.02.backup.tar.enc-aa'."
120
- )
121
- FileUtils.expects(:mv).in_sequence(s).with(
122
- File.join('/local/path', '2011.12.31.11.00.02.backup.tar.enc-aa'),
123
- File.join('remote/path', 'backup.tar.enc-aa')
124
- )
125
- # second yield
126
- Backup::Logger.expects(:message).in_sequence(s).with(
127
- "Storage::Local started transferring " +
128
- "'2011.12.31.11.00.02.backup.tar.enc-ab'."
129
- )
130
- FileUtils.expects(:mv).in_sequence(s).with(
131
- File.join('/local/path', '2011.12.31.11.00.02.backup.tar.enc-ab'),
132
- File.join('remote/path', 'backup.tar.enc-ab')
133
- )
134
-
135
- storage.send(:transfer!)
136
- end
137
- end # context 'when transfer_method is :mv'
138
-
139
- context 'when transfer_method is :cp' do
140
- before { storage.stubs(:transfer_method).returns(:cp) }
141
- it 'should copy the package files to their destination' do
142
- storage.expects(:remote_path_for).in_sequence(s).with(package).
143
- returns('remote/path')
144
- FileUtils.expects(:mkdir_p).in_sequence(s).with('remote/path')
145
-
146
- storage.expects(:files_to_transfer_for).in_sequence(s).with(package).
147
- multiple_yields(
148
- ['2011.12.31.11.00.02.backup.tar.enc-aa', 'backup.tar.enc-aa'],
149
- ['2011.12.31.11.00.02.backup.tar.enc-ab', 'backup.tar.enc-ab']
150
- )
151
- # first yield
152
- Backup::Logger.expects(:message).in_sequence(s).with(
153
- "Storage::Local started transferring " +
154
- "'2011.12.31.11.00.02.backup.tar.enc-aa'."
155
- )
156
- FileUtils.expects(:cp).in_sequence(s).with(
157
- File.join('/local/path', '2011.12.31.11.00.02.backup.tar.enc-aa'),
158
- File.join('remote/path', 'backup.tar.enc-aa')
159
- )
160
- # second yield
161
- Backup::Logger.expects(:message).in_sequence(s).with(
162
- "Storage::Local started transferring " +
163
- "'2011.12.31.11.00.02.backup.tar.enc-ab'."
164
- )
165
- FileUtils.expects(:cp).in_sequence(s).with(
166
- File.join('/local/path', '2011.12.31.11.00.02.backup.tar.enc-ab'),
167
- File.join('remote/path', 'backup.tar.enc-ab')
168
- )
169
-
170
- storage.send(:transfer!)
171
- end
172
- end # context 'when transfer_method is :cp'
173
-
174
- end # describe '#transfer!'
175
-
176
- describe '#remove!' do
177
- let(:package) { mock }
178
- let(:s) { sequence '' }
179
-
180
- before do
181
- storage.stubs(:storage_name).returns('Storage::Local')
182
- end
183
-
184
- it 'should remove the package files' do
185
- storage.expects(:remote_path_for).in_sequence(s).with(package).
186
- returns('remote/path')
187
-
188
- storage.expects(:transferred_files_for).in_sequence(s).with(package).
189
- multiple_yields(
190
- ['2011.12.31.11.00.02.backup.tar.enc-aa', 'backup.tar.enc-aa'],
191
- ['2011.12.31.11.00.02.backup.tar.enc-ab', 'backup.tar.enc-ab']
192
- )
193
- # after both yields
194
- Backup::Logger.expects(:message).in_sequence(s).with(
195
- "Storage::Local started removing " +
196
- "'2011.12.31.11.00.02.backup.tar.enc-aa'.\n" +
197
- "Storage::Local started removing " +
198
- "'2011.12.31.11.00.02.backup.tar.enc-ab'."
199
- )
200
- FileUtils.expects(:rm_r).in_sequence(s).with('remote/path')
201
-
202
- storage.send(:remove!, package)
203
- end
204
- end # describe '#remove!'
205
-
206
- describe '#transfer_method' do
207
- context 'when the storage is the last for the model' do
208
- before do
209
- model.storages << storage
210
- end
211
-
212
- it 'should return :mv' do
213
- storage.send(:transfer_method).should == :mv
214
- storage.instance_variable_get(:@transfer_method).should == :mv
215
- end
216
-
217
- it 'should only check once' do
218
- storage.instance_variable_set(:@transfer_method, :mv)
219
- model.expects(:storages).never
220
- storage.send(:transfer_method).should == :mv
221
- end
222
- end # context 'when the storage is the last for the model'
223
-
224
- context 'when the storage is not the last for the model' do
225
- let(:package) { mock }
226
-
227
- before do
228
- model.storages << storage
229
- model.storages << Backup::Storage::Local.new(model)
230
-
231
- storage.instance_variable_set(:@package, package)
232
- end
233
-
234
- it 'should log a warning and return :cp' do
235
- storage.expects(:remote_path_for).with(package).returns('remote_path')
236
- Backup::Logger.expects(:warn).with do |err|
237
- err.should be_an_instance_of Backup::Errors::Storage::Local::TransferError
238
- err.message.should ==
239
- "Storage::Local::TransferError: Local File Copy Warning!\n" +
240
- " The final backup file(s) for 'test label' (test_trigger)\n" +
241
- " will be *copied* to 'remote_path'\n" +
242
- " To avoid this, when using more than one Storage, the 'Local' Storage\n" +
243
- " should be added *last* so the files may be *moved* to their destination."
244
- end
245
-
246
- storage.send(:transfer_method).should == :cp
247
- storage.instance_variable_get(:@transfer_method).should == :cp
248
- end
249
-
250
- it 'should only check once' do
251
- storage.instance_variable_set(:@transfer_method, :cp)
252
- model.expects(:storages).never
253
- storage.send(:transfer_method).should == :cp
254
- end
255
- end # context 'when the storage is not the last for the model'
256
-
257
- end # describe '#transfer_method'
258
-
259
- end