backup 2.4.5.1 → 3.0.0.build.0
Sign up to get free protection for your applications and to get access to all the features.
- 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 +189 -75
- data/backup.gemspec +41 -0
- data/bin/backup +161 -90
- data/lib/backup.rb +133 -117
- 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 +7 -67
- 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 +47 -17
- 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/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 +80 -0
- data/lib/backup/model.rb +249 -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 +60 -3
- data/lib/backup/storage/cloudfiles.rb +85 -6
- data/lib/backup/storage/dropbox.rb +74 -4
- data/lib/backup/storage/ftp.rb +103 -27
- data/lib/backup/storage/object.rb +45 -0
- data/lib/backup/storage/rsync.rb +100 -0
- data/lib/backup/storage/s3.rb +100 -7
- data/lib/backup/storage/scp.rb +94 -19
- data/lib/backup/storage/sftp.rb +94 -19
- data/lib/backup/version.rb +70 -1
- 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/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/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 +37 -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/version_spec.rb +32 -0
- metadata +139 -123
- data/CHANGELOG +0 -131
- data/LICENSE +0 -20
- data/generators/backup/backup_generator.rb +0 -69
- data/generators/backup/templates/backup.rake +0 -56
- data/generators/backup/templates/backup.rb +0 -253
- data/generators/backup/templates/create_backup_tables.rb +0 -18
- data/generators/backup_update/backup_update_generator.rb +0 -50
- data/generators/backup_update/templates/migrations/update_backup_tables.rb +0 -27
- data/lib/backup/adapters/archive.rb +0 -34
- data/lib/backup/adapters/base.rb +0 -167
- data/lib/backup/adapters/custom.rb +0 -41
- data/lib/backup/adapters/mongo_db.rb +0 -139
- data/lib/backup/adapters/mysql.rb +0 -60
- data/lib/backup/adapters/postgresql.rb +0 -60
- data/lib/backup/adapters/sqlite.rb +0 -25
- data/lib/backup/command_helper.rb +0 -14
- data/lib/backup/configuration/adapter.rb +0 -21
- data/lib/backup/configuration/adapter_options.rb +0 -8
- data/lib/backup/configuration/attributes.rb +0 -19
- data/lib/backup/configuration/mail.rb +0 -20
- data/lib/backup/configuration/smtp.rb +0 -8
- data/lib/backup/configuration/storage.rb +0 -8
- data/lib/backup/connection/cloudfiles.rb +0 -75
- data/lib/backup/connection/dropbox.rb +0 -63
- data/lib/backup/connection/s3.rb +0 -88
- data/lib/backup/core_ext/object.rb +0 -5
- data/lib/backup/environment/base.rb +0 -12
- data/lib/backup/environment/rails_configuration.rb +0 -15
- data/lib/backup/environment/unix_configuration.rb +0 -109
- data/lib/backup/mail/base.rb +0 -97
- data/lib/backup/mail/mail.txt +0 -7
- data/lib/backup/record/base.rb +0 -65
- data/lib/backup/record/cloudfiles.rb +0 -28
- data/lib/backup/record/dropbox.rb +0 -27
- data/lib/backup/record/ftp.rb +0 -39
- data/lib/backup/record/local.rb +0 -26
- data/lib/backup/record/s3.rb +0 -25
- data/lib/backup/record/scp.rb +0 -33
- data/lib/backup/record/sftp.rb +0 -38
- data/lib/backup/storage/local.rb +0 -22
- data/lib/generators/backup/USAGE +0 -10
- data/lib/generators/backup/backup_generator.rb +0 -47
- data/lib/generators/backup/templates/backup.rake +0 -56
- data/lib/generators/backup/templates/backup.rb +0 -236
- data/lib/generators/backup/templates/create_backup_tables.rb +0 -18
- data/setup/backup.rb +0 -257
- data/setup/backup.sqlite3 +0 -0
@@ -0,0 +1,74 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
4
|
+
|
5
|
+
describe Backup::Storage::Object do
|
6
|
+
let(:object) { Backup::Storage::Object.new(:s3) }
|
7
|
+
|
8
|
+
it do
|
9
|
+
object.storage_file.should == File.join(Backup::DATA_PATH, Backup::TRIGGER, 's3.yml')
|
10
|
+
end
|
11
|
+
|
12
|
+
describe '#load' do
|
13
|
+
it 'should return an array with objects' do
|
14
|
+
File.expects(:exist?).returns(true)
|
15
|
+
YAML.expects(:load_file).with(
|
16
|
+
File.join(Backup::DATA_PATH, Backup::TRIGGER, 's3.yml')
|
17
|
+
).returns(YAML.load([Backup::Storage::S3.new, Backup::Storage::S3.new].to_yaml))
|
18
|
+
|
19
|
+
objects = object.load
|
20
|
+
objects.should be_an(Array)
|
21
|
+
objects.first.should be_an_instance_of(Backup::Storage::S3)
|
22
|
+
end
|
23
|
+
|
24
|
+
describe 'loading them sorted by time descending (newest backup is first in the array)' do
|
25
|
+
it do
|
26
|
+
obj_1 = Backup::Storage::S3.new; obj_1.time = '2007.00.00.00.00.00'
|
27
|
+
obj_2 = Backup::Storage::S3.new; obj_2.time = '2009.00.00.00.00.00'
|
28
|
+
obj_3 = Backup::Storage::S3.new; obj_3.time = '2011.00.00.00.00.00'
|
29
|
+
|
30
|
+
File.expects(:exist?).returns(true)
|
31
|
+
YAML.expects(:load_file).with(
|
32
|
+
File.join(Backup::DATA_PATH, Backup::TRIGGER, 's3.yml')
|
33
|
+
).returns(YAML.load([obj_1, obj_2, obj_3].to_yaml))
|
34
|
+
|
35
|
+
objects = object.load
|
36
|
+
objects[0].time.should == '2011.00.00.00.00.00'
|
37
|
+
objects[1].time.should == '2009.00.00.00.00.00'
|
38
|
+
objects[2].time.should == '2007.00.00.00.00.00'
|
39
|
+
end
|
40
|
+
|
41
|
+
it do
|
42
|
+
obj_3 = Backup::Storage::S3.new; obj_3.time = '2007.00.00.00.00.00'
|
43
|
+
obj_2 = Backup::Storage::S3.new; obj_2.time = '2009.00.00.00.00.00'
|
44
|
+
obj_1 = Backup::Storage::S3.new; obj_1.time = '2011.00.00.00.00.00'
|
45
|
+
|
46
|
+
File.expects(:exist?).returns(true)
|
47
|
+
YAML.expects(:load_file).with(
|
48
|
+
File.join(Backup::DATA_PATH, Backup::TRIGGER, 's3.yml')
|
49
|
+
).returns(YAML.load([obj_1, obj_2, obj_3].to_yaml))
|
50
|
+
|
51
|
+
objects = object.load
|
52
|
+
objects[0].time.should == '2011.00.00.00.00.00'
|
53
|
+
objects[1].time.should == '2009.00.00.00.00.00'
|
54
|
+
objects[2].time.should == '2007.00.00.00.00.00'
|
55
|
+
end
|
56
|
+
|
57
|
+
it do
|
58
|
+
obj_3 = Backup::Storage::S3.new; obj_3.time = '2007.00.00.00.00.00'
|
59
|
+
obj_1 = Backup::Storage::S3.new; obj_1.time = '2009.00.00.00.00.00'
|
60
|
+
obj_2 = Backup::Storage::S3.new; obj_2.time = '2011.00.00.00.00.00'
|
61
|
+
|
62
|
+
File.expects(:exist?).returns(true)
|
63
|
+
YAML.expects(:load_file).with(
|
64
|
+
File.join(Backup::DATA_PATH, Backup::TRIGGER, 's3.yml')
|
65
|
+
).returns(YAML.load([obj_1, obj_2, obj_3].to_yaml))
|
66
|
+
|
67
|
+
objects = object.load
|
68
|
+
objects[0].time.should == '2011.00.00.00.00.00'
|
69
|
+
objects[1].time.should == '2009.00.00.00.00.00'
|
70
|
+
objects[2].time.should == '2007.00.00.00.00.00'
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -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 -e ssh --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(:read).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
|