alg-backup 3.0.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (137) hide show
  1. data/.gitignore +2 -0
  2. data/.infinity_test +7 -0
  3. data/.rspec +3 -0
  4. data/Gemfile +25 -0
  5. data/Gemfile.lock +101 -0
  6. data/LICENSE.md +24 -0
  7. data/README.md +276 -0
  8. data/backup.gemspec +39 -0
  9. data/bin/backup +260 -0
  10. data/lib/backup.rb +168 -0
  11. data/lib/backup/archive.rb +73 -0
  12. data/lib/backup/cli.rb +50 -0
  13. data/lib/backup/compressor/base.rb +17 -0
  14. data/lib/backup/compressor/gzip.rb +61 -0
  15. data/lib/backup/configuration/base.rb +15 -0
  16. data/lib/backup/configuration/compressor/base.rb +10 -0
  17. data/lib/backup/configuration/compressor/gzip.rb +23 -0
  18. data/lib/backup/configuration/database/base.rb +18 -0
  19. data/lib/backup/configuration/database/mongodb.rb +37 -0
  20. data/lib/backup/configuration/database/mysql.rb +37 -0
  21. data/lib/backup/configuration/database/postgresql.rb +37 -0
  22. data/lib/backup/configuration/database/redis.rb +35 -0
  23. data/lib/backup/configuration/encryptor/base.rb +10 -0
  24. data/lib/backup/configuration/encryptor/gpg.rb +17 -0
  25. data/lib/backup/configuration/encryptor/open_ssl.rb +26 -0
  26. data/lib/backup/configuration/helpers.rb +54 -0
  27. data/lib/backup/configuration/notifier/base.rb +39 -0
  28. data/lib/backup/configuration/notifier/mail.rb +52 -0
  29. data/lib/backup/configuration/notifier/twitter.rb +21 -0
  30. data/lib/backup/configuration/storage/base.rb +18 -0
  31. data/lib/backup/configuration/storage/cloudfiles.rb +21 -0
  32. data/lib/backup/configuration/storage/dropbox.rb +29 -0
  33. data/lib/backup/configuration/storage/ftp.rb +25 -0
  34. data/lib/backup/configuration/storage/rsync.rb +25 -0
  35. data/lib/backup/configuration/storage/s3.rb +25 -0
  36. data/lib/backup/configuration/storage/scp.rb +25 -0
  37. data/lib/backup/configuration/storage/sftp.rb +25 -0
  38. data/lib/backup/configuration/syncer/rsync.rb +45 -0
  39. data/lib/backup/configuration/syncer/s3.rb +33 -0
  40. data/lib/backup/database/base.rb +33 -0
  41. data/lib/backup/database/mongodb.rb +137 -0
  42. data/lib/backup/database/mysql.rb +104 -0
  43. data/lib/backup/database/postgresql.rb +111 -0
  44. data/lib/backup/database/redis.rb +105 -0
  45. data/lib/backup/dependency.rb +84 -0
  46. data/lib/backup/encryptor/base.rb +17 -0
  47. data/lib/backup/encryptor/gpg.rb +78 -0
  48. data/lib/backup/encryptor/open_ssl.rb +67 -0
  49. data/lib/backup/finder.rb +39 -0
  50. data/lib/backup/logger.rb +86 -0
  51. data/lib/backup/model.rb +272 -0
  52. data/lib/backup/notifier/base.rb +29 -0
  53. data/lib/backup/notifier/binder.rb +32 -0
  54. data/lib/backup/notifier/mail.rb +141 -0
  55. data/lib/backup/notifier/templates/notify_failure.erb +31 -0
  56. data/lib/backup/notifier/templates/notify_success.erb +16 -0
  57. data/lib/backup/notifier/twitter.rb +87 -0
  58. data/lib/backup/storage/base.rb +67 -0
  59. data/lib/backup/storage/cloudfiles.rb +95 -0
  60. data/lib/backup/storage/dropbox.rb +87 -0
  61. data/lib/backup/storage/ftp.rb +114 -0
  62. data/lib/backup/storage/object.rb +45 -0
  63. data/lib/backup/storage/rsync.rb +99 -0
  64. data/lib/backup/storage/s3.rb +108 -0
  65. data/lib/backup/storage/scp.rb +106 -0
  66. data/lib/backup/storage/sftp.rb +106 -0
  67. data/lib/backup/syncer/base.rb +10 -0
  68. data/lib/backup/syncer/rsync.rb +117 -0
  69. data/lib/backup/syncer/s3.rb +116 -0
  70. data/lib/backup/version.rb +43 -0
  71. data/lib/templates/archive +4 -0
  72. data/lib/templates/compressor/gzip +4 -0
  73. data/lib/templates/database/mongodb +10 -0
  74. data/lib/templates/database/mysql +11 -0
  75. data/lib/templates/database/postgresql +11 -0
  76. data/lib/templates/database/redis +10 -0
  77. data/lib/templates/encryptor/gpg +9 -0
  78. data/lib/templates/encryptor/openssl +5 -0
  79. data/lib/templates/notifier/mail +14 -0
  80. data/lib/templates/notifier/twitter +9 -0
  81. data/lib/templates/readme +15 -0
  82. data/lib/templates/storage/cloudfiles +7 -0
  83. data/lib/templates/storage/dropbox +9 -0
  84. data/lib/templates/storage/ftp +8 -0
  85. data/lib/templates/storage/rsync +7 -0
  86. data/lib/templates/storage/s3 +8 -0
  87. data/lib/templates/storage/scp +8 -0
  88. data/lib/templates/storage/sftp +8 -0
  89. data/lib/templates/syncer/rsync +14 -0
  90. data/lib/templates/syncer/s3 +12 -0
  91. data/spec/archive_spec.rb +90 -0
  92. data/spec/backup_spec.rb +11 -0
  93. data/spec/compressor/gzip_spec.rb +59 -0
  94. data/spec/configuration/base_spec.rb +35 -0
  95. data/spec/configuration/compressor/gzip_spec.rb +28 -0
  96. data/spec/configuration/database/base_spec.rb +16 -0
  97. data/spec/configuration/database/mongodb_spec.rb +30 -0
  98. data/spec/configuration/database/mysql_spec.rb +32 -0
  99. data/spec/configuration/database/postgresql_spec.rb +32 -0
  100. data/spec/configuration/database/redis_spec.rb +30 -0
  101. data/spec/configuration/encryptor/gpg_spec.rb +25 -0
  102. data/spec/configuration/encryptor/open_ssl_spec.rb +31 -0
  103. data/spec/configuration/notifier/mail_spec.rb +32 -0
  104. data/spec/configuration/storage/cloudfiles_spec.rb +34 -0
  105. data/spec/configuration/storage/dropbox_spec.rb +43 -0
  106. data/spec/configuration/storage/ftp_spec.rb +40 -0
  107. data/spec/configuration/storage/rsync_spec.rb +37 -0
  108. data/spec/configuration/storage/s3_spec.rb +37 -0
  109. data/spec/configuration/storage/scp_spec.rb +40 -0
  110. data/spec/configuration/storage/sftp_spec.rb +40 -0
  111. data/spec/configuration/syncer/rsync_spec.rb +46 -0
  112. data/spec/configuration/syncer/s3_spec.rb +43 -0
  113. data/spec/database/base_spec.rb +30 -0
  114. data/spec/database/mongodb_spec.rb +144 -0
  115. data/spec/database/mysql_spec.rb +150 -0
  116. data/spec/database/postgresql_spec.rb +164 -0
  117. data/spec/database/redis_spec.rb +122 -0
  118. data/spec/encryptor/gpg_spec.rb +57 -0
  119. data/spec/encryptor/open_ssl_spec.rb +102 -0
  120. data/spec/logger_spec.rb +46 -0
  121. data/spec/model_spec.rb +236 -0
  122. data/spec/notifier/mail_spec.rb +97 -0
  123. data/spec/notifier/twitter_spec.rb +86 -0
  124. data/spec/spec_helper.rb +21 -0
  125. data/spec/storage/base_spec.rb +33 -0
  126. data/spec/storage/cloudfiles_spec.rb +102 -0
  127. data/spec/storage/dropbox_spec.rb +105 -0
  128. data/spec/storage/ftp_spec.rb +133 -0
  129. data/spec/storage/object_spec.rb +74 -0
  130. data/spec/storage/rsync_spec.rb +115 -0
  131. data/spec/storage/s3_spec.rb +110 -0
  132. data/spec/storage/scp_spec.rb +129 -0
  133. data/spec/storage/sftp_spec.rb +125 -0
  134. data/spec/syncer/rsync_spec.rb +156 -0
  135. data/spec/syncer/s3_spec.rb +139 -0
  136. data/spec/version_spec.rb +21 -0
  137. metadata +217 -0
@@ -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
@@ -0,0 +1,156 @@
1
+ # encoding: utf-8
2
+
3
+ require File.dirname(__FILE__) + '/../spec_helper'
4
+
5
+ describe Backup::Syncer::RSync do
6
+
7
+ let(:rsync) do
8
+ Backup::Syncer::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
+ rsync.mirror = true
15
+ rsync.compress = true
16
+ rsync.additional_options = []
17
+
18
+ rsync.directories do |directory|
19
+ directory.add "/some/random/directory"
20
+ directory.add "/another/random/directory"
21
+ end
22
+ end
23
+ end
24
+
25
+ before do
26
+ Backup::Configuration::Syncer::RSync.clear_defaults!
27
+ end
28
+
29
+ it 'should have defined the configuration properly' do
30
+ rsync.username.should == 'my_username'
31
+ rsync.password.should == 'my_password'
32
+ rsync.ip.should == '123.45.678.90'
33
+ rsync.port.should == "--port='22'"
34
+ rsync.path.should == 'backups/'
35
+ rsync.mirror.should == "--delete"
36
+ rsync.compress.should == "--compress"
37
+ end
38
+
39
+ it 'should use the defaults if a particular attribute has not been defined' do
40
+ Backup::Configuration::Syncer::RSync.defaults do |rsync|
41
+ rsync.username = 'my_default_username'
42
+ rsync.password = 'my_default_password'
43
+ rsync.path = '~/backups'
44
+ rsync.mirror = false
45
+ end
46
+
47
+ rsync = Backup::Syncer::RSync.new do |rsync|
48
+ rsync.password = 'my_password'
49
+ rsync.ip = '123.45.678.90'
50
+ rsync.compress = false
51
+ end
52
+
53
+ rsync.username.should == 'my_default_username'
54
+ rsync.password.should == 'my_password'
55
+ rsync.ip.should == '123.45.678.90'
56
+ rsync.port.should == "--port='22'"
57
+ rsync.mirror.should == nil
58
+ rsync.compress.should == nil
59
+ end
60
+
61
+ it 'should have its own defaults' do
62
+ rsync = Backup::Syncer::RSync.new
63
+ rsync.port.should == "--port='22'"
64
+ rsync.path.should == 'backups'
65
+ rsync.compress.should == nil
66
+ rsync.mirror.should == nil
67
+ rsync.directories.should == ''
68
+ rsync.additional_options.should == []
69
+ end
70
+
71
+ describe '#mirror' do
72
+ context 'when true' do
73
+ it do
74
+ rsync.mirror = true
75
+ rsync.mirror.should == '--delete'
76
+ end
77
+ end
78
+
79
+ context 'when nil/false' do
80
+ it do
81
+ rsync.mirror = nil
82
+ rsync.mirror.should == nil
83
+ end
84
+
85
+ it do
86
+ rsync.mirror = false
87
+ rsync.mirror.should == nil
88
+ end
89
+ end
90
+ end
91
+
92
+ describe '#compress' do
93
+ context 'when true' do
94
+ it do
95
+ rsync.compress = true
96
+ rsync.compress.should == '--compress'
97
+ end
98
+ end
99
+
100
+ context 'when nil/false' do
101
+ it do
102
+ rsync.compress = nil
103
+ rsync.compress.should == nil
104
+ end
105
+
106
+ it do
107
+ rsync.compress = false
108
+ rsync.compress.should == nil
109
+ end
110
+ end
111
+ end
112
+
113
+ describe '#archive' do
114
+ it do
115
+ rsync.archive.should == '--archive'
116
+ end
117
+ end
118
+
119
+ describe '#port' do
120
+ it do
121
+ rsync.port.should == "--port='22'"
122
+ end
123
+ end
124
+
125
+ describe '#directories' do
126
+ context 'when its empty' do
127
+ it do
128
+ rsync.directories = []
129
+ rsync.directories.should == ''
130
+ end
131
+ end
132
+
133
+ context 'when it has items' do
134
+ it do
135
+ rsync.directories = ['directory1', 'directory1/directory2', 'directory1/directory2/directory3']
136
+ rsync.directories.should == "'directory1' 'directory1/directory2' 'directory1/directory2/directory3'"
137
+ end
138
+ end
139
+ end
140
+
141
+ describe '#options' do
142
+ it do
143
+ rsync.options.should == "--archive --delete --compress --port='22'"
144
+ end
145
+ end
146
+
147
+ describe '#perform' do
148
+ it 'should invoke the rsync command to transfer the files and directories' do
149
+ Backup::Logger.expects(:message).with("Backup::Syncer::RSync started syncing '/some/random/directory' '/another/random/directory'.")
150
+ rsync.expects(:utility).with(:rsync).returns(:rsync)
151
+ rsync.expects(:run).with("rsync -vhP --archive --delete --compress --port='22' '/some/random/directory' '/another/random/directory' 'my_username@123.45.678.90:backups/'")
152
+ rsync.perform!
153
+ end
154
+ end
155
+
156
+ end