backup 3.0.3.build.0 → 3.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +2 -0
- data/.infinity_test +7 -0
- data/.rspec +3 -0
- data/Gemfile +17 -0
- data/Gemfile.lock +88 -0
- data/LICENSE.md +24 -0
- data/README.md +236 -0
- data/backup.gemspec +41 -0
- data/bin/backup +191 -12
- data/lib/backup.rb +162 -0
- data/lib/backup/archive.rb +54 -0
- data/lib/backup/cli.rb +50 -0
- data/lib/backup/compressor/base.rb +17 -0
- data/lib/backup/compressor/gzip.rb +61 -0
- data/lib/backup/configuration/base.rb +15 -0
- data/lib/backup/configuration/compressor/base.rb +10 -0
- data/lib/backup/configuration/compressor/gzip.rb +23 -0
- data/lib/backup/configuration/database/base.rb +18 -0
- data/lib/backup/configuration/database/mongodb.rb +37 -0
- data/lib/backup/configuration/database/mysql.rb +37 -0
- data/lib/backup/configuration/database/postgresql.rb +37 -0
- data/lib/backup/configuration/database/redis.rb +35 -0
- data/lib/backup/configuration/encryptor/base.rb +10 -0
- data/lib/backup/configuration/encryptor/gpg.rb +17 -0
- data/lib/backup/configuration/encryptor/open_ssl.rb +26 -0
- data/lib/backup/configuration/helpers.rb +54 -0
- data/lib/backup/configuration/notifier/base.rb +39 -0
- data/lib/backup/configuration/notifier/mail.rb +52 -0
- data/lib/backup/configuration/storage/base.rb +18 -0
- data/lib/backup/configuration/storage/cloudfiles.rb +21 -0
- data/lib/backup/configuration/storage/dropbox.rb +25 -0
- data/lib/backup/configuration/storage/ftp.rb +25 -0
- data/lib/backup/configuration/storage/rsync.rb +25 -0
- data/lib/backup/configuration/storage/s3.rb +25 -0
- data/lib/backup/configuration/storage/scp.rb +25 -0
- data/lib/backup/configuration/storage/sftp.rb +25 -0
- data/lib/backup/configuration/syncer/rsync.rb +45 -0
- data/lib/backup/database/base.rb +33 -0
- data/lib/backup/database/mongodb.rb +137 -0
- data/lib/backup/database/mysql.rb +104 -0
- data/lib/backup/database/postgresql.rb +111 -0
- data/lib/backup/database/redis.rb +105 -0
- data/lib/backup/encryptor/base.rb +17 -0
- data/lib/backup/encryptor/gpg.rb +78 -0
- data/lib/backup/encryptor/open_ssl.rb +67 -0
- data/lib/backup/finder.rb +39 -0
- data/lib/backup/logger.rb +86 -0
- data/lib/backup/model.rb +272 -0
- data/lib/backup/notifier/base.rb +29 -0
- data/lib/backup/notifier/binder.rb +32 -0
- data/lib/backup/notifier/mail.rb +141 -0
- data/lib/backup/notifier/templates/notify_failure.erb +31 -0
- data/lib/backup/notifier/templates/notify_success.erb +16 -0
- data/lib/backup/storage/base.rb +67 -0
- data/lib/backup/storage/cloudfiles.rb +95 -0
- data/lib/backup/storage/dropbox.rb +82 -0
- data/lib/backup/storage/ftp.rb +114 -0
- data/lib/backup/storage/object.rb +45 -0
- data/lib/backup/storage/rsync.rb +99 -0
- data/lib/backup/storage/s3.rb +108 -0
- data/lib/backup/storage/scp.rb +105 -0
- data/lib/backup/storage/sftp.rb +106 -0
- data/lib/backup/syncer/rsync.rb +119 -0
- data/lib/backup/version.rb +72 -0
- data/lib/templates/archive +4 -0
- data/lib/templates/compressor/gzip +4 -0
- data/lib/templates/database/mongodb +10 -0
- data/lib/templates/database/mysql +11 -0
- data/lib/templates/database/postgresql +11 -0
- data/lib/templates/database/redis +10 -0
- data/lib/templates/encryptor/gpg +9 -0
- data/lib/templates/encryptor/openssl +5 -0
- data/lib/templates/notifier/mail +14 -0
- data/lib/templates/readme +15 -0
- data/lib/templates/storage/cloudfiles +7 -0
- data/lib/templates/storage/dropbox +8 -0
- data/lib/templates/storage/ftp +8 -0
- data/lib/templates/storage/rsync +7 -0
- data/lib/templates/storage/s3 +8 -0
- data/lib/templates/storage/scp +8 -0
- data/lib/templates/storage/sftp +8 -0
- data/lib/templates/syncer/rsync +14 -0
- data/spec/archive_spec.rb +53 -0
- data/spec/backup_spec.rb +11 -0
- data/spec/compressor/gzip_spec.rb +59 -0
- data/spec/configuration/base_spec.rb +35 -0
- data/spec/configuration/compressor/gzip_spec.rb +28 -0
- data/spec/configuration/database/base_spec.rb +16 -0
- data/spec/configuration/database/mongodb_spec.rb +30 -0
- data/spec/configuration/database/mysql_spec.rb +32 -0
- data/spec/configuration/database/postgresql_spec.rb +32 -0
- data/spec/configuration/database/redis_spec.rb +30 -0
- data/spec/configuration/encryptor/gpg_spec.rb +25 -0
- data/spec/configuration/encryptor/open_ssl_spec.rb +31 -0
- data/spec/configuration/notifier/mail_spec.rb +32 -0
- data/spec/configuration/storage/cloudfiles_spec.rb +34 -0
- data/spec/configuration/storage/dropbox_spec.rb +40 -0
- data/spec/configuration/storage/ftp_spec.rb +40 -0
- data/spec/configuration/storage/rsync_spec.rb +37 -0
- data/spec/configuration/storage/s3_spec.rb +37 -0
- data/spec/configuration/storage/scp_spec.rb +40 -0
- data/spec/configuration/storage/sftp_spec.rb +40 -0
- data/spec/configuration/syncer/rsync_spec.rb +46 -0
- data/spec/database/base_spec.rb +30 -0
- data/spec/database/mongodb_spec.rb +144 -0
- data/spec/database/mysql_spec.rb +150 -0
- data/spec/database/postgresql_spec.rb +164 -0
- data/spec/database/redis_spec.rb +122 -0
- data/spec/encryptor/gpg_spec.rb +57 -0
- data/spec/encryptor/open_ssl_spec.rb +102 -0
- data/spec/logger_spec.rb +46 -0
- data/spec/model_spec.rb +236 -0
- data/spec/notifier/mail_spec.rb +97 -0
- data/spec/spec_helper.rb +21 -0
- data/spec/storage/base_spec.rb +33 -0
- data/spec/storage/cloudfiles_spec.rb +102 -0
- data/spec/storage/dropbox_spec.rb +89 -0
- data/spec/storage/ftp_spec.rb +133 -0
- data/spec/storage/object_spec.rb +74 -0
- data/spec/storage/rsync_spec.rb +115 -0
- data/spec/storage/s3_spec.rb +110 -0
- data/spec/storage/scp_spec.rb +129 -0
- data/spec/storage/sftp_spec.rb +125 -0
- data/spec/syncer/rsync_spec.rb +156 -0
- data/spec/version_spec.rb +32 -0
- metadata +195 -6
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
|
4
|
+
|
|
5
|
+
describe Backup::Storage::RSync do
|
|
6
|
+
|
|
7
|
+
let(:rsync) do
|
|
8
|
+
Backup::Storage::RSync.new do |rsync|
|
|
9
|
+
rsync.username = 'my_username'
|
|
10
|
+
rsync.password = 'my_password'
|
|
11
|
+
rsync.ip = '123.45.678.90'
|
|
12
|
+
rsync.port = 22
|
|
13
|
+
rsync.path = '~/backups/'
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
before do
|
|
18
|
+
Backup::Configuration::Storage::RSync.clear_defaults!
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it 'should have defined the configuration properly' do
|
|
22
|
+
rsync.username.should == 'my_username'
|
|
23
|
+
rsync.password.should == 'my_password'
|
|
24
|
+
rsync.ip.should == '123.45.678.90'
|
|
25
|
+
rsync.port.should == 22
|
|
26
|
+
rsync.path.should == 'backups/'
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
it 'should use the defaults if a particular attribute has not been defined' do
|
|
30
|
+
Backup::Configuration::Storage::RSync.defaults do |rsync|
|
|
31
|
+
rsync.username = 'my_default_username'
|
|
32
|
+
rsync.password = 'my_default_password'
|
|
33
|
+
rsync.path = '~/backups'
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
rsync = Backup::Storage::RSync.new do |rsync|
|
|
37
|
+
rsync.password = 'my_password'
|
|
38
|
+
rsync.ip = '123.45.678.90'
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
rsync.username.should == 'my_default_username'
|
|
42
|
+
rsync.password.should == 'my_password'
|
|
43
|
+
rsync.ip.should == '123.45.678.90'
|
|
44
|
+
rsync.port.should == 22
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
it 'should have its own defaults' do
|
|
48
|
+
rsync = Backup::Storage::RSync.new
|
|
49
|
+
rsync.port.should == 22
|
|
50
|
+
rsync.path.should == 'backups'
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
describe '#connection' do
|
|
54
|
+
it 'should establish a connection to the remote server using the provided ip address and credentials' do
|
|
55
|
+
Net::SSH.expects(:start).with('123.45.678.90', 'my_username', :password => 'my_password', :port => 22)
|
|
56
|
+
rsync.send(:connection)
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
describe '#transfer!' do
|
|
61
|
+
let(:connection) { mock('Net::SCP') }
|
|
62
|
+
|
|
63
|
+
before do
|
|
64
|
+
Net::SSH.stubs(:start).returns(connection)
|
|
65
|
+
rsync.stubs(:create_remote_directories!)
|
|
66
|
+
Backup::Logger.stubs(:message)
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
it 'should transfer the provided file to the path' do
|
|
70
|
+
Backup::Model.new('blah', 'blah') {}
|
|
71
|
+
file = mock("Backup::Storage::RSync::File")
|
|
72
|
+
|
|
73
|
+
rsync.expects(:create_remote_directories!)
|
|
74
|
+
rsync.expects(:utility).returns('rsync')
|
|
75
|
+
rsync.expects(:run).with("rsync -z --port='22' '#{ File.join(Backup::TMP_PATH, "#{ Backup::TIME }.#{ Backup::TRIGGER }.tar") }' 'my_username@123.45.678.90:backups/#{ Backup::TRIGGER }/#{ Backup::TRIGGER }.tar'")
|
|
76
|
+
|
|
77
|
+
rsync.send(:transfer!)
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
describe '#remove!' do
|
|
82
|
+
let(:connection) { mock('Net::SCP') }
|
|
83
|
+
|
|
84
|
+
before do
|
|
85
|
+
Net::SSH.stubs(:start).returns(connection)
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
it 'should remove the file from the remote server path' do
|
|
89
|
+
connection.expects(:exec!).with("rm backups/myapp/#{ Backup::TIME }.#{ Backup::TRIGGER }.tar")
|
|
90
|
+
rsync.send(:remove!)
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
describe '#create_remote_directories!' do
|
|
95
|
+
let(:connection) { mock('Net::SSH') }
|
|
96
|
+
|
|
97
|
+
before do
|
|
98
|
+
Net::SSH.stubs(:start).returns(connection)
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
it 'should properly create remote directories one by one' do
|
|
102
|
+
rsync.path = 'backups/some_other_folder/another_folder'
|
|
103
|
+
connection.expects(:exec!).with("mkdir -p 'backups/some_other_folder/another_folder/myapp'")
|
|
104
|
+
rsync.send(:create_remote_directories!)
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
describe '#perform' do
|
|
109
|
+
it 'should invoke transfer!' do
|
|
110
|
+
rsync.expects(:transfer!)
|
|
111
|
+
rsync.perform!
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
end
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
|
4
|
+
|
|
5
|
+
##
|
|
6
|
+
# available S3 regions:
|
|
7
|
+
# eu-west-1, us-east-1, ap-southeast-1, us-west-1
|
|
8
|
+
describe Backup::Storage::S3 do
|
|
9
|
+
|
|
10
|
+
let(:s3) do
|
|
11
|
+
Backup::Storage::S3.new do |s3|
|
|
12
|
+
s3.access_key_id = 'my_access_key_id'
|
|
13
|
+
s3.secret_access_key = 'my_secret_access_key'
|
|
14
|
+
s3.region = 'us-east-1'
|
|
15
|
+
s3.bucket = 'my-bucket'
|
|
16
|
+
s3.path = 'backups'
|
|
17
|
+
s3.keep = 20
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
before do
|
|
22
|
+
Backup::Configuration::Storage::S3.clear_defaults!
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it 'should have defined the configuration properly' do
|
|
26
|
+
s3.access_key_id.should == 'my_access_key_id'
|
|
27
|
+
s3.secret_access_key.should == 'my_secret_access_key'
|
|
28
|
+
s3.region.should == 'us-east-1'
|
|
29
|
+
s3.bucket.should == 'my-bucket'
|
|
30
|
+
s3.keep.should == 20
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
it 'should use the defaults if a particular attribute has not been defined' do
|
|
34
|
+
Backup::Configuration::Storage::S3.defaults do |s3|
|
|
35
|
+
s3.access_key_id = 'my_access_key_id'
|
|
36
|
+
s3.region = 'us-east-1'
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
s3 = Backup::Storage::S3.new do |s3|
|
|
40
|
+
s3.region = 'us-west-1'
|
|
41
|
+
s3.path = 'my/backups'
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
s3.access_key_id.should == 'my_access_key_id' # not defined, uses default
|
|
45
|
+
s3.secret_access_key.should == nil # not defined, no default
|
|
46
|
+
s3.region.should == 'us-west-1' # defined, overwrites default
|
|
47
|
+
s3.bucket.should == nil # not defined, no default
|
|
48
|
+
s3.path.should == 'my/backups' # overwritten from Backup::Storage::S3
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
describe '#connection' do
|
|
52
|
+
it 'should establish a connection to Amazon S3 using the provided credentials' do
|
|
53
|
+
Fog::Storage.expects(:new).with({
|
|
54
|
+
:provider => 'AWS',
|
|
55
|
+
:aws_access_key_id => 'my_access_key_id',
|
|
56
|
+
:aws_secret_access_key => 'my_secret_access_key',
|
|
57
|
+
:region => 'us-east-1'
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
s3.send(:connection)
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
describe '#provider' do
|
|
65
|
+
it 'should be AWS' do
|
|
66
|
+
s3.provider == 'AWS'
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
describe '#transfer!' do
|
|
71
|
+
let(:connection) { mock('Fog::Storage') }
|
|
72
|
+
before do
|
|
73
|
+
Fog::Storage.stubs(:new).returns(connection)
|
|
74
|
+
Backup::Logger.stubs(:message)
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
it 'should transfer the provided file to the bucket' do
|
|
78
|
+
Backup::Model.new('blah', 'blah') {}
|
|
79
|
+
file = mock("Backup::Storage::S3::File")
|
|
80
|
+
File.expects(:open).with("#{File.join(Backup::TMP_PATH, "#{ Backup::TIME }.#{ Backup::TRIGGER}")}.tar").returns(file)
|
|
81
|
+
s3.expects(:remote_file).returns("#{ Backup::TIME }.#{ Backup::TRIGGER }.tar").twice
|
|
82
|
+
connection.expects(:sync_clock)
|
|
83
|
+
connection.expects(:put_object).with('my-bucket', "backups/myapp/#{ Backup::TIME }.#{ Backup::TRIGGER }.tar", file)
|
|
84
|
+
s3.send(:transfer!)
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
describe '#remove!' do
|
|
89
|
+
let(:connection) { mock('Fog::Storage') }
|
|
90
|
+
before do
|
|
91
|
+
Fog::Storage.stubs(:new).returns(connection)
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
it 'should remove the file from the bucket' do
|
|
95
|
+
s3.expects(:remote_file).returns("#{ Backup::TIME }.#{ Backup::TRIGGER }.tar")
|
|
96
|
+
connection.expects(:sync_clock)
|
|
97
|
+
connection.expects(:delete_object).with('my-bucket', "backups/myapp/#{ Backup::TIME }.#{ Backup::TRIGGER }.tar")
|
|
98
|
+
s3.send(:remove!)
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
describe '#perform' do
|
|
103
|
+
it 'should invoke transfer! and cycle!' do
|
|
104
|
+
s3.expects(:transfer!)
|
|
105
|
+
s3.expects(:cycle!)
|
|
106
|
+
s3.perform!
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
end
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
|
4
|
+
|
|
5
|
+
describe Backup::Storage::SCP do
|
|
6
|
+
|
|
7
|
+
let(:scp) do
|
|
8
|
+
Backup::Storage::SCP.new do |scp|
|
|
9
|
+
scp.username = 'my_username'
|
|
10
|
+
scp.password = 'my_password'
|
|
11
|
+
scp.ip = '123.45.678.90'
|
|
12
|
+
scp.port = 22
|
|
13
|
+
scp.path = '~/backups/'
|
|
14
|
+
scp.keep = 20
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
before do
|
|
19
|
+
Backup::Configuration::Storage::SCP.clear_defaults!
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it 'should have defined the configuration properly' do
|
|
23
|
+
scp.username.should == 'my_username'
|
|
24
|
+
scp.password.should == 'my_password'
|
|
25
|
+
scp.ip.should == '123.45.678.90'
|
|
26
|
+
scp.port.should == 22
|
|
27
|
+
scp.path.should == 'backups/'
|
|
28
|
+
scp.keep.should == 20
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
it 'should use the defaults if a particular attribute has not been defined' do
|
|
32
|
+
Backup::Configuration::Storage::SCP.defaults do |scp|
|
|
33
|
+
scp.username = 'my_default_username'
|
|
34
|
+
scp.password = 'my_default_password'
|
|
35
|
+
scp.path = '~/backups'
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
scp = Backup::Storage::SCP.new do |scp|
|
|
39
|
+
scp.password = 'my_password'
|
|
40
|
+
scp.ip = '123.45.678.90'
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
scp.username.should == 'my_default_username'
|
|
44
|
+
scp.password.should == 'my_password'
|
|
45
|
+
scp.ip.should == '123.45.678.90'
|
|
46
|
+
scp.port.should == 22
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
it 'should have its own defaults' do
|
|
50
|
+
scp = Backup::Storage::SCP.new
|
|
51
|
+
scp.port.should == 22
|
|
52
|
+
scp.path.should == 'backups'
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
describe '#connection' do
|
|
56
|
+
it 'should establish a connection to the remote server using the provided ip address and credentials' do
|
|
57
|
+
Net::SSH.expects(:start).with('123.45.678.90', 'my_username', :password => 'my_password', :port => 22)
|
|
58
|
+
scp.send(:connection)
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
describe '#transfer!' do
|
|
63
|
+
let(:connection) { mock('Net::SCP') }
|
|
64
|
+
|
|
65
|
+
before do
|
|
66
|
+
Net::SSH.stubs(:start).returns(connection)
|
|
67
|
+
scp.stubs(:create_remote_directories!)
|
|
68
|
+
Backup::Logger.stubs(:message)
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
it 'should transfer the provided file to the path' do
|
|
72
|
+
Backup::Model.new('blah', 'blah') {}
|
|
73
|
+
file = mock("Backup::Storage::SCP::File")
|
|
74
|
+
|
|
75
|
+
scp.expects(:create_remote_directories!)
|
|
76
|
+
|
|
77
|
+
ssh_scp = mock('Net::SSH::SCP')
|
|
78
|
+
connection.expects(:scp).returns(ssh_scp)
|
|
79
|
+
|
|
80
|
+
ssh_scp.expects(:upload!).with(
|
|
81
|
+
File.join(Backup::TMP_PATH, "#{ Backup::TIME }.#{ Backup::TRIGGER }.tar"),
|
|
82
|
+
File.join('backups/myapp', "#{ Backup::TIME }.#{ Backup::TRIGGER }.tar")
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
scp.send(:transfer!)
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
describe '#remove!' do
|
|
90
|
+
let(:connection) { mock('Net::SCP') }
|
|
91
|
+
|
|
92
|
+
before do
|
|
93
|
+
Net::SSH.stubs(:start).returns(connection)
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
it 'should remove the file from the remote server path' do
|
|
97
|
+
connection.expects(:exec!).with("rm backups/myapp/#{ Backup::TIME }.#{ Backup::TRIGGER }.tar")
|
|
98
|
+
scp.send(:remove!)
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
describe '#create_remote_directories!' do
|
|
103
|
+
let(:connection) { mock('Net::SSH') }
|
|
104
|
+
|
|
105
|
+
before do
|
|
106
|
+
Net::SSH.stubs(:start).returns(connection)
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
it 'should properly create remote directories one by one' do
|
|
110
|
+
scp.path = 'backups/some_other_folder/another_folder'
|
|
111
|
+
|
|
112
|
+
connection.expects(:exec!).with("mkdir 'backups'")
|
|
113
|
+
connection.expects(:exec!).with("mkdir 'backups/some_other_folder'")
|
|
114
|
+
connection.expects(:exec!).with("mkdir 'backups/some_other_folder/another_folder'")
|
|
115
|
+
connection.expects(:exec!).with("mkdir 'backups/some_other_folder/another_folder/myapp'")
|
|
116
|
+
|
|
117
|
+
scp.send(:create_remote_directories!)
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
describe '#perform' do
|
|
122
|
+
it 'should invoke transfer! and cycle!' do
|
|
123
|
+
scp.expects(:transfer!)
|
|
124
|
+
scp.expects(:cycle!)
|
|
125
|
+
scp.perform!
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
end
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
|
4
|
+
|
|
5
|
+
describe Backup::Storage::SFTP do
|
|
6
|
+
|
|
7
|
+
let(:sftp) do
|
|
8
|
+
Backup::Storage::SFTP.new do |sftp|
|
|
9
|
+
sftp.username = 'my_username'
|
|
10
|
+
sftp.password = 'my_password'
|
|
11
|
+
sftp.ip = '123.45.678.90'
|
|
12
|
+
sftp.port = 22
|
|
13
|
+
sftp.path = '~/backups/'
|
|
14
|
+
sftp.keep = 20
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
before do
|
|
19
|
+
Backup::Configuration::Storage::SFTP.clear_defaults!
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it 'should have defined the configuration properly' do
|
|
23
|
+
sftp.username.should == 'my_username'
|
|
24
|
+
sftp.password.should == 'my_password'
|
|
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
|
|
30
|
+
|
|
31
|
+
it 'should use the defaults if a particular attribute has not been defined' do
|
|
32
|
+
Backup::Configuration::Storage::SFTP.defaults do |sftp|
|
|
33
|
+
sftp.username = 'my_default_username'
|
|
34
|
+
sftp.password = 'my_default_password'
|
|
35
|
+
sftp.path = '~/backups'
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
sftp = Backup::Storage::SFTP.new do |sftp|
|
|
39
|
+
sftp.password = 'my_password'
|
|
40
|
+
sftp.ip = '123.45.678.90'
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
sftp.username.should == 'my_default_username'
|
|
44
|
+
sftp.password.should == 'my_password'
|
|
45
|
+
sftp.ip.should == '123.45.678.90'
|
|
46
|
+
sftp.port.should == 22
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
it 'should have its own defaults' do
|
|
50
|
+
sftp = Backup::Storage::SFTP.new
|
|
51
|
+
sftp.port.should == 22
|
|
52
|
+
sftp.path.should == 'backups'
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
describe '#connection' do
|
|
56
|
+
it 'should establish a connection to the remote server using the provided ip address and credentials' do
|
|
57
|
+
Net::SFTP.expects(:start).with('123.45.678.90', 'my_username', :password => 'my_password', :port => 22)
|
|
58
|
+
sftp.send(:connection)
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
describe '#transfer!' do
|
|
63
|
+
let(:connection) { mock('Fog::Storage') }
|
|
64
|
+
|
|
65
|
+
before do
|
|
66
|
+
Net::SFTP.stubs(:start).returns(connection)
|
|
67
|
+
sftp.stubs(:create_remote_directories!)
|
|
68
|
+
Backup::Logger.stubs(:message)
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
it 'should transfer the provided file to the path' do
|
|
72
|
+
Backup::Model.new('blah', 'blah') {}
|
|
73
|
+
file = mock("Backup::Storage::SFTP::File")
|
|
74
|
+
|
|
75
|
+
sftp.expects(:create_remote_directories!)
|
|
76
|
+
connection.expects(:upload!).with(
|
|
77
|
+
File.join(Backup::TMP_PATH, "#{ Backup::TIME }.#{ Backup::TRIGGER }.tar"),
|
|
78
|
+
File.join('backups/myapp', "#{ Backup::TIME }.#{ Backup::TRIGGER }.tar")
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
sftp.send(:transfer!)
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
describe '#remove!' do
|
|
86
|
+
let(:connection) { mock('Net::SFTP') }
|
|
87
|
+
|
|
88
|
+
before do
|
|
89
|
+
Net::SFTP.stubs(:start).returns(connection)
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
it 'should remove the file from the remote server path' do
|
|
93
|
+
connection.expects(:remove!).with("backups/myapp/#{ Backup::TIME }.#{ Backup::TRIGGER }.tar")
|
|
94
|
+
sftp.send(:remove!)
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
describe '#create_remote_directories!' do
|
|
99
|
+
let(:connection) { mock('Net::SFTP') }
|
|
100
|
+
|
|
101
|
+
before do
|
|
102
|
+
Net::SFTP.stubs(:start).returns(connection)
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
it 'should properly create remote directories one by one' do
|
|
106
|
+
sftp.path = 'backups/some_other_folder/another_folder'
|
|
107
|
+
|
|
108
|
+
connection.expects(:mkdir!).with('backups')
|
|
109
|
+
connection.expects(:mkdir!).with('backups/some_other_folder')
|
|
110
|
+
connection.expects(:mkdir!).with('backups/some_other_folder/another_folder')
|
|
111
|
+
connection.expects(:mkdir!).with('backups/some_other_folder/another_folder/myapp')
|
|
112
|
+
|
|
113
|
+
sftp.send(:create_remote_directories!)
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
describe '#perform' do
|
|
118
|
+
it 'should invoke transfer! and cycle!' do
|
|
119
|
+
sftp.expects(:transfer!)
|
|
120
|
+
sftp.expects(:cycle!)
|
|
121
|
+
sftp.perform!
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
end
|