backup 3.0.2 → 3.0.3.build.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (121) hide show
  1. data/bin/backup +12 -190
  2. metadata +7 -191
  3. data/.gitignore +0 -2
  4. data/.infinity_test +0 -7
  5. data/.rspec +0 -3
  6. data/Gemfile +0 -17
  7. data/Gemfile.lock +0 -88
  8. data/LICENSE.md +0 -24
  9. data/README.md +0 -236
  10. data/backup.gemspec +0 -41
  11. data/lib/backup.rb +0 -148
  12. data/lib/backup/archive.rb +0 -54
  13. data/lib/backup/cli.rb +0 -50
  14. data/lib/backup/compressor/base.rb +0 -17
  15. data/lib/backup/compressor/gzip.rb +0 -61
  16. data/lib/backup/configuration/base.rb +0 -15
  17. data/lib/backup/configuration/compressor/base.rb +0 -10
  18. data/lib/backup/configuration/compressor/gzip.rb +0 -23
  19. data/lib/backup/configuration/database/base.rb +0 -18
  20. data/lib/backup/configuration/database/mongodb.rb +0 -37
  21. data/lib/backup/configuration/database/mysql.rb +0 -37
  22. data/lib/backup/configuration/database/postgresql.rb +0 -37
  23. data/lib/backup/configuration/database/redis.rb +0 -35
  24. data/lib/backup/configuration/encryptor/base.rb +0 -10
  25. data/lib/backup/configuration/encryptor/gpg.rb +0 -17
  26. data/lib/backup/configuration/encryptor/open_ssl.rb +0 -26
  27. data/lib/backup/configuration/helpers.rb +0 -54
  28. data/lib/backup/configuration/notifier/base.rb +0 -39
  29. data/lib/backup/configuration/notifier/mail.rb +0 -52
  30. data/lib/backup/configuration/storage/base.rb +0 -18
  31. data/lib/backup/configuration/storage/cloudfiles.rb +0 -21
  32. data/lib/backup/configuration/storage/dropbox.rb +0 -25
  33. data/lib/backup/configuration/storage/ftp.rb +0 -25
  34. data/lib/backup/configuration/storage/rsync.rb +0 -25
  35. data/lib/backup/configuration/storage/s3.rb +0 -25
  36. data/lib/backup/configuration/storage/scp.rb +0 -25
  37. data/lib/backup/configuration/storage/sftp.rb +0 -25
  38. data/lib/backup/database/base.rb +0 -33
  39. data/lib/backup/database/mongodb.rb +0 -137
  40. data/lib/backup/database/mysql.rb +0 -104
  41. data/lib/backup/database/postgresql.rb +0 -111
  42. data/lib/backup/database/redis.rb +0 -105
  43. data/lib/backup/encryptor/base.rb +0 -17
  44. data/lib/backup/encryptor/gpg.rb +0 -78
  45. data/lib/backup/encryptor/open_ssl.rb +0 -67
  46. data/lib/backup/finder.rb +0 -39
  47. data/lib/backup/logger.rb +0 -80
  48. data/lib/backup/model.rb +0 -249
  49. data/lib/backup/notifier/base.rb +0 -29
  50. data/lib/backup/notifier/binder.rb +0 -32
  51. data/lib/backup/notifier/mail.rb +0 -141
  52. data/lib/backup/notifier/templates/notify_failure.erb +0 -31
  53. data/lib/backup/notifier/templates/notify_success.erb +0 -16
  54. data/lib/backup/storage/base.rb +0 -67
  55. data/lib/backup/storage/cloudfiles.rb +0 -95
  56. data/lib/backup/storage/dropbox.rb +0 -82
  57. data/lib/backup/storage/ftp.rb +0 -114
  58. data/lib/backup/storage/object.rb +0 -45
  59. data/lib/backup/storage/rsync.rb +0 -100
  60. data/lib/backup/storage/s3.rb +0 -108
  61. data/lib/backup/storage/scp.rb +0 -105
  62. data/lib/backup/storage/sftp.rb +0 -106
  63. data/lib/backup/version.rb +0 -72
  64. data/lib/templates/archive +0 -4
  65. data/lib/templates/compressor/gzip +0 -4
  66. data/lib/templates/database/mongodb +0 -10
  67. data/lib/templates/database/mysql +0 -11
  68. data/lib/templates/database/postgresql +0 -11
  69. data/lib/templates/database/redis +0 -10
  70. data/lib/templates/encryptor/gpg +0 -9
  71. data/lib/templates/encryptor/openssl +0 -5
  72. data/lib/templates/notifier/mail +0 -14
  73. data/lib/templates/readme +0 -15
  74. data/lib/templates/storage/cloudfiles +0 -7
  75. data/lib/templates/storage/dropbox +0 -8
  76. data/lib/templates/storage/ftp +0 -8
  77. data/lib/templates/storage/rsync +0 -7
  78. data/lib/templates/storage/s3 +0 -8
  79. data/lib/templates/storage/scp +0 -8
  80. data/lib/templates/storage/sftp +0 -8
  81. data/spec/archive_spec.rb +0 -53
  82. data/spec/backup_spec.rb +0 -11
  83. data/spec/compressor/gzip_spec.rb +0 -59
  84. data/spec/configuration/base_spec.rb +0 -35
  85. data/spec/configuration/compressor/gzip_spec.rb +0 -28
  86. data/spec/configuration/database/base_spec.rb +0 -16
  87. data/spec/configuration/database/mongodb_spec.rb +0 -30
  88. data/spec/configuration/database/mysql_spec.rb +0 -32
  89. data/spec/configuration/database/postgresql_spec.rb +0 -32
  90. data/spec/configuration/database/redis_spec.rb +0 -30
  91. data/spec/configuration/encryptor/gpg_spec.rb +0 -25
  92. data/spec/configuration/encryptor/open_ssl_spec.rb +0 -31
  93. data/spec/configuration/notifier/mail_spec.rb +0 -32
  94. data/spec/configuration/storage/cloudfiles_spec.rb +0 -34
  95. data/spec/configuration/storage/dropbox_spec.rb +0 -40
  96. data/spec/configuration/storage/ftp_spec.rb +0 -40
  97. data/spec/configuration/storage/rsync_spec.rb +0 -37
  98. data/spec/configuration/storage/s3_spec.rb +0 -37
  99. data/spec/configuration/storage/scp_spec.rb +0 -40
  100. data/spec/configuration/storage/sftp_spec.rb +0 -40
  101. data/spec/database/base_spec.rb +0 -30
  102. data/spec/database/mongodb_spec.rb +0 -144
  103. data/spec/database/mysql_spec.rb +0 -150
  104. data/spec/database/postgresql_spec.rb +0 -164
  105. data/spec/database/redis_spec.rb +0 -122
  106. data/spec/encryptor/gpg_spec.rb +0 -57
  107. data/spec/encryptor/open_ssl_spec.rb +0 -102
  108. data/spec/logger_spec.rb +0 -37
  109. data/spec/model_spec.rb +0 -236
  110. data/spec/notifier/mail_spec.rb +0 -97
  111. data/spec/spec_helper.rb +0 -21
  112. data/spec/storage/base_spec.rb +0 -33
  113. data/spec/storage/cloudfiles_spec.rb +0 -102
  114. data/spec/storage/dropbox_spec.rb +0 -89
  115. data/spec/storage/ftp_spec.rb +0 -133
  116. data/spec/storage/object_spec.rb +0 -74
  117. data/spec/storage/rsync_spec.rb +0 -115
  118. data/spec/storage/s3_spec.rb +0 -110
  119. data/spec/storage/scp_spec.rb +0 -129
  120. data/spec/storage/sftp_spec.rb +0 -125
  121. data/spec/version_spec.rb +0 -32
@@ -1,74 +0,0 @@
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
@@ -1,115 +0,0 @@
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
@@ -1,110 +0,0 @@
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
@@ -1,129 +0,0 @@
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
@@ -1,125 +0,0 @@
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