backup 3.0.2 → 3.0.3.build.0
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/backup +12 -190
- metadata +7 -191
- data/.gitignore +0 -2
- data/.infinity_test +0 -7
- data/.rspec +0 -3
- data/Gemfile +0 -17
- data/Gemfile.lock +0 -88
- data/LICENSE.md +0 -24
- data/README.md +0 -236
- data/backup.gemspec +0 -41
- data/lib/backup.rb +0 -148
- data/lib/backup/archive.rb +0 -54
- data/lib/backup/cli.rb +0 -50
- data/lib/backup/compressor/base.rb +0 -17
- data/lib/backup/compressor/gzip.rb +0 -61
- data/lib/backup/configuration/base.rb +0 -15
- data/lib/backup/configuration/compressor/base.rb +0 -10
- data/lib/backup/configuration/compressor/gzip.rb +0 -23
- data/lib/backup/configuration/database/base.rb +0 -18
- data/lib/backup/configuration/database/mongodb.rb +0 -37
- data/lib/backup/configuration/database/mysql.rb +0 -37
- data/lib/backup/configuration/database/postgresql.rb +0 -37
- data/lib/backup/configuration/database/redis.rb +0 -35
- data/lib/backup/configuration/encryptor/base.rb +0 -10
- data/lib/backup/configuration/encryptor/gpg.rb +0 -17
- data/lib/backup/configuration/encryptor/open_ssl.rb +0 -26
- data/lib/backup/configuration/helpers.rb +0 -54
- data/lib/backup/configuration/notifier/base.rb +0 -39
- data/lib/backup/configuration/notifier/mail.rb +0 -52
- data/lib/backup/configuration/storage/base.rb +0 -18
- data/lib/backup/configuration/storage/cloudfiles.rb +0 -21
- data/lib/backup/configuration/storage/dropbox.rb +0 -25
- data/lib/backup/configuration/storage/ftp.rb +0 -25
- data/lib/backup/configuration/storage/rsync.rb +0 -25
- data/lib/backup/configuration/storage/s3.rb +0 -25
- data/lib/backup/configuration/storage/scp.rb +0 -25
- data/lib/backup/configuration/storage/sftp.rb +0 -25
- data/lib/backup/database/base.rb +0 -33
- data/lib/backup/database/mongodb.rb +0 -137
- data/lib/backup/database/mysql.rb +0 -104
- data/lib/backup/database/postgresql.rb +0 -111
- data/lib/backup/database/redis.rb +0 -105
- data/lib/backup/encryptor/base.rb +0 -17
- data/lib/backup/encryptor/gpg.rb +0 -78
- data/lib/backup/encryptor/open_ssl.rb +0 -67
- data/lib/backup/finder.rb +0 -39
- data/lib/backup/logger.rb +0 -80
- data/lib/backup/model.rb +0 -249
- data/lib/backup/notifier/base.rb +0 -29
- data/lib/backup/notifier/binder.rb +0 -32
- data/lib/backup/notifier/mail.rb +0 -141
- data/lib/backup/notifier/templates/notify_failure.erb +0 -31
- data/lib/backup/notifier/templates/notify_success.erb +0 -16
- data/lib/backup/storage/base.rb +0 -67
- data/lib/backup/storage/cloudfiles.rb +0 -95
- data/lib/backup/storage/dropbox.rb +0 -82
- data/lib/backup/storage/ftp.rb +0 -114
- data/lib/backup/storage/object.rb +0 -45
- data/lib/backup/storage/rsync.rb +0 -100
- data/lib/backup/storage/s3.rb +0 -108
- data/lib/backup/storage/scp.rb +0 -105
- data/lib/backup/storage/sftp.rb +0 -106
- data/lib/backup/version.rb +0 -72
- data/lib/templates/archive +0 -4
- data/lib/templates/compressor/gzip +0 -4
- data/lib/templates/database/mongodb +0 -10
- data/lib/templates/database/mysql +0 -11
- data/lib/templates/database/postgresql +0 -11
- data/lib/templates/database/redis +0 -10
- data/lib/templates/encryptor/gpg +0 -9
- data/lib/templates/encryptor/openssl +0 -5
- data/lib/templates/notifier/mail +0 -14
- data/lib/templates/readme +0 -15
- data/lib/templates/storage/cloudfiles +0 -7
- data/lib/templates/storage/dropbox +0 -8
- data/lib/templates/storage/ftp +0 -8
- data/lib/templates/storage/rsync +0 -7
- data/lib/templates/storage/s3 +0 -8
- data/lib/templates/storage/scp +0 -8
- data/lib/templates/storage/sftp +0 -8
- data/spec/archive_spec.rb +0 -53
- data/spec/backup_spec.rb +0 -11
- data/spec/compressor/gzip_spec.rb +0 -59
- data/spec/configuration/base_spec.rb +0 -35
- data/spec/configuration/compressor/gzip_spec.rb +0 -28
- data/spec/configuration/database/base_spec.rb +0 -16
- data/spec/configuration/database/mongodb_spec.rb +0 -30
- data/spec/configuration/database/mysql_spec.rb +0 -32
- data/spec/configuration/database/postgresql_spec.rb +0 -32
- data/spec/configuration/database/redis_spec.rb +0 -30
- data/spec/configuration/encryptor/gpg_spec.rb +0 -25
- data/spec/configuration/encryptor/open_ssl_spec.rb +0 -31
- data/spec/configuration/notifier/mail_spec.rb +0 -32
- data/spec/configuration/storage/cloudfiles_spec.rb +0 -34
- data/spec/configuration/storage/dropbox_spec.rb +0 -40
- data/spec/configuration/storage/ftp_spec.rb +0 -40
- data/spec/configuration/storage/rsync_spec.rb +0 -37
- data/spec/configuration/storage/s3_spec.rb +0 -37
- data/spec/configuration/storage/scp_spec.rb +0 -40
- data/spec/configuration/storage/sftp_spec.rb +0 -40
- data/spec/database/base_spec.rb +0 -30
- data/spec/database/mongodb_spec.rb +0 -144
- data/spec/database/mysql_spec.rb +0 -150
- data/spec/database/postgresql_spec.rb +0 -164
- data/spec/database/redis_spec.rb +0 -122
- data/spec/encryptor/gpg_spec.rb +0 -57
- data/spec/encryptor/open_ssl_spec.rb +0 -102
- data/spec/logger_spec.rb +0 -37
- data/spec/model_spec.rb +0 -236
- data/spec/notifier/mail_spec.rb +0 -97
- data/spec/spec_helper.rb +0 -21
- data/spec/storage/base_spec.rb +0 -33
- data/spec/storage/cloudfiles_spec.rb +0 -102
- data/spec/storage/dropbox_spec.rb +0 -89
- data/spec/storage/ftp_spec.rb +0 -133
- data/spec/storage/object_spec.rb +0 -74
- data/spec/storage/rsync_spec.rb +0 -115
- data/spec/storage/s3_spec.rb +0 -110
- data/spec/storage/scp_spec.rb +0 -129
- data/spec/storage/sftp_spec.rb +0 -125
- data/spec/version_spec.rb +0 -32
data/spec/notifier/mail_spec.rb
DELETED
@@ -1,97 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require File.dirname(__FILE__) + '/../spec_helper'
|
4
|
-
|
5
|
-
describe Backup::Notifier::Mail do
|
6
|
-
let(:notifier) do
|
7
|
-
Backup::Notifier::Mail.new do |mail|
|
8
|
-
mail.from = 'my.sender.email@gmail.com'
|
9
|
-
mail.to = 'my.receiver.email@gmail.com'
|
10
|
-
mail.address = 'smtp.gmail.com'
|
11
|
-
mail.port = 587
|
12
|
-
mail.domain = 'your.host.name'
|
13
|
-
mail.user_name = 'user'
|
14
|
-
mail.password = 'secret'
|
15
|
-
mail.authentication = 'plain'
|
16
|
-
mail.enable_starttls_auto = true
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
it do
|
21
|
-
notifier.from.should == 'my.sender.email@gmail.com'
|
22
|
-
notifier.to.should == 'my.receiver.email@gmail.com'
|
23
|
-
notifier.address.should == 'smtp.gmail.com'
|
24
|
-
notifier.port.should == 587
|
25
|
-
notifier.domain.should == 'your.host.name'
|
26
|
-
notifier.user_name.should == 'user'
|
27
|
-
notifier.password.should == 'secret'
|
28
|
-
notifier.authentication.should == 'plain'
|
29
|
-
notifier.enable_starttls_auto.should == true
|
30
|
-
|
31
|
-
notifier.on_success.should == true
|
32
|
-
notifier.on_failure.should == true
|
33
|
-
end
|
34
|
-
|
35
|
-
describe 'defaults' do
|
36
|
-
it do
|
37
|
-
Backup::Configuration::Notifier::Mail.defaults do |mail|
|
38
|
-
mail.to = 'some.receiver.email@gmail.com'
|
39
|
-
mail.on_success = false
|
40
|
-
mail.on_failure = true
|
41
|
-
end
|
42
|
-
notifier = Backup::Notifier::Mail.new do |mail|
|
43
|
-
mail.from = 'my.sender.email@gmail.com'
|
44
|
-
end
|
45
|
-
|
46
|
-
notifier.to.should == 'some.receiver.email@gmail.com'
|
47
|
-
notifier.from.should == 'my.sender.email@gmail.com'
|
48
|
-
notifier.on_success.should == false
|
49
|
-
notifier.on_failure.should == true
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
describe '#initialize' do
|
54
|
-
it do
|
55
|
-
Backup::Notifier::Mail.any_instance.expects(:set_defaults!)
|
56
|
-
Backup::Notifier::Mail.new
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
describe '#perform!' do
|
61
|
-
let(:model) { Backup::Model.new('blah', 'blah') {} }
|
62
|
-
before do
|
63
|
-
notifier.on_success = false
|
64
|
-
notifier.on_failure = false
|
65
|
-
end
|
66
|
-
|
67
|
-
context "when successful" do
|
68
|
-
it do
|
69
|
-
Backup::Logger.expects(:message).with("Backup::Notifier::Mail started notifying about the process.")
|
70
|
-
notifier.expects("notify_success!")
|
71
|
-
notifier.on_success = true
|
72
|
-
notifier.perform!(model)
|
73
|
-
end
|
74
|
-
|
75
|
-
it do
|
76
|
-
notifier.expects("notify_success!").never
|
77
|
-
notifier.on_success = false
|
78
|
-
notifier.perform!(model)
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
context "when failed" do
|
83
|
-
it do
|
84
|
-
Backup::Logger.expects(:message).with("Backup::Notifier::Mail started notifying about the process.")
|
85
|
-
notifier.expects("notify_failure!")
|
86
|
-
notifier.on_failure = true
|
87
|
-
notifier.perform!(model, Exception.new)
|
88
|
-
end
|
89
|
-
|
90
|
-
it do
|
91
|
-
notifier.expects("notify_failure!").never
|
92
|
-
notifier.on_failure = false
|
93
|
-
notifier.perform!(model, Exception.new)
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|
data/spec/spec_helper.rb
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
##
|
4
|
-
# Load Backup
|
5
|
-
require File.expand_path( '../../lib/backup', __FILE__ )
|
6
|
-
|
7
|
-
##
|
8
|
-
# Use Mocha to mock with RSpec
|
9
|
-
RSpec.configure do |config|
|
10
|
-
config.mock_with :mocha
|
11
|
-
end
|
12
|
-
|
13
|
-
# FIXTURES_PATH = File.join( File.dirname(__FILE__), 'fixtures' )
|
14
|
-
|
15
|
-
Backup.send(:remove_const, :TRIGGER) if defined? Backup::TRIGGER
|
16
|
-
Backup.send(:remove_const, :TIME) if defined? Backup::TIME
|
17
|
-
|
18
|
-
module Backup
|
19
|
-
TRIGGER = 'myapp'
|
20
|
-
TIME = Time.now.strftime("%Y.%m.%d.%H.%M.%S")
|
21
|
-
end
|
data/spec/storage/base_spec.rb
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require File.dirname(__FILE__) + '/../spec_helper'
|
4
|
-
|
5
|
-
describe Backup::Storage::Base do
|
6
|
-
let(:base) { Backup::Storage::Base.new }
|
7
|
-
|
8
|
-
before do
|
9
|
-
Backup::Logger.stubs(:message)
|
10
|
-
end
|
11
|
-
|
12
|
-
it do
|
13
|
-
storage_object = mock
|
14
|
-
Backup::Storage::Object.expects(:new).with('Base').returns(storage_object)
|
15
|
-
storage_object.stubs(:load).returns([])
|
16
|
-
storage_object.expects(:write)
|
17
|
-
base.keep = 1
|
18
|
-
base.cycle!
|
19
|
-
end
|
20
|
-
|
21
|
-
it do
|
22
|
-
base.keep = 3
|
23
|
-
storage_object = mock
|
24
|
-
objects = %w[1 2 3 4].map { Backup::Storage::Base.new }
|
25
|
-
|
26
|
-
Backup::Storage::Object.expects(:new).with('Base').returns(storage_object)
|
27
|
-
storage_object.stubs(:load).returns(objects)
|
28
|
-
storage_object.expects(:write)
|
29
|
-
Backup::Storage::Base.any_instance.expects(:remove!).times(2)
|
30
|
-
|
31
|
-
base.cycle!
|
32
|
-
end
|
33
|
-
end
|
@@ -1,102 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require File.dirname(__FILE__) + '/../spec_helper'
|
4
|
-
|
5
|
-
describe Backup::Storage::CloudFiles do
|
6
|
-
|
7
|
-
let(:cf) do
|
8
|
-
Backup::Storage::CloudFiles.new do |cf|
|
9
|
-
cf.username = 'my_username'
|
10
|
-
cf.api_key = 'my_api_key'
|
11
|
-
cf.container = 'my_container'
|
12
|
-
cf.path = 'backups'
|
13
|
-
cf.keep = 20
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
before do
|
18
|
-
Backup::Configuration::Storage::CloudFiles.clear_defaults!
|
19
|
-
end
|
20
|
-
|
21
|
-
it 'should have defined the configuration properly' do
|
22
|
-
cf.username.should == 'my_username'
|
23
|
-
cf.api_key.should == 'my_api_key'
|
24
|
-
cf.container.should == 'my_container'
|
25
|
-
cf.path.should == 'backups'
|
26
|
-
cf.keep.should == 20
|
27
|
-
end
|
28
|
-
|
29
|
-
it 'should use the defaults if a particular attribute has not been defined' do
|
30
|
-
Backup::Configuration::Storage::CloudFiles.defaults do |cf|
|
31
|
-
cf.username = 'my_username'
|
32
|
-
cf.api_key = 'my_api_key'
|
33
|
-
end
|
34
|
-
|
35
|
-
cf = Backup::Storage::CloudFiles.new do |cf|
|
36
|
-
cf.container = 'my_container'
|
37
|
-
cf.path = 'my/backups'
|
38
|
-
end
|
39
|
-
|
40
|
-
cf.username.should == 'my_username'
|
41
|
-
cf.api_key.should == 'my_api_key'
|
42
|
-
cf.container.should == 'my_container'
|
43
|
-
cf.path.should == 'my/backups'
|
44
|
-
end
|
45
|
-
|
46
|
-
describe '#connection' do
|
47
|
-
it 'should establish a connection to Rackspace Cloud Files. using the provided credentials' do
|
48
|
-
Fog::Storage.expects(:new).with({
|
49
|
-
:provider => 'Rackspace',
|
50
|
-
:rackspace_username => 'my_username',
|
51
|
-
:rackspace_api_key => 'my_api_key'
|
52
|
-
})
|
53
|
-
|
54
|
-
cf.send(:connection)
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
describe '#provider' do
|
59
|
-
it 'should be Rackspace' do
|
60
|
-
cf.provider == 'Rackspace'
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
describe '#transfer!' do
|
65
|
-
let(:connection) { mock('Fog::Storage') }
|
66
|
-
before do
|
67
|
-
Fog::Storage.stubs(:new).returns(connection)
|
68
|
-
Backup::Logger.stubs(:message)
|
69
|
-
end
|
70
|
-
|
71
|
-
it 'should transfer the provided file to the container' do
|
72
|
-
Backup::Model.new('blah', 'blah') {}
|
73
|
-
file = mock("Backup::Storage::CloudFiles::File")
|
74
|
-
File.expects(:open).with("#{File.join(Backup::TMP_PATH, "#{ Backup::TIME }.#{ Backup::TRIGGER}")}.tar").returns(file)
|
75
|
-
cf.expects(:remote_file).returns("#{ Backup::TIME }.#{ Backup::TRIGGER }.tar").twice
|
76
|
-
connection.expects(:put_object).with('my_container', "backups/myapp/#{ Backup::TIME }.#{ Backup::TRIGGER }.tar", file)
|
77
|
-
cf.send(:transfer!)
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
describe '#remove!' do
|
82
|
-
let(:connection) { mock('Fog::Storage') }
|
83
|
-
before do
|
84
|
-
Fog::Storage.stubs(:new).returns(connection)
|
85
|
-
end
|
86
|
-
|
87
|
-
it 'should remove the file from the container' do
|
88
|
-
cf.expects(:remote_file).returns("#{ Backup::TIME }.#{ Backup::TRIGGER }.tar")
|
89
|
-
connection.expects(:delete_object).with('my_container', "backups/myapp/#{ Backup::TIME }.#{ Backup::TRIGGER }.tar")
|
90
|
-
cf.send(:remove!)
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
describe '#perform' do
|
95
|
-
it 'should invoke transfer! and cycle!' do
|
96
|
-
cf.expects(:transfer!)
|
97
|
-
cf.expects(:cycle!)
|
98
|
-
cf.perform!
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
end
|
@@ -1,89 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require File.dirname(__FILE__) + '/../spec_helper'
|
4
|
-
|
5
|
-
describe Backup::Storage::Dropbox do
|
6
|
-
|
7
|
-
let(:db) do
|
8
|
-
Backup::Storage::Dropbox.new do |db|
|
9
|
-
db.email = 'my@email.com'
|
10
|
-
db.password = 'my_password'
|
11
|
-
db.api_key = 'my_api_key'
|
12
|
-
db.api_secret = 'my_secret'
|
13
|
-
db.keep = 20
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
let(:connection) do
|
18
|
-
c = mock("Dropbox::Session")
|
19
|
-
db.stubs(:connection).returns(c); c
|
20
|
-
end
|
21
|
-
|
22
|
-
before do
|
23
|
-
Backup::Configuration::Storage::Dropbox.clear_defaults!
|
24
|
-
end
|
25
|
-
|
26
|
-
it 'should have defined the configuration properly' do
|
27
|
-
db.email.should == 'my@email.com'
|
28
|
-
db.password.should == 'my_password'
|
29
|
-
db.api_key.should == 'my_api_key'
|
30
|
-
db.api_secret.should == 'my_secret'
|
31
|
-
db.path.should == 'backups'
|
32
|
-
db.keep.should == 20
|
33
|
-
end
|
34
|
-
|
35
|
-
it 'should overwrite the default path' do
|
36
|
-
db = Backup::Storage::Dropbox.new do |db|
|
37
|
-
db.path = 'my/backups'
|
38
|
-
end
|
39
|
-
|
40
|
-
db.path.should == 'my/backups'
|
41
|
-
end
|
42
|
-
|
43
|
-
describe '#connection' do
|
44
|
-
it do
|
45
|
-
session = mock("Dropbox::Session")
|
46
|
-
Dropbox::Session.expects(:new).with('my_api_key', 'my_secret').returns(session)
|
47
|
-
session.expects(:mode=).with(:dropbox)
|
48
|
-
session.expects(:authorizing_user=).with('my@email.com')
|
49
|
-
session.expects(:authorizing_password=).with('my_password')
|
50
|
-
session.expects(:authorize!)
|
51
|
-
|
52
|
-
db.send(:connection)
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
describe '#transfer!' do
|
57
|
-
before do
|
58
|
-
Backup::Logger.stubs(:message)
|
59
|
-
connection.stubs(:upload)
|
60
|
-
connection.stubs(:delete)
|
61
|
-
end
|
62
|
-
|
63
|
-
it do
|
64
|
-
Backup::Logger.expects(:message).with("Backup::Storage::Dropbox started transferring \"#{ Backup::TIME }.#{ Backup::TRIGGER }.tar\".")
|
65
|
-
db.send(:transfer!)
|
66
|
-
end
|
67
|
-
|
68
|
-
it do
|
69
|
-
connection.expects(:upload).with(
|
70
|
-
File.join(Backup::TMP_PATH, "#{ Backup::TIME }.#{ Backup::TRIGGER }.tar"),
|
71
|
-
File.join('backups', Backup::TRIGGER),
|
72
|
-
:timeout => 300
|
73
|
-
)
|
74
|
-
|
75
|
-
db.send(:transfer!)
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
describe '#remove!' do
|
80
|
-
it do
|
81
|
-
connection.expects(:delete).with(
|
82
|
-
File.join('backups', Backup::TRIGGER, "#{ Backup::TIME }.#{ Backup::TRIGGER }.tar")
|
83
|
-
)
|
84
|
-
|
85
|
-
db.send(:remove!)
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
end
|
data/spec/storage/ftp_spec.rb
DELETED
@@ -1,133 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require File.dirname(__FILE__) + '/../spec_helper'
|
4
|
-
|
5
|
-
describe Backup::Storage::FTP do
|
6
|
-
|
7
|
-
let(:ftp) do
|
8
|
-
Backup::Storage::FTP.new do |ftp|
|
9
|
-
ftp.username = 'my_username'
|
10
|
-
ftp.password = 'my_password'
|
11
|
-
ftp.ip = '123.45.678.90'
|
12
|
-
ftp.port = 21
|
13
|
-
ftp.path = '~/backups/'
|
14
|
-
ftp.keep = 20
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
before do
|
19
|
-
Backup::Configuration::Storage::FTP.clear_defaults!
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'should have defined the configuration properly' do
|
23
|
-
ftp.username.should == 'my_username'
|
24
|
-
ftp.password.should == 'my_password'
|
25
|
-
ftp.ip.should == '123.45.678.90'
|
26
|
-
ftp.port.should == 21
|
27
|
-
ftp.path.should == 'backups/'
|
28
|
-
ftp.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::FTP.defaults do |ftp|
|
33
|
-
ftp.username = 'my_default_username'
|
34
|
-
ftp.password = 'my_default_password'
|
35
|
-
ftp.path = '~/backups'
|
36
|
-
end
|
37
|
-
|
38
|
-
ftp = Backup::Storage::FTP.new do |ftp|
|
39
|
-
ftp.password = 'my_password'
|
40
|
-
ftp.ip = '123.45.678.90'
|
41
|
-
end
|
42
|
-
|
43
|
-
ftp.username.should == 'my_default_username'
|
44
|
-
ftp.password.should == 'my_password'
|
45
|
-
ftp.ip.should == '123.45.678.90'
|
46
|
-
ftp.port.should == 21
|
47
|
-
end
|
48
|
-
|
49
|
-
it 'should have its own defaults' do
|
50
|
-
ftp = Backup::Storage::FTP.new
|
51
|
-
ftp.port.should == 21
|
52
|
-
ftp.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::FTP.expects(:new).with('123.45.678.90', 'my_username', 'my_password')
|
58
|
-
ftp.send(:connection)
|
59
|
-
end
|
60
|
-
|
61
|
-
it 'should re-define the Net::FTP port' do
|
62
|
-
Net::FTP.stubs(:new)
|
63
|
-
ftp.port = 40
|
64
|
-
ftp.send(:connection)
|
65
|
-
Net::FTP::FTP_PORT.should == 40
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
describe '#transfer!' do
|
70
|
-
let(:connection) { mock('Fog::Storage') }
|
71
|
-
|
72
|
-
before do
|
73
|
-
Net::FTP.stubs(:new).returns(connection)
|
74
|
-
ftp.stubs(:create_remote_directories!)
|
75
|
-
Backup::Logger.stubs(:message)
|
76
|
-
end
|
77
|
-
|
78
|
-
it 'should transfer the provided file to the path' do
|
79
|
-
Backup::Model.new('blah', 'blah') {}
|
80
|
-
file = mock("Backup::Storage::FTP::File")
|
81
|
-
|
82
|
-
ftp.expects(:create_remote_directories!)
|
83
|
-
connection.expects(:put).with(
|
84
|
-
File.join(Backup::TMP_PATH, "#{ Backup::TIME }.#{ Backup::TRIGGER }.tar"),
|
85
|
-
File.join('backups/myapp', "#{ Backup::TIME }.#{ Backup::TRIGGER }.tar")
|
86
|
-
)
|
87
|
-
|
88
|
-
ftp.send(:transfer!)
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
describe '#remove!' do
|
93
|
-
let(:connection) { mock('Net::FTP') }
|
94
|
-
|
95
|
-
before do
|
96
|
-
Net::FTP.stubs(:new).returns(connection)
|
97
|
-
end
|
98
|
-
|
99
|
-
it 'should remove the file from the remote server path' do
|
100
|
-
connection.expects(:delete).with("backups/myapp/#{ Backup::TIME }.#{ Backup::TRIGGER }.tar")
|
101
|
-
ftp.send(:remove!)
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
describe '#create_remote_directories!' do
|
106
|
-
let(:connection) { mock('Net::FTP') }
|
107
|
-
|
108
|
-
before do
|
109
|
-
Net::FTP.stubs(:new).returns(connection)
|
110
|
-
end
|
111
|
-
|
112
|
-
it 'should properly create remote directories one by one' do
|
113
|
-
ftp.path = '~/backups/some_other_folder/another_folder'
|
114
|
-
|
115
|
-
connection.expects(:mkdir).with('~')
|
116
|
-
connection.expects(:mkdir).with('~/backups')
|
117
|
-
connection.expects(:mkdir).with('~/backups/some_other_folder')
|
118
|
-
connection.expects(:mkdir).with('~/backups/some_other_folder/another_folder')
|
119
|
-
connection.expects(:mkdir).with('~/backups/some_other_folder/another_folder/myapp')
|
120
|
-
|
121
|
-
ftp.send(:create_remote_directories!)
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
describe '#perform' do
|
126
|
-
it 'should invoke transfer! and cycle!' do
|
127
|
-
ftp.expects(:transfer!)
|
128
|
-
ftp.expects(:cycle!)
|
129
|
-
ftp.perform!
|
130
|
-
end
|
131
|
-
end
|
132
|
-
|
133
|
-
end
|