backup 3.0.20 → 3.0.21
Sign up to get free protection for your applications and to get access to all the features.
- 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/storage/sftp_spec.rb
CHANGED
@@ -3,197 +3,215 @@
|
|
3
3
|
require File.expand_path('../../spec_helper.rb', __FILE__)
|
4
4
|
|
5
5
|
describe Backup::Storage::SFTP do
|
6
|
-
|
7
|
-
let(:
|
8
|
-
Backup::Storage::SFTP.new do |sftp|
|
6
|
+
let(:model) { Backup::Model.new(:test_trigger, 'test label') }
|
7
|
+
let(:storage) do
|
8
|
+
Backup::Storage::SFTP.new(model) do |sftp|
|
9
9
|
sftp.username = 'my_username'
|
10
10
|
sftp.password = 'my_password'
|
11
11
|
sftp.ip = '123.45.678.90'
|
12
|
-
sftp.
|
13
|
-
sftp.path = '~/backups/'
|
14
|
-
sftp.keep = 20
|
12
|
+
sftp.keep = 5
|
15
13
|
end
|
16
14
|
end
|
17
15
|
|
18
|
-
|
19
|
-
|
20
|
-
|
16
|
+
describe '#initialize' do
|
17
|
+
it 'should set the correct values' do
|
18
|
+
storage.username.should == 'my_username'
|
19
|
+
storage.password.should == 'my_password'
|
20
|
+
storage.ip.should == '123.45.678.90'
|
21
|
+
storage.port.should == 22
|
22
|
+
storage.path.should == 'backups'
|
21
23
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
sftp.ip.should == '123.45.678.90'
|
26
|
-
sftp.port.should == 22
|
27
|
-
sftp.path.should == 'backups/'
|
28
|
-
sftp.keep.should == 20
|
29
|
-
end
|
24
|
+
storage.storage_id.should be_nil
|
25
|
+
storage.keep.should == 5
|
26
|
+
end
|
30
27
|
|
31
|
-
|
32
|
-
|
33
|
-
sftp.
|
34
|
-
sftp.password = 'my_default_password'
|
35
|
-
sftp.path = '~/backups'
|
28
|
+
it 'should set a storage_id if given' do
|
29
|
+
sftp = Backup::Storage::SFTP.new(model, 'my storage_id')
|
30
|
+
sftp.storage_id.should == 'my storage_id'
|
36
31
|
end
|
37
32
|
|
38
|
-
|
39
|
-
|
40
|
-
|
33
|
+
it 'should remove any preceeding tilde and slash from the path' do
|
34
|
+
storage = Backup::Storage::SFTP.new(model) do |sftp|
|
35
|
+
sftp.path = '~/my_backups/path'
|
36
|
+
end
|
37
|
+
storage.path.should == 'my_backups/path'
|
41
38
|
end
|
42
39
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
40
|
+
context 'when setting configuration defaults' do
|
41
|
+
after { Backup::Configuration::Storage::SFTP.clear_defaults! }
|
42
|
+
|
43
|
+
it 'should use the configured defaults' do
|
44
|
+
Backup::Configuration::Storage::SFTP.defaults do |sftp|
|
45
|
+
sftp.username = 'some_username'
|
46
|
+
sftp.password = 'some_password'
|
47
|
+
sftp.ip = 'some_ip'
|
48
|
+
sftp.port = 'some_port'
|
49
|
+
sftp.path = 'some_path'
|
50
|
+
sftp.keep = 'some_keep'
|
51
|
+
end
|
52
|
+
storage = Backup::Storage::SFTP.new(model)
|
53
|
+
storage.username.should == 'some_username'
|
54
|
+
storage.password.should == 'some_password'
|
55
|
+
storage.ip.should == 'some_ip'
|
56
|
+
storage.port.should == 'some_port'
|
57
|
+
storage.path.should == 'some_path'
|
58
|
+
|
59
|
+
storage.storage_id.should be_nil
|
60
|
+
storage.keep.should == 'some_keep'
|
61
|
+
end
|
48
62
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
63
|
+
it 'should override the configured defaults' do
|
64
|
+
Backup::Configuration::Storage::SFTP.defaults do |sftp|
|
65
|
+
sftp.username = 'old_username'
|
66
|
+
sftp.password = 'old_password'
|
67
|
+
sftp.ip = 'old_ip'
|
68
|
+
sftp.port = 'old_port'
|
69
|
+
sftp.path = 'old_path'
|
70
|
+
sftp.keep = 'old_keep'
|
71
|
+
end
|
72
|
+
storage = Backup::Storage::SFTP.new(model) do |sftp|
|
73
|
+
sftp.username = 'new_username'
|
74
|
+
sftp.password = 'new_password'
|
75
|
+
sftp.ip = 'new_ip'
|
76
|
+
sftp.port = 'new_port'
|
77
|
+
sftp.path = 'new_path'
|
78
|
+
sftp.keep = 'new_keep'
|
79
|
+
end
|
80
|
+
|
81
|
+
storage.username.should == 'new_username'
|
82
|
+
storage.password.should == 'new_password'
|
83
|
+
storage.ip.should == 'new_ip'
|
84
|
+
storage.port.should == 'new_port'
|
85
|
+
storage.path.should == 'new_path'
|
86
|
+
|
87
|
+
storage.storage_id.should be_nil
|
88
|
+
storage.keep.should == 'new_keep'
|
89
|
+
end
|
90
|
+
end # context 'when setting configuration defaults'
|
54
91
|
|
55
|
-
describe '#
|
56
|
-
it 'should invoke transfer! and cycle!' do
|
57
|
-
sftp.expects(:transfer!)
|
58
|
-
sftp.expects(:cycle!)
|
59
|
-
sftp.perform!
|
60
|
-
end
|
61
|
-
end
|
92
|
+
end # describe '#initialize'
|
62
93
|
|
63
94
|
describe '#connection' do
|
64
|
-
|
65
|
-
|
95
|
+
let(:connection) { mock }
|
96
|
+
|
97
|
+
it 'should yield a connection to the remote server' do
|
66
98
|
Net::SFTP.expects(:start).with(
|
67
|
-
'123.45.678.90',
|
68
|
-
'my_username',
|
69
|
-
:password => 'my_password',
|
70
|
-
:port => 22
|
99
|
+
'123.45.678.90', 'my_username', :password => 'my_password', :port => 22
|
71
100
|
).yields(connection)
|
72
101
|
|
73
|
-
|
74
|
-
|
102
|
+
storage.send(:connection) do |sftp|
|
103
|
+
sftp.should be(connection)
|
75
104
|
end
|
76
105
|
end
|
77
|
-
end
|
106
|
+
end
|
78
107
|
|
79
108
|
describe '#transfer!' do
|
80
109
|
let(:connection) { mock }
|
110
|
+
let(:package) { mock }
|
111
|
+
let(:s) { sequence '' }
|
81
112
|
|
82
113
|
before do
|
83
|
-
|
114
|
+
storage.instance_variable_set(:@package, package)
|
115
|
+
storage.stubs(:storage_name).returns('Storage::SFTP')
|
116
|
+
storage.stubs(:local_path).returns('/local/path')
|
117
|
+
storage.stubs(:connection).yields(connection)
|
84
118
|
end
|
85
119
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
sftp.expects(:create_remote_directories).with(connection)
|
93
|
-
|
94
|
-
Backup::Logger.expects(:message).with(
|
95
|
-
"Storage::SFTP started transferring '#{local_file}' to '#{sftp.ip}'."
|
96
|
-
)
|
97
|
-
|
98
|
-
connection.expects(:upload!).with(
|
99
|
-
File.join(Backup::TMP_PATH, local_file),
|
100
|
-
File.join('backups/myapp', Backup::TIME, remote_file)
|
101
|
-
)
|
120
|
+
it 'should transfer the package files' do
|
121
|
+
storage.expects(:remote_path_for).in_sequence(s).with(package).
|
122
|
+
returns('remote/path')
|
123
|
+
storage.expects(:create_remote_path).in_sequence(s).with(
|
124
|
+
'remote/path', connection
|
125
|
+
)
|
102
126
|
|
103
|
-
|
104
|
-
|
105
|
-
|
127
|
+
storage.expects(:files_to_transfer_for).in_sequence(s).with(package).
|
128
|
+
multiple_yields(
|
129
|
+
['2011.12.31.11.00.02.backup.tar.enc-aa', 'backup.tar.enc-aa'],
|
130
|
+
['2011.12.31.11.00.02.backup.tar.enc-ab', 'backup.tar.enc-ab']
|
131
|
+
)
|
132
|
+
# first yield
|
133
|
+
Backup::Logger.expects(:message).in_sequence(s).with(
|
134
|
+
"Storage::SFTP started transferring " +
|
135
|
+
"'2011.12.31.11.00.02.backup.tar.enc-aa' to '123.45.678.90'."
|
136
|
+
)
|
137
|
+
connection.expects(:upload!).in_sequence(s).with(
|
138
|
+
File.join('/local/path', '2011.12.31.11.00.02.backup.tar.enc-aa'),
|
139
|
+
File.join('remote/path', 'backup.tar.enc-aa')
|
140
|
+
)
|
141
|
+
# second yield
|
142
|
+
Backup::Logger.expects(:message).in_sequence(s).with(
|
143
|
+
"Storage::SFTP started transferring " +
|
144
|
+
"'2011.12.31.11.00.02.backup.tar.enc-ab' to '123.45.678.90'."
|
145
|
+
)
|
146
|
+
connection.expects(:upload!).in_sequence(s).with(
|
147
|
+
File.join('/local/path', '2011.12.31.11.00.02.backup.tar.enc-ab'),
|
148
|
+
File.join('remote/path', 'backup.tar.enc-ab')
|
149
|
+
)
|
106
150
|
|
107
|
-
|
108
|
-
it 'should transfer all the provided files using a single connection' do
|
109
|
-
s = sequence ''
|
110
|
-
|
111
|
-
sftp.expects(:connection).in_sequence(s).yields(connection)
|
112
|
-
sftp.expects(:create_remote_directories).in_sequence(s).with(connection)
|
113
|
-
|
114
|
-
sftp.expects(:files_to_transfer).in_sequence(s).multiple_yields(
|
115
|
-
['local_file1', 'remote_file1'], ['local_file2', 'remote_file2']
|
116
|
-
)
|
117
|
-
|
118
|
-
Backup::Logger.expects(:message).in_sequence(s).with(
|
119
|
-
"Storage::SFTP started transferring 'local_file1' to '#{sftp.ip}'."
|
120
|
-
)
|
121
|
-
connection.expects(:upload!).in_sequence(s).with(
|
122
|
-
File.join(Backup::TMP_PATH, 'local_file1'),
|
123
|
-
File.join('backups/myapp', Backup::TIME, 'remote_file1')
|
124
|
-
)
|
125
|
-
|
126
|
-
Backup::Logger.expects(:message).in_sequence(s).with(
|
127
|
-
"Storage::SFTP started transferring 'local_file2' to '#{sftp.ip}'."
|
128
|
-
)
|
129
|
-
connection.expects(:upload!).in_sequence(s).with(
|
130
|
-
File.join(Backup::TMP_PATH, 'local_file2'),
|
131
|
-
File.join('backups/myapp', Backup::TIME, 'remote_file2')
|
132
|
-
)
|
133
|
-
|
134
|
-
sftp.send(:transfer!)
|
135
|
-
end
|
151
|
+
storage.send(:transfer!)
|
136
152
|
end
|
137
|
-
end # describe '#transfer'
|
153
|
+
end # describe '#transfer!'
|
138
154
|
|
139
155
|
describe '#remove!' do
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
remote_path = "backups/myapp/#{ Backup::TIME }"
|
144
|
-
sftp.stubs(:storage_name).returns('Storage::SFTP')
|
156
|
+
let(:package) { mock }
|
157
|
+
let(:connection) { mock }
|
158
|
+
let(:s) { sequence '' }
|
145
159
|
|
146
|
-
|
160
|
+
before do
|
161
|
+
storage.stubs(:storage_name).returns('Storage::SFTP')
|
162
|
+
storage.stubs(:connection).yields(connection)
|
163
|
+
end
|
147
164
|
|
148
|
-
|
149
|
-
|
150
|
-
|
165
|
+
it 'should remove the package files' do
|
166
|
+
storage.expects(:remote_path_for).in_sequence(s).with(package).
|
167
|
+
returns('remote/path')
|
151
168
|
|
169
|
+
storage.expects(:transferred_files_for).in_sequence(s).with(package).
|
170
|
+
multiple_yields(
|
171
|
+
['2011.12.31.11.00.02.backup.tar.enc-aa', 'backup.tar.enc-aa'],
|
172
|
+
['2011.12.31.11.00.02.backup.tar.enc-ab', 'backup.tar.enc-ab']
|
173
|
+
)
|
174
|
+
# first yield
|
152
175
|
Backup::Logger.expects(:message).in_sequence(s).with(
|
153
|
-
"Storage::SFTP started removing
|
176
|
+
"Storage::SFTP started removing " +
|
177
|
+
"'2011.12.31.11.00.02.backup.tar.enc-aa' from '123.45.678.90'."
|
154
178
|
)
|
155
179
|
connection.expects(:remove!).in_sequence(s).with(
|
156
|
-
File.join(
|
180
|
+
File.join('remote/path', 'backup.tar.enc-aa')
|
157
181
|
)
|
158
|
-
|
182
|
+
# second yield
|
159
183
|
Backup::Logger.expects(:message).in_sequence(s).with(
|
160
|
-
"Storage::SFTP started removing
|
184
|
+
"Storage::SFTP started removing " +
|
185
|
+
"'2011.12.31.11.00.02.backup.tar.enc-ab' from '123.45.678.90'."
|
161
186
|
)
|
162
187
|
connection.expects(:remove!).in_sequence(s).with(
|
163
|
-
File.join(
|
188
|
+
File.join('remote/path', 'backup.tar.enc-ab')
|
164
189
|
)
|
165
190
|
|
166
|
-
connection.expects(:rmdir!).
|
191
|
+
connection.expects(:rmdir!).with('remote/path').in_sequence(s)
|
167
192
|
|
168
|
-
|
193
|
+
storage.send(:remove!, package)
|
169
194
|
end
|
170
195
|
end # describe '#remove!'
|
171
196
|
|
172
|
-
describe '#
|
173
|
-
let(:connection)
|
197
|
+
describe '#create_remote_path' do
|
198
|
+
let(:connection) { mock }
|
199
|
+
let(:remote_path) { 'backups/folder/another_folder' }
|
200
|
+
let(:s) { sequence '' }
|
201
|
+
let(:sftp_response) { stub(:code => 11, :message => nil) }
|
202
|
+
let(:sftp_status_exception) { Net::SFTP::StatusException.new(sftp_response) }
|
174
203
|
|
175
204
|
context 'while properly creating remote directories one by one' do
|
176
|
-
it 'should rescue any SFTP::
|
177
|
-
s = sequence ''
|
178
|
-
sftp.path = '~/backups/some_other_folder/another_folder'
|
179
|
-
sftp_response = stub(:code => 11, :message => nil)
|
180
|
-
sftp_status_exception = Net::SFTP::StatusException.new(sftp_response)
|
181
|
-
|
182
|
-
connection.expects(:mkdir!).in_sequence(s).
|
183
|
-
with("~").raises(sftp_status_exception)
|
184
|
-
connection.expects(:mkdir!).in_sequence(s).
|
185
|
-
with("~/backups").raises(sftp_status_exception)
|
186
|
-
connection.expects(:mkdir!).in_sequence(s).
|
187
|
-
with("~/backups/some_other_folder")
|
205
|
+
it 'should rescue any SFTP::StatusException and continue' do
|
188
206
|
connection.expects(:mkdir!).in_sequence(s).
|
189
|
-
with("
|
207
|
+
with("backups").raises(sftp_status_exception)
|
190
208
|
connection.expects(:mkdir!).in_sequence(s).
|
191
|
-
with("
|
209
|
+
with("backups/folder")
|
192
210
|
connection.expects(:mkdir!).in_sequence(s).
|
193
|
-
with("
|
211
|
+
with("backups/folder/another_folder")
|
194
212
|
|
195
213
|
expect do
|
196
|
-
|
214
|
+
storage.send(:create_remote_path, remote_path, connection)
|
197
215
|
end.not_to raise_error
|
198
216
|
end
|
199
217
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require File.expand_path('../../spec_helper.rb', __FILE__)
|
4
|
+
|
5
|
+
describe Backup::Syncer::Base do
|
6
|
+
let(:base) { Backup::Syncer::Base }
|
7
|
+
let(:syncer) { base.new }
|
8
|
+
|
9
|
+
it 'should include CLI::Helpers' do
|
10
|
+
base.included_modules.should include(Backup::CLI::Helpers)
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'should include Configuration::Helpers' do
|
14
|
+
base.included_modules.should include(Backup::Configuration::Helpers)
|
15
|
+
end
|
16
|
+
|
17
|
+
describe '#syncer_name' do
|
18
|
+
it 'should return the class name with the Backup:: namespace removed' do
|
19
|
+
syncer.send(:syncer_name).should == 'Syncer::Base'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,118 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require File.expand_path('../../../spec_helper.rb', __FILE__)
|
4
|
+
|
5
|
+
describe Backup::Syncer::RSync::Base do
|
6
|
+
let(:syncer) { Backup::Syncer::RSync::Base.new }
|
7
|
+
|
8
|
+
describe '#initialize' do
|
9
|
+
|
10
|
+
it 'should use default values' do
|
11
|
+
syncer.path.should == 'backups'
|
12
|
+
syncer.directories.should == []
|
13
|
+
syncer.mirror.should == false
|
14
|
+
syncer.additional_options.should == []
|
15
|
+
end
|
16
|
+
|
17
|
+
context 'when setting configuration defaults' do
|
18
|
+
after { Backup::Configuration::Syncer::RSync::Base.clear_defaults! }
|
19
|
+
|
20
|
+
it 'should use the configured defaults' do
|
21
|
+
Backup::Configuration::Syncer::RSync::Base.defaults do |rsync|
|
22
|
+
rsync.path = 'some_path'
|
23
|
+
#rsync.directories = 'cannot_have_a_default_value'
|
24
|
+
rsync.mirror = 'some_mirror'
|
25
|
+
rsync.additional_options = 'some_additional_options'
|
26
|
+
end
|
27
|
+
syncer = Backup::Syncer::RSync::Base.new
|
28
|
+
syncer.path.should == 'some_path'
|
29
|
+
syncer.directories.should == []
|
30
|
+
syncer.mirror.should == 'some_mirror'
|
31
|
+
syncer.additional_options.should == 'some_additional_options'
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
end # describe '#initialize'
|
36
|
+
|
37
|
+
describe '#directories' do
|
38
|
+
before do
|
39
|
+
syncer.directories = ['/some/directory', '/another/directory']
|
40
|
+
end
|
41
|
+
|
42
|
+
context 'when no block is given' do
|
43
|
+
it 'should return @directories' do
|
44
|
+
syncer.directories.should ==
|
45
|
+
['/some/directory', '/another/directory']
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context 'when a block is given' do
|
50
|
+
it 'should evalute the block, allowing #add to add directories' do
|
51
|
+
syncer.directories do
|
52
|
+
add '/new/path'
|
53
|
+
add '/another/new/path'
|
54
|
+
end
|
55
|
+
syncer.directories.should == [
|
56
|
+
'/some/directory',
|
57
|
+
'/another/directory',
|
58
|
+
'/new/path',
|
59
|
+
'/another/new/path'
|
60
|
+
]
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end # describe '#directories'
|
64
|
+
|
65
|
+
describe '#add' do
|
66
|
+
before do
|
67
|
+
syncer.directories = ['/some/directory', '/another/directory']
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'should add the given path to @directories' do
|
71
|
+
syncer.add '/my/path'
|
72
|
+
syncer.directories.should ==
|
73
|
+
['/some/directory', '/another/directory', '/my/path']
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
describe '#directory_options' do
|
78
|
+
before do
|
79
|
+
syncer.directories = ['/some/directory', '/another/directory']
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'should return the directories for use in the command line' do
|
83
|
+
syncer.send(:directories_option).should ==
|
84
|
+
"'/some/directory' '/another/directory'"
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'should expand relative paths' do
|
88
|
+
syncer.directories += ['relative/path', '~/home/path']
|
89
|
+
syncer.send(:directories_option).should ==
|
90
|
+
"'/some/directory' '/another/directory' " +
|
91
|
+
"'#{ File.expand_path('relative/path') }' " +
|
92
|
+
"'#{ File.expand_path('~/home/path') }'"
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
describe '#mirror_option' do
|
97
|
+
context 'when @mirror is true' do
|
98
|
+
before { syncer.mirror = true }
|
99
|
+
it 'should return the command line flag for mirroring' do
|
100
|
+
syncer.send(:mirror_option).should == '--delete'
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
context 'when @mirror is false' do
|
105
|
+
before { syncer.mirror = false }
|
106
|
+
it 'should return nil' do
|
107
|
+
syncer.send(:mirror_option).should be_nil
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
describe '#archive_option' do
|
113
|
+
it 'should return the command line flag for archiving' do
|
114
|
+
syncer.send(:archive_option).should == '--archive'
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
end
|