alg-backup 3.0.10
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 +25 -0
- data/Gemfile.lock +101 -0
- data/LICENSE.md +24 -0
- data/README.md +276 -0
- data/backup.gemspec +39 -0
- data/bin/backup +260 -0
- data/lib/backup.rb +168 -0
- data/lib/backup/archive.rb +73 -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 +15 -0
- 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 +54 -0
- data/lib/backup/configuration/notifier/base.rb +39 -0
- data/lib/backup/configuration/notifier/mail.rb +52 -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 +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/dependency.rb +84 -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 +86 -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/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/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 +87 -0
- data/lib/backup/storage/ftp.rb +114 -0
- data/lib/backup/storage/object.rb +45 -0
- data/lib/backup/storage/rsync.rb +99 -0
- data/lib/backup/storage/s3.rb +108 -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 +117 -0
- data/lib/backup/syncer/s3.rb +116 -0
- data/lib/backup/version.rb +43 -0
- 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/notifier/twitter +9 -0
- data/lib/templates/readme +15 -0
- data/lib/templates/storage/cloudfiles +7 -0
- data/lib/templates/storage/dropbox +9 -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/lib/templates/syncer/rsync +14 -0
- data/lib/templates/syncer/s3 +12 -0
- data/spec/archive_spec.rb +90 -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 +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 +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 +46 -0
- data/spec/model_spec.rb +236 -0
- data/spec/notifier/mail_spec.rb +97 -0
- data/spec/notifier/twitter_spec.rb +86 -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 +105 -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/syncer/rsync_spec.rb +156 -0
- data/spec/syncer/s3_spec.rb +139 -0
- data/spec/version_spec.rb +21 -0
- metadata +217 -0
@@ -0,0 +1,43 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Backup
|
4
|
+
class Version
|
5
|
+
|
6
|
+
##
|
7
|
+
# Change the MAJOR, MINOR and PATCH constants below
|
8
|
+
# to adjust the version of the Backup gem
|
9
|
+
#
|
10
|
+
# MAJOR:
|
11
|
+
# Defines the major version
|
12
|
+
# MINOR:
|
13
|
+
# Defines the minor version
|
14
|
+
# PATCH:
|
15
|
+
# Defines the patch version
|
16
|
+
MAJOR, MINOR, PATCH = 3, 0, 10
|
17
|
+
|
18
|
+
##
|
19
|
+
# Returns the major version ( big release based off of multiple minor releases )
|
20
|
+
def self.major
|
21
|
+
MAJOR
|
22
|
+
end
|
23
|
+
|
24
|
+
##
|
25
|
+
# Returns the minor version ( small release based off of multiple patches )
|
26
|
+
def self.minor
|
27
|
+
MINOR
|
28
|
+
end
|
29
|
+
|
30
|
+
##
|
31
|
+
# Returns the patch version ( updates, features and (crucial) bug fixes )
|
32
|
+
def self.patch
|
33
|
+
PATCH
|
34
|
+
end
|
35
|
+
|
36
|
+
##
|
37
|
+
# Returns the current version of the Backup gem ( qualified for the gemspec )
|
38
|
+
def self.current
|
39
|
+
"#{major}.#{minor}.#{patch}"
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
database MongoDB do |db|
|
2
|
+
db.name = "my_database_name"
|
3
|
+
db.username = "my_username"
|
4
|
+
db.password = "my_password"
|
5
|
+
db.host = "localhost"
|
6
|
+
db.port = 5432
|
7
|
+
db.ipv6 = false
|
8
|
+
db.only_collections = ['only', 'these' 'collections']
|
9
|
+
db.additional_options = []
|
10
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
database MySQL do |db|
|
2
|
+
db.name = "my_database_name"
|
3
|
+
db.username = "my_username"
|
4
|
+
db.password = "my_password"
|
5
|
+
db.host = "localhost"
|
6
|
+
db.port = 3306
|
7
|
+
db.socket = "/tmp/mysql.sock"
|
8
|
+
db.skip_tables = ['skip', 'these', 'tables']
|
9
|
+
db.only_tables = ['only', 'these' 'tables']
|
10
|
+
db.additional_options = ['--quick', '--single-transaction']
|
11
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
database PostgreSQL do |db|
|
2
|
+
db.name = "my_database_name"
|
3
|
+
db.username = "my_username"
|
4
|
+
db.password = "my_password"
|
5
|
+
db.host = "localhost"
|
6
|
+
db.port = 5432
|
7
|
+
db.socket = "/tmp/pg.sock"
|
8
|
+
db.skip_tables = ['skip', 'these', 'tables']
|
9
|
+
db.only_tables = ['only', 'these' 'tables']
|
10
|
+
db.additional_options = ['--quick', '--single-transaction']
|
11
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
notify_by Mail do |mail|
|
2
|
+
mail.on_success = true
|
3
|
+
mail.on_failure = true
|
4
|
+
|
5
|
+
mail.from = 'sender@email.com'
|
6
|
+
mail.to = 'receiver@email.com'
|
7
|
+
mail.address = 'smtp.gmail.com'
|
8
|
+
mail.port = 587
|
9
|
+
mail.domain = 'your.host.name'
|
10
|
+
mail.user_name = 'sender@email.com'
|
11
|
+
mail.password = 'my_password'
|
12
|
+
mail.authentication = 'plain'
|
13
|
+
mail.enable_starttls_auto = true
|
14
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
notify_by Twitter do |tweet|
|
2
|
+
tweet.on_success = true
|
3
|
+
tweet.on_failure = true
|
4
|
+
|
5
|
+
tweet.consumer_key = 'my_consumer_key'
|
6
|
+
tweet.consumer_secret = 'my_consumer_secret'
|
7
|
+
tweet.oauth_token = 'my_oauth_token'
|
8
|
+
tweet.oauth_token_secret = 'my_oauth_token_secret'
|
9
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
##
|
2
|
+
# Backup
|
3
|
+
# Generated Template
|
4
|
+
#
|
5
|
+
# For more information:
|
6
|
+
#
|
7
|
+
# View the Git repository at https://github.com/meskyanichi/backup
|
8
|
+
# View the Wiki/Documentation at https://github.com/meskyanichi/backup/wiki
|
9
|
+
# View the issue log at https://github.com/meskyanichi/backup/issues
|
10
|
+
#
|
11
|
+
# When you're finished configuring this configuration file,
|
12
|
+
# you can run it from the command line by issuing the following command:
|
13
|
+
#
|
14
|
+
# $ backup -t my_backup [-c <path_to_configuration_file>]
|
15
|
+
|
@@ -0,0 +1,14 @@
|
|
1
|
+
sync_with RSync do |rsync|
|
2
|
+
rsync.ip = "123.45.678.90"
|
3
|
+
rsync.port = 22
|
4
|
+
rsync.username = "my_username"
|
5
|
+
rsync.password = "my_password"
|
6
|
+
rsync.path = "~/backups/"
|
7
|
+
rsync.mirror = true
|
8
|
+
rsync.compress = true
|
9
|
+
|
10
|
+
rsync.directories do |directory|
|
11
|
+
directory.add "/var/apps/my_app/public/uploads"
|
12
|
+
directory.add "/var/apps/my_app/logs"
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
sync_with S3 do |s3|
|
2
|
+
s3.access_key_id = "my_access_key_id"
|
3
|
+
s3.secret_access_key = "my_secret_access_key"
|
4
|
+
s3.bucket = "my-bucket"
|
5
|
+
s3.path = "/backups"
|
6
|
+
s3.mirror = true
|
7
|
+
|
8
|
+
s3.directories do |directory|
|
9
|
+
directory.add "/path/to/directory/to/sync"
|
10
|
+
directory.add "/path/to/other/directory/to/sync"
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
4
|
+
|
5
|
+
describe Backup::Archive do
|
6
|
+
|
7
|
+
let(:archive) do
|
8
|
+
Backup::Archive.new(:dummy_archive) do |a|
|
9
|
+
a.add '/home/rspecuser/somefile'
|
10
|
+
a.add '/home/rspecuser/logs/'
|
11
|
+
a.add '/home/rspecuser/dotfiles/'
|
12
|
+
a.exclude '/home/rspecuser/excludefile'
|
13
|
+
a.exclude '/home/rspecuser/excludedir/'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should have no paths' do
|
18
|
+
archive = Backup::Archive.new(:dummy_archive) { |a| }
|
19
|
+
archive.paths.count.should == 0
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'should have no excludes' do
|
23
|
+
archive = Backup::Archive.new(:dummy_archive) { |a| }
|
24
|
+
archive.excludes.count.should == 0
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'should have 3 paths' do
|
28
|
+
archive.paths.count.should == 3
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'should have 2 excludes' do
|
32
|
+
archive.excludes.count.should == 2
|
33
|
+
end
|
34
|
+
|
35
|
+
it do
|
36
|
+
archive.name.should == :dummy_archive
|
37
|
+
end
|
38
|
+
|
39
|
+
describe '#paths_to_package' do
|
40
|
+
it 'should return a tar -c friendly string' do
|
41
|
+
archive.send(:paths_to_package).should ==
|
42
|
+
"'/home/rspecuser/somefile' '/home/rspecuser/logs/' '/home/rspecuser/dotfiles/'"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe '#paths_to_exclude' do
|
47
|
+
it 'should be empty' do
|
48
|
+
archive = Backup::Archive.new(:dummy_archive) { |a| }
|
49
|
+
archive.send(:paths_to_exclude).should be_nil
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'should return a tar -c friendly string' do
|
53
|
+
archive.send(:paths_to_exclude).should ==
|
54
|
+
"--exclude={'/home/rspecuser/excludefile','/home/rspecuser/excludedir/'}"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe '#perform!' do
|
59
|
+
before do
|
60
|
+
[:mkdir, :run, :utility].each { |method| archive.stubs(method) }
|
61
|
+
Backup::Logger.stubs(:message)
|
62
|
+
end
|
63
|
+
|
64
|
+
context 'when both paths were added and paths that should be excluded were added' do
|
65
|
+
it 'should render both the syntax for the paths that be included as well as excluded' do
|
66
|
+
archive.expects(:mkdir).with(File.join(Backup::TMP_PATH, Backup::TRIGGER, 'archive'))
|
67
|
+
archive.expects(:run).with("tar -c --exclude={'/home/rspecuser/excludefile','/home/rspecuser/excludedir/'} '/home/rspecuser/somefile' '/home/rspecuser/logs/' '/home/rspecuser/dotfiles/' 1> '#{File.join(Backup::TMP_PATH, Backup::TRIGGER, 'archive', "#{:dummy_archive}.tar")}' 2> /dev/null")
|
68
|
+
archive.expects(:utility).with(:tar).returns(:tar)
|
69
|
+
archive.perform!
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
context 'when there are paths to add, and no exclude patterns were defined' do
|
74
|
+
it 'should only render syntax for the defined paths' do
|
75
|
+
archive = Backup::Archive.new(:dummy_archive) do |a|
|
76
|
+
a.add '/path/to/archive'
|
77
|
+
end
|
78
|
+
|
79
|
+
archive.stubs(:utility).returns(:tar)
|
80
|
+
archive.expects(:run).with("tar -c '/path/to/archive' 1> '#{File.join(Backup::TMP_PATH, Backup::TRIGGER, 'archive', "#{:dummy_archive}.tar")}' 2> /dev/null")
|
81
|
+
archive.perform!
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'should log the status' do
|
86
|
+
Backup::Logger.expects(:message).with("Backup::Archive started packaging and archiving \"/home/rspecuser/somefile\", \"/home/rspecuser/logs/\", \"/home/rspecuser/dotfiles/\".")
|
87
|
+
archive.perform!
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
data/spec/backup_spec.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
4
|
+
|
5
|
+
describe Backup do
|
6
|
+
it do
|
7
|
+
Backup::TMP_PATH.should == File.join(ENV['HOME'], 'Backup', '.tmp')
|
8
|
+
Backup::DATA_PATH.should == File.join(ENV['HOME'], 'Backup', 'data')
|
9
|
+
Backup::CONFIG_FILE.should == File.join(ENV['HOME'], 'Backup', 'config.rb')
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
4
|
+
|
5
|
+
describe Backup::Compressor::Gzip do
|
6
|
+
let(:compressor) { Backup::Compressor::Gzip.new }
|
7
|
+
|
8
|
+
before do
|
9
|
+
Backup::Model.extension = 'tar'
|
10
|
+
end
|
11
|
+
|
12
|
+
describe 'the options' do
|
13
|
+
it do
|
14
|
+
compressor.send(:best).should == []
|
15
|
+
end
|
16
|
+
|
17
|
+
it do
|
18
|
+
compressor.send(:fast).should == []
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '#perform!' do
|
23
|
+
before do
|
24
|
+
[:run, :utility].each { |method| compressor.stubs(method) }
|
25
|
+
Backup::Logger.stubs(:message)
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'should perform the compression' do
|
29
|
+
compressor.expects(:utility).with(:gzip).returns(:gzip)
|
30
|
+
compressor.expects(:run).with("gzip '#{ File.join(Backup::TMP_PATH, "#{ Backup::TIME }.#{ Backup::TRIGGER }.tar") }'")
|
31
|
+
compressor.perform!
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'should perform the compression with the --best and --fast options' do
|
35
|
+
compressor = Backup::Compressor::Gzip.new do |c|
|
36
|
+
c.best = true
|
37
|
+
c.fast = true
|
38
|
+
end
|
39
|
+
|
40
|
+
compressor.stubs(:utility).returns(:gzip)
|
41
|
+
compressor.expects(:run).with("gzip --best --fast '#{ File.join(Backup::TMP_PATH, "#{ Backup::TIME }.#{ Backup::TRIGGER }.tar") }'")
|
42
|
+
compressor.perform!
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'should set the class variable @extension (Backup::Model.extension) to .gz' do
|
46
|
+
compressor.stubs(:utility).returns(:gzip)
|
47
|
+
compressor.expects(:run)
|
48
|
+
|
49
|
+
Backup::Model.extension.should == 'tar'
|
50
|
+
compressor.perform!
|
51
|
+
Backup::Model.extension.should == 'tar.gz'
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'should log' do
|
55
|
+
Backup::Logger.expects(:message).with("Backup::Compressor::Gzip started compressing the archive.")
|
56
|
+
compressor.perform!
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
4
|
+
|
5
|
+
describe Backup::Configuration::Helpers do
|
6
|
+
|
7
|
+
before do
|
8
|
+
class Backup::Configuration::Base
|
9
|
+
class << self
|
10
|
+
attr_accessor :rspec_method, :rspec_test, :rspec_mocha
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should clear the defaults' do
|
16
|
+
Backup::Configuration::Base.expects(:send).with('rspec_method=', nil)
|
17
|
+
Backup::Configuration::Base.expects(:send).with('rspec_test=', nil)
|
18
|
+
Backup::Configuration::Base.expects(:send).with('rspec_mocha=', nil)
|
19
|
+
Backup::Configuration::Base.clear_defaults!
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'should return the setters' do
|
23
|
+
Backup::Configuration::Base.setter_methods.count.should == 3
|
24
|
+
%w[rspec_method= rspec_test= rspec_mocha=].each do |method|
|
25
|
+
Backup::Configuration::Base.setter_methods.should include(method)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'should return the getters' do
|
30
|
+
Backup::Configuration::Base.getter_methods.count.should == 3
|
31
|
+
%w[rspec_method rspec_test rspec_mocha].each do |method|
|
32
|
+
Backup::Configuration::Base.getter_methods.should include(method)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|