backup 3.0.16 → 3.0.18

Sign up to get free protection for your applications and to get access to all the features.
Files changed (81) hide show
  1. data/.travis.yml +10 -0
  2. data/Gemfile.lock +50 -47
  3. data/Guardfile +3 -3
  4. data/README.md +136 -81
  5. data/backup.gemspec +3 -2
  6. data/bin/backup +36 -15
  7. data/lib/backup.rb +30 -20
  8. data/lib/backup/cli.rb +30 -2
  9. data/lib/backup/compressor/lzma.rb +63 -0
  10. data/lib/backup/configuration/compressor/lzma.rb +23 -0
  11. data/lib/backup/configuration/helpers.rb +10 -4
  12. data/lib/backup/configuration/notifier/mail.rb +5 -0
  13. data/lib/backup/configuration/storage/dropbox.rb +19 -4
  14. data/lib/backup/configuration/storage/ftp.rb +4 -0
  15. data/lib/backup/configuration/storage/local.rb +17 -0
  16. data/lib/backup/configuration/storage/ninefold.rb +20 -0
  17. data/lib/backup/configuration/storage/rsync.rb +4 -0
  18. data/lib/backup/database/postgresql.rb +12 -3
  19. data/lib/backup/database/redis.rb +5 -1
  20. data/lib/backup/dependency.rb +11 -12
  21. data/lib/backup/encryptor/gpg.rb +2 -0
  22. data/lib/backup/exception/command_failed.rb +8 -0
  23. data/lib/backup/finder.rb +49 -9
  24. data/lib/backup/notifier/mail.rb +7 -1
  25. data/lib/backup/notifier/twitter.rb +1 -1
  26. data/lib/backup/storage/dropbox.rb +93 -16
  27. data/lib/backup/storage/ftp.rb +10 -3
  28. data/lib/backup/storage/local.rb +78 -0
  29. data/lib/backup/storage/ninefold.rb +96 -0
  30. data/lib/backup/storage/rsync.rb +37 -20
  31. data/lib/backup/storage/s3.rb +1 -1
  32. data/lib/backup/storage/scp.rb +1 -1
  33. data/lib/backup/syncer/rsync.rb +1 -1
  34. data/lib/backup/version.rb +1 -1
  35. data/lib/templates/compressor/lzma +7 -0
  36. data/lib/templates/storage/dropbox +2 -2
  37. data/lib/templates/storage/ftp +8 -7
  38. data/lib/templates/storage/local +7 -0
  39. data/lib/templates/storage/ninefold +9 -0
  40. data/lib/templates/storage/rsync +1 -0
  41. data/spec/archive_spec.rb +0 -1
  42. data/spec/compressor/bzip2_spec.rb +0 -1
  43. data/spec/compressor/gzip_spec.rb +0 -1
  44. data/spec/compressor/lzma_spec.rb +58 -0
  45. data/spec/configuration/compressor/bzip2_spec.rb +28 -0
  46. data/spec/configuration/compressor/lzma_spec.rb +28 -0
  47. data/spec/configuration/database/mongodb_spec.rb +16 -0
  48. data/spec/configuration/database/mysql_spec.rb +17 -0
  49. data/spec/configuration/database/postgresql_spec.rb +17 -0
  50. data/spec/configuration/database/redis_spec.rb +16 -0
  51. data/spec/configuration/notifier/campfire_spec.rb +11 -0
  52. data/spec/configuration/notifier/mail_spec.rb +20 -0
  53. data/spec/configuration/notifier/presently_spec.rb +34 -0
  54. data/spec/configuration/notifier/twitter_spec.rb +12 -0
  55. data/spec/configuration/storage/dropbox_spec.rb +0 -6
  56. data/spec/configuration/storage/ftp_spec.rb +15 -12
  57. data/spec/configuration/storage/local_spec.rb +28 -0
  58. data/spec/configuration/storage/ninefold_spec.rb +31 -0
  59. data/spec/configuration/storage/rsync_spec.rb +2 -0
  60. data/spec/database/mongodb_spec.rb +0 -1
  61. data/spec/database/mysql_spec.rb +0 -1
  62. data/spec/database/postgresql_spec.rb +31 -11
  63. data/spec/database/redis_spec.rb +9 -4
  64. data/spec/encryptor/gpg_spec.rb +1 -1
  65. data/spec/encryptor/open_ssl_spec.rb +0 -1
  66. data/spec/logger_spec.rb +32 -24
  67. data/spec/model_spec.rb +15 -15
  68. data/spec/spec_helper.rb +8 -4
  69. data/spec/storage/base_spec.rb +0 -4
  70. data/spec/storage/cloudfiles_spec.rb +0 -1
  71. data/spec/storage/dropbox_spec.rb +44 -14
  72. data/spec/storage/ftp_spec.rb +26 -15
  73. data/spec/storage/local_spec.rb +83 -0
  74. data/spec/storage/ninefold_spec.rb +142 -0
  75. data/spec/storage/object_spec.rb +1 -1
  76. data/spec/storage/rsync_spec.rb +17 -7
  77. data/spec/storage/s3_spec.rb +4 -3
  78. data/spec/storage/scp_spec.rb +0 -1
  79. data/spec/storage/sftp_spec.rb +0 -1
  80. data/spec/syncer/rsync_spec.rb +8 -8
  81. metadata +62 -36
@@ -0,0 +1,28 @@
1
+ # encoding: utf-8
2
+
3
+ require File.dirname(__FILE__) + '/../../spec_helper'
4
+
5
+ describe Backup::Configuration::Compressor::Bzip2 do
6
+ before do
7
+ Backup::Configuration::Compressor::Bzip2.defaults do |compressor|
8
+ compressor.best = true
9
+ compressor.fast = true
10
+ end
11
+ end
12
+
13
+ it 'should set the default compressor configuration' do
14
+ compressor = Backup::Configuration::Compressor::Bzip2
15
+ compressor.best.should == true
16
+ compressor.fast.should == true
17
+ end
18
+
19
+ describe '#clear_defaults!' do
20
+ it 'should clear all the defaults, resetting them to nil' do
21
+ Backup::Configuration::Compressor::Bzip2.clear_defaults!
22
+
23
+ compressor = Backup::Configuration::Compressor::Bzip2
24
+ compressor.best.should == nil
25
+ compressor.fast.should == nil
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,28 @@
1
+ # encoding: utf-8
2
+
3
+ require File.dirname(__FILE__) + '/../../spec_helper'
4
+
5
+ describe Backup::Configuration::Compressor::Lzma do
6
+ before do
7
+ Backup::Configuration::Compressor::Lzma.defaults do |compressor|
8
+ compressor.best = true
9
+ compressor.fast = true
10
+ end
11
+ end
12
+
13
+ it 'should set the default compressor configuration' do
14
+ compressor = Backup::Configuration::Compressor::Lzma
15
+ compressor.best.should == true
16
+ compressor.fast.should == true
17
+ end
18
+
19
+ describe '#clear_defaults!' do
20
+ it 'should clear all the defaults, resetting them to nil' do
21
+ Backup::Configuration::Compressor::Lzma.clear_defaults!
22
+
23
+ compressor = Backup::Configuration::Compressor::Lzma
24
+ compressor.best.should == nil
25
+ compressor.fast.should == nil
26
+ end
27
+ end
28
+ end
@@ -27,4 +27,20 @@ describe Backup::Configuration::Database::MongoDB do
27
27
  db.additional_options.should == %w[my options]
28
28
  db.ipv6.should == true
29
29
  end
30
+
31
+ describe '#clear_defaults!' do
32
+ it 'should clear all the defaults, resetting them to nil' do
33
+ Backup::Configuration::Database::MongoDB.clear_defaults!
34
+
35
+ db = Backup::Configuration::Database::MongoDB
36
+ db.name.should == nil
37
+ db.username.should == nil
38
+ db.password.should == nil
39
+ db.host.should == nil
40
+ db.port.should == nil
41
+ db.only_collections.should == nil
42
+ db.additional_options.should == nil
43
+ db.ipv6.should == nil
44
+ end
45
+ end
30
46
  end
@@ -29,4 +29,21 @@ describe Backup::Configuration::Database::MySQL do
29
29
  db.only_tables.should == %w[my other tables]
30
30
  db.additional_options.should == %w[my options]
31
31
  end
32
+
33
+ describe '#clear_defaults!' do
34
+ it 'should clear all the defaults, resetting them to nil' do
35
+ Backup::Configuration::Database::MySQL.clear_defaults!
36
+
37
+ db = Backup::Configuration::Database::MySQL
38
+ db.name.should == nil
39
+ db.username.should == nil
40
+ db.password.should == nil
41
+ db.host.should == nil
42
+ db.port.should == nil
43
+ db.socket.should == nil
44
+ db.skip_tables.should == nil
45
+ db.only_tables.should == nil
46
+ db.additional_options.should == nil
47
+ end
48
+ end
32
49
  end
@@ -29,4 +29,21 @@ describe Backup::Configuration::Database::PostgreSQL do
29
29
  db.only_tables.should == %w[my other tables]
30
30
  db.additional_options.should == %w[my options]
31
31
  end
32
+
33
+ describe '#clear_defaults!' do
34
+ it 'should clear all the defaults, resetting them to nil' do
35
+ Backup::Configuration::Database::PostgreSQL.clear_defaults!
36
+
37
+ db = Backup::Configuration::Database::PostgreSQL
38
+ db.name.should == nil
39
+ db.username.should == nil
40
+ db.password.should == nil
41
+ db.host.should == nil
42
+ db.port.should == nil
43
+ db.socket.should == nil
44
+ db.skip_tables.should == nil
45
+ db.only_tables.should == nil
46
+ db.additional_options.should == nil
47
+ end
48
+ end
32
49
  end
@@ -27,4 +27,20 @@ describe Backup::Configuration::Database::Redis do
27
27
  db.socket.should == '/redis.sock'
28
28
  db.additional_options.should == %w[my options]
29
29
  end
30
+
31
+ describe '#clear_defaults!' do
32
+ it 'should clear all the defaults, resetting them to nil' do
33
+ Backup::Configuration::Database::Redis.clear_defaults!
34
+
35
+ db = Backup::Configuration::Database::Redis
36
+ db.name.should == nil
37
+ db.path.should == nil
38
+ db.password.should == nil
39
+ db.invoke_save.should == nil
40
+ db.host.should == nil
41
+ db.port.should == nil
42
+ db.socket.should == nil
43
+ db.additional_options.should == nil
44
+ end
45
+ end
30
46
  end
@@ -17,4 +17,15 @@ describe Backup::Configuration::Notifier::Campfire do
17
17
  campfire.subdomain.should == 'my_subdomain'
18
18
  campfire.room_id.should == 'my_room_id'
19
19
  end
20
+
21
+ describe '#clear_defaults!' do
22
+ it 'should clear all the defaults, resetting them to nil' do
23
+ Backup::Configuration::Notifier::Campfire.clear_defaults!
24
+
25
+ campfire = Backup::Configuration::Notifier::Campfire
26
+ campfire.api_token.should == nil
27
+ campfire.subdomain.should == nil
28
+ campfire.room_id.should == nil
29
+ end
30
+ end
20
31
  end
@@ -14,6 +14,7 @@ describe Backup::Configuration::Notifier::Mail do
14
14
  mail.password = 'secret'
15
15
  mail.authentication = 'plain'
16
16
  mail.enable_starttls_auto = true
17
+ mail.openssl_verify_mode = true
17
18
  end
18
19
  end
19
20
 
@@ -28,5 +29,24 @@ describe Backup::Configuration::Notifier::Mail do
28
29
  mail.password.should == 'secret'
29
30
  mail.authentication.should == 'plain'
30
31
  mail.enable_starttls_auto.should == true
32
+ mail.openssl_verify_mode.should == true
33
+ end
34
+
35
+ describe '#clear_defaults!' do
36
+ it 'should clear all the defaults, resetting them to nil' do
37
+ Backup::Configuration::Notifier::Mail.clear_defaults!
38
+
39
+ mail = Backup::Configuration::Notifier::Mail
40
+ mail.from.should == nil
41
+ mail.to.should == nil
42
+ mail.address.should == nil
43
+ mail.port.should == nil
44
+ mail.domain.should == nil
45
+ mail.user_name.should == nil
46
+ mail.password.should == nil
47
+ mail.authentication.should == nil
48
+ mail.enable_starttls_auto.should == nil
49
+ mail.openssl_verify_mode.should == nil
50
+ end
31
51
  end
32
52
  end
@@ -0,0 +1,34 @@
1
+ # encoding: utf-8
2
+
3
+ require File.dirname(__FILE__) + '/../../spec_helper'
4
+
5
+ describe Backup::Configuration::Notifier::Presently do
6
+ before do
7
+ Backup::Configuration::Notifier::Presently.defaults do |presently|
8
+ presently.subdomain = 'my_subdomain'
9
+ presently.user_name = 'my_user_name'
10
+ presently.password = 'my_password'
11
+ presently.group_id = 'my_group_id'
12
+ end
13
+ end
14
+
15
+ it 'should set the default tweet configuration' do
16
+ presently = Backup::Configuration::Notifier::Presently
17
+ presently.subdomain.should == 'my_subdomain'
18
+ presently.user_name.should == 'my_user_name'
19
+ presently.password.should == 'my_password'
20
+ presently.group_id.should == 'my_group_id'
21
+ end
22
+
23
+ describe '#clear_defaults!' do
24
+ it 'should clear all the defaults, resetting them to nil' do
25
+ Backup::Configuration::Notifier::Presently.clear_defaults!
26
+
27
+ presently = Backup::Configuration::Notifier::Presently
28
+ presently.subdomain.should == nil
29
+ presently.user_name.should == nil
30
+ presently.password.should == nil
31
+ presently.group_id.should == nil
32
+ end
33
+ end
34
+ end
@@ -19,4 +19,16 @@ describe Backup::Configuration::Notifier::Twitter do
19
19
  tweet.oauth_token.should == 'my_oauth_token'
20
20
  tweet.oauth_token_secret.should == 'my_oauth_token_secret'
21
21
  end
22
+
23
+ describe '#clear_defaults!' do
24
+ it 'should clear all the defaults, resetting them to nil' do
25
+ Backup::Configuration::Notifier::Twitter.clear_defaults!
26
+
27
+ tweet = Backup::Configuration::Notifier::Twitter
28
+ tweet.consumer_key.should == nil
29
+ tweet.consumer_secret.should == nil
30
+ tweet.oauth_token.should == nil
31
+ tweet.oauth_token_secret.should == nil
32
+ end
33
+ end
22
34
  end
@@ -5,8 +5,6 @@ require File.dirname(__FILE__) + '/../../spec_helper'
5
5
  describe Backup::Configuration::Storage::Dropbox do
6
6
  before do
7
7
  Backup::Configuration::Storage::Dropbox.defaults do |db|
8
- db.email = 'my@email.com'
9
- db.password = 'my_password'
10
8
  db.api_key = 'my_api_key'
11
9
  db.api_secret = 'my_secret'
12
10
  db.path = 'my_backups'
@@ -17,8 +15,6 @@ describe Backup::Configuration::Storage::Dropbox do
17
15
 
18
16
  it 'should set the default Dropbox configuration' do
19
17
  db = Backup::Configuration::Storage::Dropbox
20
- db.email.should == 'my@email.com'
21
- db.password.should == 'my_password'
22
18
  db.api_key.should == 'my_api_key'
23
19
  db.api_secret.should == 'my_secret'
24
20
  db.path.should == 'my_backups'
@@ -31,8 +27,6 @@ describe Backup::Configuration::Storage::Dropbox do
31
27
  Backup::Configuration::Storage::Dropbox.clear_defaults!
32
28
 
33
29
  db = Backup::Configuration::Storage::Dropbox
34
- db.email.should == nil
35
- db.password.should == nil
36
30
  db.api_key.should == nil
37
31
  db.api_secret.should == nil
38
32
  db.path.should == nil
@@ -5,12 +5,13 @@ require File.dirname(__FILE__) + '/../../spec_helper'
5
5
  describe Backup::Configuration::Storage::FTP do
6
6
  before do
7
7
  Backup::Configuration::Storage::FTP.defaults do |ftp|
8
- ftp.username = 'my_username'
9
- ftp.password = 'my_password'
10
- ftp.ip = '123.45.678.90'
11
- ftp.port = 21
12
- ftp.path = 'my_backups'
13
- ftp.keep = 20
8
+ ftp.username = 'my_username'
9
+ ftp.password = 'my_password'
10
+ ftp.ip = '123.45.678.90'
11
+ ftp.port = 21
12
+ ftp.path = 'my_backups'
13
+ ftp.keep = 20
14
+ ftp.passive_mode = false
14
15
  end
15
16
  end
16
17
 
@@ -22,6 +23,7 @@ describe Backup::Configuration::Storage::FTP do
22
23
  ftp.port.should == 21
23
24
  ftp.path.should == 'my_backups'
24
25
  ftp.keep.should == 20
26
+ ftp.passive_mode == false
25
27
  end
26
28
 
27
29
  describe '#clear_defaults!' do
@@ -29,12 +31,13 @@ describe Backup::Configuration::Storage::FTP do
29
31
  Backup::Configuration::Storage::FTP.clear_defaults!
30
32
 
31
33
  ftp = Backup::Configuration::Storage::FTP
32
- ftp.username.should == nil
33
- ftp.password.should == nil
34
- ftp.ip.should == nil
35
- ftp.port.should == nil
36
- ftp.path.should == nil
37
- ftp.keep.should == nil
34
+ ftp.username.should == nil
35
+ ftp.password.should == nil
36
+ ftp.ip.should == nil
37
+ ftp.port.should == nil
38
+ ftp.path.should == nil
39
+ ftp.keep.should == nil
40
+ ftp.passive_mode.should == nil
38
41
  end
39
42
  end
40
43
  end
@@ -0,0 +1,28 @@
1
+ # encoding: utf-8
2
+
3
+ require File.dirname(__FILE__) + '/../../spec_helper'
4
+
5
+ describe Backup::Configuration::Storage::Local do
6
+ before do
7
+ Backup::Configuration::Storage::Local.defaults do |local|
8
+ local.path = 'my_backups'
9
+ local.keep = 20
10
+ end
11
+ end
12
+
13
+ it 'should set the default local configuration' do
14
+ local = Backup::Configuration::Storage::Local
15
+ local.path.should == 'my_backups'
16
+ local.keep.should == 20
17
+ end
18
+
19
+ describe '#clear_defaults!' do
20
+ it 'should clear all the defaults, resetting them to nil' do
21
+ Backup::Configuration::Storage::Local.clear_defaults!
22
+
23
+ local = Backup::Configuration::Storage::Local
24
+ local.path.should == nil
25
+ local.keep.should == nil
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,31 @@
1
+ # encoding: utf-8
2
+
3
+ require File.dirname(__FILE__) + '/../../spec_helper'
4
+
5
+ describe Backup::Configuration::Storage::Ninefold do
6
+ before do
7
+ Backup::Configuration::Storage::Ninefold.defaults do |nf|
8
+ nf.storage_token = 'my_storage_token'
9
+ nf.storage_secret = 'my_storage_secret'
10
+ nf.path = 'my_backups'
11
+ end
12
+ end
13
+
14
+ it 'should set the default Ninefold configuration' do
15
+ ninefold = Backup::Configuration::Storage::Ninefold
16
+ ninefold.storage_token.should == 'my_storage_token'
17
+ ninefold.storage_secret.should == 'my_storage_secret'
18
+ ninefold.path.should == 'my_backups'
19
+ end
20
+
21
+ describe '#clear_defaults!' do
22
+ it 'should clear all the defaults, resetting them to nil' do
23
+ Backup::Configuration::Storage::Ninefold.clear_defaults!
24
+
25
+ ninefold = Backup::Configuration::Storage::Ninefold
26
+ ninefold.storage_token.should == nil
27
+ ninefold.storage_secret.should == nil
28
+ ninefold.path.should == nil
29
+ end
30
+ end
31
+ end
@@ -20,6 +20,7 @@ describe Backup::Configuration::Storage::RSync do
20
20
  rsync.ip.should == '123.45.678.90'
21
21
  rsync.port.should == 21
22
22
  rsync.path.should == 'my_backups'
23
+ rsync.local.should == nil
23
24
  end
24
25
 
25
26
  describe '#clear_defaults!' do
@@ -32,6 +33,7 @@ describe Backup::Configuration::Storage::RSync do
32
33
  rsync.ip.should == nil
33
34
  rsync.port.should == nil
34
35
  rsync.path.should == nil
36
+ rsync.local.should == nil
35
37
  end
36
38
  end
37
39
  end
@@ -109,7 +109,6 @@ describe Backup::Database::MongoDB do
109
109
 
110
110
  describe '#perform!' do
111
111
  before do
112
- Backup::Logger.stubs(:message)
113
112
  db.stubs(:utility).returns('mongodump')
114
113
  db.stubs(:mkdir)
115
114
  db.stubs(:run)
@@ -131,7 +131,6 @@ describe Backup::Database::MySQL do
131
131
 
132
132
  describe '#perform!' do
133
133
  before do
134
- Backup::Logger.stubs(:message)
135
134
  db.stubs(:utility).returns('mysqldump')
136
135
  db.stubs(:mkdir)
137
136
  db.stubs(:run)
@@ -49,18 +49,20 @@ describe Backup::Database::PostgreSQL do
49
49
  db.additional_options.should == []
50
50
  end
51
51
 
52
- it do
52
+ it 'handles an empty username' do
53
53
  db = Backup::Database::PostgreSQL.new {}
54
54
  db.username = ''
55
55
 
56
- db.credential_options.should == ''
56
+ db.username_options.should == ''
57
+ db.password_options.should == ''
57
58
  end
58
59
 
59
- it do
60
+ it 'handles a nil username' do
60
61
  db = Backup::Database::PostgreSQL.new {}
61
62
  db.username = nil
62
63
 
63
- db.credential_options.should == ''
64
+ db.username_options.should == ''
65
+ db.password_options.should == ''
64
66
  end
65
67
 
66
68
  it 'should ensure the directory is available' do
@@ -91,9 +93,9 @@ describe Backup::Database::PostgreSQL do
91
93
  end
92
94
  end
93
95
 
94
- describe '#credential_options' do
95
- it 'should return the postgresql syntax for the credential options' do
96
- db.credential_options.should == "--username='someuser'"
96
+ describe '#username_options' do
97
+ it 'should return the postgresql syntax for the username options' do
98
+ db.username_options.should == "--username='someuser'"
97
99
  end
98
100
 
99
101
  it 'should only return the postgresql syntax for the user' do
@@ -101,7 +103,13 @@ describe Backup::Database::PostgreSQL do
101
103
  db.username = 'someuser'
102
104
  end
103
105
 
104
- db.credential_options.should == "--username='someuser'"
106
+ db.username_options.should == "--username='someuser'"
107
+ end
108
+ end
109
+
110
+ describe '#password_options' do
111
+ it 'returns the environment variable set for the password' do
112
+ db.password_options.should == "PGPASSWORD='secret'"
105
113
  end
106
114
  end
107
115
 
@@ -133,19 +141,31 @@ describe Backup::Database::PostgreSQL do
133
141
  end
134
142
 
135
143
  describe '#pg_dump_string' do
136
- it 'should return the full pg_dump string' do
144
+ before do
137
145
  db.expects(:utility).with(:pg_dump).returns('pg_dump')
146
+ end
147
+
148
+ it 'should return the full pg_dump string' do
138
149
  db.pgdump.should ==
139
- "pg_dump --username='someuser' " +
150
+ "PGPASSWORD='secret' pg_dump --username='someuser' " +
140
151
  "--host='localhost' --port='123' --host='/pg.sock' " +
141
152
  "--single-transaction --quick --table='users' --table='pirates' " +
142
153
  "--exclude-table='logs' --exclude-table='profiles' mydatabase"
143
154
  end
155
+
156
+ it 'returns the full pg_dump string when a password is not specified' do
157
+ db.password = nil
158
+ db.pgdump.should ==
159
+ "pg_dump --username='someuser' " +
160
+ "--host='localhost' --port='123' --host='/pg.sock' " +
161
+ "--single-transaction --quick --table='users' --table='pirates' " +
162
+ "--exclude-table='logs' --exclude-table='profiles' mydatabase"
163
+
164
+ end
144
165
  end
145
166
 
146
167
  describe '#perform!' do
147
168
  before do
148
- Backup::Logger.stubs(:message)
149
169
  db.stubs(:utility).returns('pg_dump')
150
170
  db.stubs(:mkdir)
151
171
  db.stubs(:run)