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,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 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.gsub(/^(\s|\t)+/, '')
|
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
|
@@ -0,0 +1,102 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
4
|
+
|
5
|
+
describe Backup::Encryptor::OpenSSL do
|
6
|
+
|
7
|
+
context "when no block is provided" do
|
8
|
+
let(:encryptor) { Backup::Encryptor::OpenSSL.new }
|
9
|
+
|
10
|
+
it do
|
11
|
+
encryptor.password.should == nil
|
12
|
+
end
|
13
|
+
|
14
|
+
it do
|
15
|
+
encryptor.send(:base64).should == []
|
16
|
+
end
|
17
|
+
|
18
|
+
it do
|
19
|
+
encryptor.send(:salt).should == []
|
20
|
+
end
|
21
|
+
|
22
|
+
it do
|
23
|
+
encryptor.send(:options).should == "aes-256-cbc"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context "when a block is provided" do
|
28
|
+
let(:encryptor) do
|
29
|
+
Backup::Encryptor::OpenSSL.new do |e|
|
30
|
+
e.password = "my_secret_password"
|
31
|
+
e.salt = true
|
32
|
+
e.base64 = true
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
it do
|
37
|
+
encryptor.password.should == "my_secret_password"
|
38
|
+
end
|
39
|
+
|
40
|
+
it do
|
41
|
+
encryptor.send(:salt).should == ['-salt']
|
42
|
+
end
|
43
|
+
|
44
|
+
it do
|
45
|
+
encryptor.send(:base64).should == ['-base64']
|
46
|
+
end
|
47
|
+
|
48
|
+
it do
|
49
|
+
encryptor.send(:options).should == "aes-256-cbc -base64 -salt"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe '#perform!' do
|
54
|
+
let(:encryptor) { Backup::Encryptor::OpenSSL.new }
|
55
|
+
before do
|
56
|
+
Backup::Model.extension = 'tar'
|
57
|
+
Backup::Logger.stubs(:message)
|
58
|
+
[:utility, :run, :rm].each { |method| encryptor.stubs(method) }
|
59
|
+
end
|
60
|
+
|
61
|
+
it do
|
62
|
+
encryptor = Backup::Encryptor::OpenSSL.new
|
63
|
+
encryptor.expects(:utility).returns(:openssl)
|
64
|
+
encryptor.expects(:run).with("openssl aes-256-cbc -in '#{ File.join(Backup::TMP_PATH, "#{Backup::TIME}.#{Backup::TRIGGER}.tar") }' -out '#{ File.join(Backup::TMP_PATH, "#{Backup::TIME}.#{Backup::TRIGGER}.tar.enc") }' -k ''")
|
65
|
+
encryptor.perform!
|
66
|
+
end
|
67
|
+
|
68
|
+
it do
|
69
|
+
encryptor = Backup::Encryptor::OpenSSL.new do |e|
|
70
|
+
e.password = "my_secret_password"
|
71
|
+
e.salt = true
|
72
|
+
e.base64 = true
|
73
|
+
end
|
74
|
+
encryptor.stubs(:utility).returns(:openssl)
|
75
|
+
encryptor.expects(:run).with("openssl aes-256-cbc -base64 -salt -in '#{ File.join(Backup::TMP_PATH, "#{Backup::TIME}.#{Backup::TRIGGER}.tar") }' -out '#{ File.join(Backup::TMP_PATH, "#{Backup::TIME}.#{Backup::TRIGGER}.tar.enc") }' -k 'my_secret_password'")
|
76
|
+
encryptor.perform!
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'should append the .enc extension after the encryption' do
|
80
|
+
Backup::Model.extension.should == 'tar'
|
81
|
+
encryptor.perform!
|
82
|
+
Backup::Model.extension.should == 'tar.enc'
|
83
|
+
end
|
84
|
+
|
85
|
+
it do
|
86
|
+
encryptor.expects(:utility).with(:openssl)
|
87
|
+
encryptor.perform!
|
88
|
+
end
|
89
|
+
|
90
|
+
it do
|
91
|
+
Backup::Logger.expects(:message).with("Backup::Encryptor::OpenSSL started encrypting the archive.")
|
92
|
+
encryptor.perform!
|
93
|
+
end
|
94
|
+
|
95
|
+
context "after encrypting the file (which creates a new file)" do
|
96
|
+
it 'should remove the non-encrypted file' do
|
97
|
+
encryptor.expects(:rm).with(Backup::Model.file)
|
98
|
+
encryptor.perform!
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
data/spec/logger_spec.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
4
|
+
require 'timecop'
|
5
|
+
|
6
|
+
describe Backup::Logger do
|
7
|
+
before do
|
8
|
+
Timecop.freeze( Time.now )
|
9
|
+
end
|
10
|
+
|
11
|
+
context 'when logging regular messages' do
|
12
|
+
it do
|
13
|
+
Backup::Logger.expects(:puts).with("[#{ Time.now.strftime("%Y/%m/%d %H:%M:%S") }][\e[32mmessage\e[0m] This has been logged.")
|
14
|
+
File.expects(:open).with(File.join(Backup::LOG_PATH, 'backup.log'), 'a')
|
15
|
+
|
16
|
+
Backup::Logger.message "This has been logged."
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context 'when logging error messages' do
|
21
|
+
it do
|
22
|
+
Backup::Logger.expects(:puts).with("[#{ Time.now.strftime("%Y/%m/%d %H:%M:%S") }][\e[31merror\e[0m] This has been logged.")
|
23
|
+
File.expects(:open).with(File.join(Backup::LOG_PATH, 'backup.log'), 'a')
|
24
|
+
|
25
|
+
Backup::Logger.error "This has been logged."
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context 'when logging warn messages' do
|
30
|
+
it do
|
31
|
+
Backup::Logger.expects(:puts).with("[#{ Time.now.strftime("%Y/%m/%d %H:%M:%S") }][\e[33mwarning\e[0m] This has been logged.")
|
32
|
+
File.expects(:open).with(File.join(Backup::LOG_PATH, 'backup.log'), 'a')
|
33
|
+
|
34
|
+
Backup::Logger.warn "This has been logged."
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/spec/model_spec.rb
ADDED
@@ -0,0 +1,236 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
4
|
+
|
5
|
+
describe Backup::Model do
|
6
|
+
|
7
|
+
before do
|
8
|
+
class Backup::Database::TestDatabase
|
9
|
+
def initialize(&block); end
|
10
|
+
end
|
11
|
+
class Backup::Storage::TestStorage
|
12
|
+
def initialize(&block); end
|
13
|
+
end
|
14
|
+
class Backup::Archive
|
15
|
+
def initialize(name, &block); end
|
16
|
+
end
|
17
|
+
class Backup::Compressor::Gzip
|
18
|
+
def initialize(&block); end
|
19
|
+
end
|
20
|
+
class Backup::Compressor::SevenZip
|
21
|
+
def initialize(&block); end
|
22
|
+
end
|
23
|
+
class Backup::Encryptor::OpenSSL
|
24
|
+
def initialize(&block); end
|
25
|
+
end
|
26
|
+
class Backup::Encryptor::GPG
|
27
|
+
def initialize(&block); end
|
28
|
+
end
|
29
|
+
class Backup::Notifier::TestMail
|
30
|
+
def initialize(&block); end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
let(:model) { Backup::Model.new('mysql-s3', 'MySQL S3 Backup for MyApp') {} }
|
35
|
+
|
36
|
+
it do
|
37
|
+
Backup::Model.extension.should == 'tar'
|
38
|
+
end
|
39
|
+
|
40
|
+
it do
|
41
|
+
Backup::Model.new('foo', 'bar') {}
|
42
|
+
Backup::Model.extension.should == 'tar'
|
43
|
+
end
|
44
|
+
|
45
|
+
before do
|
46
|
+
Backup::Model.extension = 'tar'
|
47
|
+
end
|
48
|
+
|
49
|
+
it do
|
50
|
+
Backup::Model.new('blah', 'blah') {}
|
51
|
+
Backup::Model.extension.should == 'tar'
|
52
|
+
end
|
53
|
+
|
54
|
+
it do
|
55
|
+
Backup::Model.new('blah', 'blah') {}
|
56
|
+
Backup::Model.file.should == "#{ File.join(Backup::TMP_PATH, "#{ Backup::TIME }.#{ Backup::TRIGGER }.tar") }"
|
57
|
+
end
|
58
|
+
|
59
|
+
it do
|
60
|
+
Backup::Model.new('blah', 'blah') {}
|
61
|
+
File.basename(Backup::Model.file).should == "#{ Backup::TIME }.#{ Backup::TRIGGER }.tar"
|
62
|
+
end
|
63
|
+
|
64
|
+
it do
|
65
|
+
Backup::Model.new('blah', 'blah') {}
|
66
|
+
Backup::Model.tmp_path.should == File.join(Backup::TMP_PATH, Backup::TRIGGER)
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'should create a new model with a trigger and label' do
|
70
|
+
model = Backup::Model.new('mysql-s3', 'MySQL S3 Backup for MyApp') {}
|
71
|
+
model.trigger.should == 'mysql-s3'
|
72
|
+
model.label.should == 'MySQL S3 Backup for MyApp'
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'should have the time logged in the object' do
|
76
|
+
model = Backup::Model.new('mysql-s3', 'MySQL S3 Backup for MyApp') {}
|
77
|
+
model.time.should == Backup::TIME
|
78
|
+
end
|
79
|
+
|
80
|
+
describe '#extension' do
|
81
|
+
it 'should start out with just .tar before compression occurs' do
|
82
|
+
Backup::Model.extension.should == 'tar'
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
describe 'databases' do
|
87
|
+
it 'should add the mysql adapter to the array of databases to invoke' do
|
88
|
+
model = Backup::Model.new('mysql-s3', 'MySQL S3 Backup for MyApp') do
|
89
|
+
database('TestDatabase')
|
90
|
+
end
|
91
|
+
|
92
|
+
model.databases.count.should == 1
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'should add 2 mysql adapters to the array of adapters to invoke' do
|
96
|
+
model = Backup::Model.new('mysql-s3', 'MySQL S3 Backup for MyApp') do
|
97
|
+
database('TestDatabase')
|
98
|
+
database('TestDatabase')
|
99
|
+
end
|
100
|
+
|
101
|
+
model.databases.count.should == 2
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
describe 'storages' do
|
106
|
+
it 'should add a storage to the array of storages to use' do
|
107
|
+
model = Backup::Model.new('mysql-s3', 'MySQL S3 Backup for MyApp') do
|
108
|
+
store_with('TestStorage')
|
109
|
+
end
|
110
|
+
|
111
|
+
model.storages.count.should == 1
|
112
|
+
end
|
113
|
+
|
114
|
+
it 'should add a storage to the array of storages to use' do
|
115
|
+
model = Backup::Model.new('mysql-s3', 'MySQL S3 Backup for MyApp') do
|
116
|
+
store_with('TestStorage')
|
117
|
+
store_with('TestStorage')
|
118
|
+
end
|
119
|
+
|
120
|
+
model.storages.count.should == 2
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
describe 'archives' do
|
125
|
+
it 'should add an archive to the array of archives to use' do
|
126
|
+
model = Backup::Model.new('mysql-s3', 'MySQL S3 Backup for MyApp') do
|
127
|
+
archive('my_archive')
|
128
|
+
end
|
129
|
+
|
130
|
+
model.archives.count.should == 1
|
131
|
+
end
|
132
|
+
|
133
|
+
it 'should add a storage to the array of storages to use' do
|
134
|
+
model = Backup::Model.new('mysql-s3', 'MySQL S3 Backup for MyApp') do
|
135
|
+
archive('TestStorage')
|
136
|
+
archive('TestStorage')
|
137
|
+
end
|
138
|
+
|
139
|
+
model.archives.count.should == 2
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
describe '#compress_with' do
|
144
|
+
it 'should add a compressor to the array of compressors to use' do
|
145
|
+
model = Backup::Model.new('mysql-s3', 'MySQL S3 Backup for MyApp') do
|
146
|
+
compress_with('Gzip')
|
147
|
+
end
|
148
|
+
|
149
|
+
model.compressors.count.should == 1
|
150
|
+
end
|
151
|
+
|
152
|
+
it 'should add a compressor to the array of compressors to use' do
|
153
|
+
model = Backup::Model.new('mysql-s3', 'MySQL S3 Backup for MyApp') do
|
154
|
+
compress_with('Gzip')
|
155
|
+
compress_with('SevenZip')
|
156
|
+
end
|
157
|
+
|
158
|
+
model.compressors.count.should == 2
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
describe '#encrypt_with' do
|
163
|
+
it 'should add a encryptor to the array of encryptors to use' do
|
164
|
+
model = Backup::Model.new('mysql-s3', 'MySQL S3 Backup for MyApp') do
|
165
|
+
encrypt_with('OpenSSL')
|
166
|
+
end
|
167
|
+
|
168
|
+
model.encryptors.count.should == 1
|
169
|
+
end
|
170
|
+
|
171
|
+
it 'should add a encryptor to the array of encryptors to use' do
|
172
|
+
model = Backup::Model.new('mysql-s3', 'MySQL S3 Backup for MyApp') do
|
173
|
+
encrypt_with('OpenSSL')
|
174
|
+
encrypt_with('GPG')
|
175
|
+
end
|
176
|
+
|
177
|
+
model.encryptors.count.should == 2
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
describe '#notify_by' do
|
182
|
+
it 'should add a notifier to the array of notifiers to use' do
|
183
|
+
model = Backup::Model.new('mysql-s3', 'MySQL S3 Backup for MyApp') do
|
184
|
+
notify_by('TestMail')
|
185
|
+
end
|
186
|
+
|
187
|
+
model.notifiers.count.should == 1
|
188
|
+
end
|
189
|
+
|
190
|
+
it 'should add a notifier to the array of notifiers to use' do
|
191
|
+
model = Backup::Model.new('mysql-s3', 'MySQL S3 Backup for MyApp') do
|
192
|
+
notify_by('TestMail')
|
193
|
+
notify_by('TestMail')
|
194
|
+
end
|
195
|
+
|
196
|
+
model.notifiers.count.should == 2
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
describe '#package!' do
|
201
|
+
before do
|
202
|
+
[:utility, :run].each { |method| model.stubs(method) }
|
203
|
+
Backup::Logger.stubs(:message)
|
204
|
+
end
|
205
|
+
|
206
|
+
it 'should package the folder' do
|
207
|
+
model.expects(:utility).with(:tar).returns(:tar)
|
208
|
+
model.expects(:run).with("tar -c -C '#{ Backup::TMP_PATH }' '#{ Backup::TRIGGER }' > '#{ File.join( Backup::TMP_PATH, "#{ Backup::TIME }.#{ Backup::TRIGGER }.tar" ) }'")
|
209
|
+
model.send(:package!)
|
210
|
+
end
|
211
|
+
|
212
|
+
it 'should log' do
|
213
|
+
Backup::Logger.expects(:message).with("Backup started packaging everything to a single archive file.")
|
214
|
+
model.send(:package!)
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
218
|
+
describe '#clean!' do
|
219
|
+
before do
|
220
|
+
[:utility, :run, :rm].each { |method| model.stubs(method) }
|
221
|
+
Backup::Logger.stubs(:message)
|
222
|
+
end
|
223
|
+
|
224
|
+
it 'should remove the temporary files and folders that were created' do
|
225
|
+
model.expects(:utility).with(:rm).returns(:rm)
|
226
|
+
model.expects(:run).with("rm -rf '#{ File.join(Backup::TMP_PATH, Backup::TRIGGER) }' '#{ File.join(Backup::TMP_PATH, "#{ Backup::TIME }.#{ Backup::TRIGGER }.tar") }'")
|
227
|
+
model.send(:clean!)
|
228
|
+
end
|
229
|
+
|
230
|
+
it do
|
231
|
+
Backup::Logger.expects(:message).with("Backup started cleaning up the temporary files.")
|
232
|
+
model.send(:clean!)
|
233
|
+
end
|
234
|
+
end
|
235
|
+
|
236
|
+
end
|