interu-backup 3.0.16
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.
- data/.gitignore +2 -0
- data/Gemfile +31 -0
- data/Gemfile.lock +117 -0
- data/Guardfile +17 -0
- data/LICENSE.md +24 -0
- data/README.md +332 -0
- data/backup.gemspec +31 -0
- data/bin/backup +267 -0
- data/lib/backup.rb +181 -0
- data/lib/backup/archive.rb +73 -0
- data/lib/backup/cli.rb +82 -0
- data/lib/backup/compressor/base.rb +17 -0
- data/lib/backup/compressor/bzip2.rb +64 -0
- data/lib/backup/compressor/gzip.rb +61 -0
- data/lib/backup/configuration/base.rb +15 -0
- data/lib/backup/configuration/compressor/base.rb +10 -0
- data/lib/backup/configuration/compressor/bzip2.rb +23 -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 +41 -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 +54 -0
- data/lib/backup/configuration/notifier/base.rb +39 -0
- data/lib/backup/configuration/notifier/campfire.rb +25 -0
- data/lib/backup/configuration/notifier/mail.rb +52 -0
- data/lib/backup/configuration/notifier/presently.rb +25 -0
- data/lib/backup/configuration/notifier/twitter.rb +21 -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 +29 -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/configuration/syncer/rsync.rb +45 -0
- data/lib/backup/configuration/syncer/s3.rb +33 -0
- data/lib/backup/database/base.rb +33 -0
- data/lib/backup/database/mongodb.rb +179 -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/dependency.rb +96 -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/exception/command_not_found.rb +8 -0
- data/lib/backup/finder.rb +39 -0
- data/lib/backup/logger.rb +102 -0
- data/lib/backup/model.rb +272 -0
- data/lib/backup/notifier/base.rb +29 -0
- data/lib/backup/notifier/binder.rb +32 -0
- data/lib/backup/notifier/campfire.rb +194 -0
- data/lib/backup/notifier/mail.rb +141 -0
- data/lib/backup/notifier/presently.rb +105 -0
- data/lib/backup/notifier/templates/notify_failure.erb +33 -0
- data/lib/backup/notifier/templates/notify_success.erb +16 -0
- data/lib/backup/notifier/twitter.rb +87 -0
- data/lib/backup/storage/base.rb +67 -0
- data/lib/backup/storage/cloudfiles.rb +95 -0
- data/lib/backup/storage/dropbox.rb +91 -0
- data/lib/backup/storage/ftp.rb +114 -0
- data/lib/backup/storage/object.rb +45 -0
- data/lib/backup/storage/rsync.rb +129 -0
- data/lib/backup/storage/s3.rb +180 -0
- data/lib/backup/storage/scp.rb +106 -0
- data/lib/backup/storage/sftp.rb +106 -0
- data/lib/backup/syncer/base.rb +10 -0
- data/lib/backup/syncer/rsync.rb +152 -0
- data/lib/backup/syncer/s3.rb +118 -0
- data/lib/backup/version.rb +43 -0
- data/lib/templates/archive +7 -0
- data/lib/templates/compressor/bzip2 +7 -0
- data/lib/templates/compressor/gzip +7 -0
- data/lib/templates/database/mongodb +14 -0
- data/lib/templates/database/mysql +14 -0
- data/lib/templates/database/postgresql +14 -0
- data/lib/templates/database/redis +13 -0
- data/lib/templates/encryptor/gpg +12 -0
- data/lib/templates/encryptor/openssl +8 -0
- data/lib/templates/notifier/campfire +11 -0
- data/lib/templates/notifier/mail +17 -0
- data/lib/templates/notifier/presently +12 -0
- data/lib/templates/notifier/twitter +12 -0
- data/lib/templates/readme +15 -0
- data/lib/templates/storage/cloudfiles +10 -0
- data/lib/templates/storage/dropbox +12 -0
- data/lib/templates/storage/ftp +11 -0
- data/lib/templates/storage/rsync +10 -0
- data/lib/templates/storage/s3 +21 -0
- data/lib/templates/storage/scp +11 -0
- data/lib/templates/storage/sftp +11 -0
- data/lib/templates/syncer/rsync +17 -0
- data/lib/templates/syncer/s3 +15 -0
- data/spec/archive_spec.rb +90 -0
- data/spec/backup_spec.rb +11 -0
- data/spec/compressor/bzip2_spec.rb +59 -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/campfire_spec.rb +20 -0
- data/spec/configuration/notifier/mail_spec.rb +32 -0
- data/spec/configuration/notifier/twitter_spec.rb +22 -0
- data/spec/configuration/storage/cloudfiles_spec.rb +34 -0
- data/spec/configuration/storage/dropbox_spec.rb +43 -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/configuration/syncer/rsync_spec.rb +46 -0
- data/spec/configuration/syncer/s3_spec.rb +43 -0
- data/spec/database/base_spec.rb +30 -0
- data/spec/database/mongodb_spec.rb +181 -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 +58 -0
- data/spec/model_spec.rb +236 -0
- data/spec/notifier/campfire_spec.rb +96 -0
- data/spec/notifier/mail_spec.rb +97 -0
- data/spec/notifier/presently_spec.rb +99 -0
- data/spec/notifier/twitter_spec.rb +86 -0
- data/spec/spec_helper.rb +25 -0
- data/spec/storage/base_spec.rb +33 -0
- data/spec/storage/cloudfiles_spec.rb +102 -0
- data/spec/storage/dropbox_spec.rb +105 -0
- data/spec/storage/ftp_spec.rb +133 -0
- data/spec/storage/object_spec.rb +74 -0
- data/spec/storage/rsync_spec.rb +131 -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/syncer/rsync_spec.rb +195 -0
- data/spec/syncer/s3_spec.rb +139 -0
- data/spec/version_spec.rb +21 -0
- metadata +231 -0
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
|
4
|
+
|
|
5
|
+
describe Backup::Database::MySQL do
|
|
6
|
+
|
|
7
|
+
before do
|
|
8
|
+
Backup::Database::MySQL.any_instance.stubs(:load_defaults!)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
let(:db) do
|
|
12
|
+
Backup::Database::MySQL.new do |db|
|
|
13
|
+
db.name = 'mydatabase'
|
|
14
|
+
db.username = 'someuser'
|
|
15
|
+
db.password = 'secret'
|
|
16
|
+
db.host = 'localhost'
|
|
17
|
+
db.port = '123'
|
|
18
|
+
db.socket = '/mysql.sock'
|
|
19
|
+
|
|
20
|
+
db.skip_tables = ['logs', 'profiles']
|
|
21
|
+
db.only_tables = ['users', 'pirates']
|
|
22
|
+
db.additional_options = ['--single-transaction', '--quick']
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
describe '#new' do
|
|
27
|
+
it 'should read the adapter details correctly' do
|
|
28
|
+
db.name.should == 'mydatabase'
|
|
29
|
+
db.username.should == 'someuser'
|
|
30
|
+
db.password.should == 'secret'
|
|
31
|
+
db.host.should == 'localhost'
|
|
32
|
+
db.port.should == '123'
|
|
33
|
+
db.socket.should == '/mysql.sock'
|
|
34
|
+
|
|
35
|
+
db.skip_tables.should == ['logs', 'profiles']
|
|
36
|
+
db.only_tables.should == ['users', 'pirates']
|
|
37
|
+
db.additional_options.should == ['--single-transaction', '--quick']
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
it 'arrays should default to empty arrays when not specified' do
|
|
41
|
+
db = Backup::Database::MySQL.new do |db|
|
|
42
|
+
db.name = 'mydatabase'
|
|
43
|
+
db.username = 'someuser'
|
|
44
|
+
db.password = 'secret'
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
db.skip_tables.should == []
|
|
48
|
+
db.only_tables.should == []
|
|
49
|
+
db.additional_options.should == []
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
it 'should ensure the directory is available' do
|
|
53
|
+
Backup::Database::MySQL.any_instance.expects(:mkdir).with("#{Backup::TMP_PATH}/myapp/MySQL")
|
|
54
|
+
Backup::Database::MySQL.new {}
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
describe '#skip_tables' do
|
|
59
|
+
it 'should return a string for the mysqldump --ignore-tables option' do
|
|
60
|
+
db.tables_to_skip.should == "--ignore-table='mydatabase.logs'\s--ignore-table='mydatabase.profiles'"
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
it 'should return an empty string' do
|
|
64
|
+
db = Backup::Database::MySQL.new {}
|
|
65
|
+
db.tables_to_skip.should == ""
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
describe '#only_tables' do
|
|
70
|
+
it 'should return a string for the mysqldump selected table to dump option' do
|
|
71
|
+
db.tables_to_dump.should == "users\spirates"
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
it 'should return an empty string' do
|
|
75
|
+
db = Backup::Database::MySQL.new {}
|
|
76
|
+
db.tables_to_dump.should == ""
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
describe '#credential_options' do
|
|
81
|
+
it 'should return the mysql syntax for the credential options' do
|
|
82
|
+
db.credential_options.should == "--user='someuser' --password='secret'"
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
it 'should only return the mysql syntax for the user' do
|
|
86
|
+
db = Backup::Database::MySQL.new do |db|
|
|
87
|
+
db.username = 'someuser'
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
db.credential_options.should == "--user='someuser'"
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
describe '#connectivity_options' do
|
|
95
|
+
it 'should return the mysql syntax for the connectivity options' do
|
|
96
|
+
db.connectivity_options.should == "--host='localhost' --port='123' --socket='/mysql.sock'"
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
it 'should return only the socket' do
|
|
100
|
+
db = Backup::Database::MySQL.new do |db|
|
|
101
|
+
db.host = ''
|
|
102
|
+
db.port = nil
|
|
103
|
+
db.socket = '/mysql.sock'
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
db.connectivity_options.should == "--socket='/mysql.sock'"
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
describe '#additional_options' do
|
|
111
|
+
it 'should return a string of additional options specified by the user' do
|
|
112
|
+
db.options.should == '--single-transaction --quick'
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
it 'should return an empty string' do
|
|
116
|
+
db = Backup::Database::MySQL.new {}
|
|
117
|
+
db.options.should == ""
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
describe '#mysqldump_string' do
|
|
122
|
+
it 'should return the full mysqldump string' do
|
|
123
|
+
db.expects(:utility).with(:mysqldump).returns('mysqldump')
|
|
124
|
+
db.mysqldump.should ==
|
|
125
|
+
"mysqldump --user='someuser' --password='secret' " +
|
|
126
|
+
"--host='localhost' --port='123' --socket='/mysql.sock' " +
|
|
127
|
+
"--single-transaction --quick mydatabase users pirates " +
|
|
128
|
+
"--ignore-table='mydatabase.logs' --ignore-table='mydatabase.profiles'"
|
|
129
|
+
end
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
describe '#perform!' do
|
|
133
|
+
before do
|
|
134
|
+
Backup::Logger.stubs(:message)
|
|
135
|
+
db.stubs(:utility).returns('mysqldump')
|
|
136
|
+
db.stubs(:mkdir)
|
|
137
|
+
db.stubs(:run)
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
it 'should run the mysqldump command and dump it to the specified path' do
|
|
141
|
+
db.expects(:run).with("#{db.mysqldump} > '#{Backup::TMP_PATH}/myapp/MySQL/mydatabase.sql'")
|
|
142
|
+
db.perform!
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
it do
|
|
146
|
+
Backup::Logger.expects(:message).with("Backup::Database::MySQL started dumping and archiving \"mydatabase\".")
|
|
147
|
+
db.perform!
|
|
148
|
+
end
|
|
149
|
+
end
|
|
150
|
+
end
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
|
4
|
+
|
|
5
|
+
describe Backup::Database::PostgreSQL do
|
|
6
|
+
|
|
7
|
+
before do
|
|
8
|
+
Backup::Database::PostgreSQL.any_instance.stubs(:load_defaults!)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
let(:db) do
|
|
12
|
+
Backup::Database::PostgreSQL.new do |db|
|
|
13
|
+
db.name = 'mydatabase'
|
|
14
|
+
db.username = 'someuser'
|
|
15
|
+
db.password = 'secret'
|
|
16
|
+
db.host = 'localhost'
|
|
17
|
+
db.port = '123'
|
|
18
|
+
db.socket = '/pg.sock'
|
|
19
|
+
|
|
20
|
+
db.skip_tables = ['logs', 'profiles']
|
|
21
|
+
db.only_tables = ['users', 'pirates']
|
|
22
|
+
db.additional_options = ['--single-transaction', '--quick']
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
describe '#new' do
|
|
27
|
+
it 'should read the adapter details correctly' do
|
|
28
|
+
db.name.should == 'mydatabase'
|
|
29
|
+
db.username.should == 'someuser'
|
|
30
|
+
db.password.should == 'secret'
|
|
31
|
+
db.host.should == 'localhost'
|
|
32
|
+
db.port.should == '123'
|
|
33
|
+
db.socket.should == '/pg.sock'
|
|
34
|
+
|
|
35
|
+
db.skip_tables.should == ['logs', 'profiles']
|
|
36
|
+
db.only_tables.should == ['users', 'pirates']
|
|
37
|
+
db.additional_options.should == ['--single-transaction', '--quick']
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
it 'arrays should default to empty arrays when not specified' do
|
|
41
|
+
db = Backup::Database::PostgreSQL.new do |db|
|
|
42
|
+
db.name = 'mydatabase'
|
|
43
|
+
db.username = 'someuser'
|
|
44
|
+
db.password = 'secret'
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
db.skip_tables.should == []
|
|
48
|
+
db.only_tables.should == []
|
|
49
|
+
db.additional_options.should == []
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
it do
|
|
53
|
+
db = Backup::Database::PostgreSQL.new {}
|
|
54
|
+
db.username = ''
|
|
55
|
+
|
|
56
|
+
db.credential_options.should == ''
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
it do
|
|
60
|
+
db = Backup::Database::PostgreSQL.new {}
|
|
61
|
+
db.username = nil
|
|
62
|
+
|
|
63
|
+
db.credential_options.should == ''
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
it 'should ensure the directory is available' do
|
|
67
|
+
Backup::Database::PostgreSQL.any_instance.expects(:mkdir).with("#{Backup::TMP_PATH}/myapp/PostgreSQL")
|
|
68
|
+
Backup::Database::PostgreSQL.new {}
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
describe '#skip_tables' do
|
|
73
|
+
it 'should return a string for the pg_dump --ignore-tables option' do
|
|
74
|
+
db.tables_to_skip.should == "--exclude-table='logs' --exclude-table='profiles'"
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
it 'should return an empty string' do
|
|
78
|
+
db = Backup::Database::PostgreSQL.new {}
|
|
79
|
+
db.tables_to_skip.should == ""
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
describe '#only_tables' do
|
|
84
|
+
it 'should return a string for the pg_dump selected table to dump option' do
|
|
85
|
+
db.tables_to_dump.should == "--table='users' --table='pirates'"
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
it 'should return an empty string' do
|
|
89
|
+
db = Backup::Database::PostgreSQL.new {}
|
|
90
|
+
db.tables_to_dump.should == ""
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
describe '#credential_options' do
|
|
95
|
+
it 'should return the postgresql syntax for the credential options' do
|
|
96
|
+
db.credential_options.should == "--username='someuser'"
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
it 'should only return the postgresql syntax for the user' do
|
|
100
|
+
db = Backup::Database::PostgreSQL.new do |db|
|
|
101
|
+
db.username = 'someuser'
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
db.credential_options.should == "--username='someuser'"
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
describe '#connectivity_options' do
|
|
109
|
+
it 'should return the postgresql syntax for the connectivity options' do
|
|
110
|
+
db.connectivity_options.should == "--host='localhost' --port='123' --host='/pg.sock'"
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
it 'should return only the socket' do
|
|
114
|
+
db = Backup::Database::PostgreSQL.new do |db|
|
|
115
|
+
db.host = ''
|
|
116
|
+
db.port = nil
|
|
117
|
+
db.socket = '/pg.sock'
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
db.connectivity_options.should == "--host='/pg.sock'"
|
|
121
|
+
end
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
describe '#additional_options' do
|
|
125
|
+
it 'should return a string of additional options specified by the user' do
|
|
126
|
+
db.options.should == '--single-transaction --quick'
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
it 'should return an empty string' do
|
|
130
|
+
db = Backup::Database::PostgreSQL.new {}
|
|
131
|
+
db.options.should == ""
|
|
132
|
+
end
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
describe '#pg_dump_string' do
|
|
136
|
+
it 'should return the full pg_dump string' do
|
|
137
|
+
db.expects(:utility).with(:pg_dump).returns('pg_dump')
|
|
138
|
+
db.pgdump.should ==
|
|
139
|
+
"pg_dump --username='someuser' " +
|
|
140
|
+
"--host='localhost' --port='123' --host='/pg.sock' " +
|
|
141
|
+
"--single-transaction --quick --table='users' --table='pirates' " +
|
|
142
|
+
"--exclude-table='logs' --exclude-table='profiles' mydatabase"
|
|
143
|
+
end
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
describe '#perform!' do
|
|
147
|
+
before do
|
|
148
|
+
Backup::Logger.stubs(:message)
|
|
149
|
+
db.stubs(:utility).returns('pg_dump')
|
|
150
|
+
db.stubs(:mkdir)
|
|
151
|
+
db.stubs(:run)
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
it 'should run the pg_dump command and dump it to the specified path' do
|
|
155
|
+
db.expects(:run).with("#{db.pgdump} > '#{Backup::TMP_PATH}/myapp/PostgreSQL/mydatabase.sql'")
|
|
156
|
+
db.perform!
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
it do
|
|
160
|
+
Backup::Logger.expects(:message).with("Backup::Database::PostgreSQL started dumping and archiving \"mydatabase\".")
|
|
161
|
+
db.perform!
|
|
162
|
+
end
|
|
163
|
+
end
|
|
164
|
+
end
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
|
4
|
+
|
|
5
|
+
describe Backup::Database::Redis do
|
|
6
|
+
|
|
7
|
+
before do
|
|
8
|
+
Backup::Database::Redis.any_instance.stubs(:load_defaults!)
|
|
9
|
+
Backup::Logger.stubs(:error)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
let(:db) do
|
|
13
|
+
Backup::Database::Redis.new do |db|
|
|
14
|
+
db.name = 'mydatabase'
|
|
15
|
+
db.path = '/var/lib/redis/db/'
|
|
16
|
+
db.password = 'secret'
|
|
17
|
+
db.host = 'localhost'
|
|
18
|
+
db.port = 123
|
|
19
|
+
db.socket = '/redis.sock'
|
|
20
|
+
db.invoke_save = true
|
|
21
|
+
|
|
22
|
+
db.additional_options = ['--query']
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
describe '#new' do
|
|
27
|
+
it 'should read the adapter details correctly' do
|
|
28
|
+
db.name.should == 'mydatabase'
|
|
29
|
+
db.password.should == 'secret'
|
|
30
|
+
db.host.should == 'localhost'
|
|
31
|
+
db.port.should == 123
|
|
32
|
+
db.socket.should == '/redis.sock'
|
|
33
|
+
db.invoke_save.should == true
|
|
34
|
+
|
|
35
|
+
db.additional_options.should == '--query'
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
it 'arrays should default to empty arrays when not specified' do
|
|
39
|
+
db = Backup::Database::Redis.new do |db|
|
|
40
|
+
db.name = 'mydatabase'
|
|
41
|
+
db.password = 'secret'
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
db.additional_options.should == ""
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
it 'should ensure the directory is available' do
|
|
48
|
+
Backup::Database::Redis.any_instance.expects(:mkdir).with("#{Backup::TMP_PATH}/myapp/Redis")
|
|
49
|
+
Backup::Database::Redis.new {}
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
describe '#credential_options' do
|
|
54
|
+
it 'should return the mongo syntax for the credential options' do
|
|
55
|
+
db.credential_options.should == "-a 'secret'"
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
describe '#connectivity_options' do
|
|
60
|
+
it 'should return the redis syntax for the connectivity options' do
|
|
61
|
+
db.connectivity_options.should == "-h 'localhost' -p '123' -s '/redis.sock'"
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
it 'should return only the port' do
|
|
65
|
+
db = Backup::Database::Redis.new do |db|
|
|
66
|
+
db.host = nil
|
|
67
|
+
db.port = 123
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
db.connectivity_options.should == "-p '123'"
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
describe '#invoke_save!' do
|
|
75
|
+
it 'should return the full mongodump string' do
|
|
76
|
+
db.expects(:utility).with('redis-cli').returns('redis-cli')
|
|
77
|
+
db.expects(:run).with("redis-cli -a 'secret' -h 'localhost' -p '123' -s '/redis.sock' --query SAVE")
|
|
78
|
+
db.invoke_save!
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
describe '#copy!' do
|
|
83
|
+
it do
|
|
84
|
+
File.expects(:exist?).returns(true)
|
|
85
|
+
db.stubs(:utility).returns('cp')
|
|
86
|
+
db.expects(:run).with("cp '#{ File.join('/var/lib/redis/db/mydatabase.rdb') }' '#{ File.join(Backup::TMP_PATH, Backup::TRIGGER, 'Redis', 'mydatabase.rdb') }'")
|
|
87
|
+
db.copy!
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
describe '#perform!' do
|
|
92
|
+
before do
|
|
93
|
+
Backup::Logger.stubs(:message)
|
|
94
|
+
File.stubs(:exist?).returns(true)
|
|
95
|
+
db.stubs(:utility).returns('redis-cli')
|
|
96
|
+
db.stubs(:mkdir)
|
|
97
|
+
db.stubs(:run)
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
it 'should copy over without persisting (saving) first' do
|
|
101
|
+
db.invoke_save = nil
|
|
102
|
+
db.expects(:invoke_save!).never
|
|
103
|
+
db.expects(:copy!)
|
|
104
|
+
|
|
105
|
+
db.perform!
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
it 'should copy over after persisting (saving) the most recent updates' do
|
|
109
|
+
db.invoke_save = true
|
|
110
|
+
db.expects(:invoke_save!)
|
|
111
|
+
db.expects(:copy!)
|
|
112
|
+
|
|
113
|
+
db.perform!
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
it do
|
|
117
|
+
Backup::Logger.expects(:message).with("Backup::Database::Redis started dumping and archiving \"mydatabase\".")
|
|
118
|
+
|
|
119
|
+
db.perform!
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
end
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
|
4
|
+
|
|
5
|
+
describe Backup::Encryptor::GPG do
|
|
6
|
+
|
|
7
|
+
let(:encryptor) do
|
|
8
|
+
Backup::Encryptor::GPG.new do |e|
|
|
9
|
+
e.key = <<-KEY
|
|
10
|
+
-----BEGIN PGP PUBLIC KEY BLOCK-----
|
|
11
|
+
Version: GnuPG v1.4.11 (Darwin)
|
|
12
|
+
|
|
13
|
+
mQENBE12G/8BCAC4mnlSMYMBwBYTHe5zURcnYYNCORPWOr0iXGiLWuKxYtrDQyLm
|
|
14
|
+
X2Nws44Iz7Wp7AuJRAjkitf1cRBgXyDu8wuogXO7JqPmtsUdBCABz9w5NH6IQjgR
|
|
15
|
+
WNa3g2n0nokA7Zr5FA4GXoEaYivfbvGiyNpd6P4okH+//G2p+3FIryu5xz+89D1b
|
|
16
|
+
=Yvhg
|
|
17
|
+
-----END PGP PUBLIC KEY BLOCK-----
|
|
18
|
+
KEY
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
context "when a block is provided" do
|
|
23
|
+
it "should strip initial whitespace from key lines" do
|
|
24
|
+
key = <<-KEY
|
|
25
|
+
-----BEGIN PGP PUBLIC KEY BLOCK-----
|
|
26
|
+
Version: GnuPG v1.4.11 (Darwin)
|
|
27
|
+
|
|
28
|
+
mQENBE12G/8BCAC4mnlSMYMBwBYTHe5zURcnYYNCORPWOr0iXGiLWuKxYtrDQyLm
|
|
29
|
+
X2Nws44Iz7Wp7AuJRAjkitf1cRBgXyDu8wuogXO7JqPmtsUdBCABz9w5NH6IQjgR
|
|
30
|
+
WNa3g2n0nokA7Zr5FA4GXoEaYivfbvGiyNpd6P4okH+//G2p+3FIryu5xz+89D1b
|
|
31
|
+
=Yvhg
|
|
32
|
+
-----END PGP PUBLIC KEY BLOCK-----
|
|
33
|
+
KEY
|
|
34
|
+
|
|
35
|
+
encryptor.key.should == key
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
describe '#options' do
|
|
40
|
+
it do
|
|
41
|
+
encryptor.expects(:encryption_key_id).returns('secret')
|
|
42
|
+
encryptor.send(:options).should == "-e --trust-model always -r 'secret'"
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
describe '#write_tmp_file!' do
|
|
47
|
+
it do
|
|
48
|
+
tmp_file = mock('TmpFile')
|
|
49
|
+
Tempfile.expects(:new).returns(tmp_file)
|
|
50
|
+
tmp_file.expects(:write).with('secret')
|
|
51
|
+
tmp_file.expects(:close)
|
|
52
|
+
|
|
53
|
+
encryptor.key = 'secret'
|
|
54
|
+
encryptor.send(:write_tmp_file!)
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|