backup_checksum 3.0.23
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of backup_checksum might be problematic. Click here for more details.
- data/.gitignore +7 -0
- data/.travis.yml +10 -0
- data/Gemfile +28 -0
- data/Gemfile.lock +130 -0
- data/Guardfile +21 -0
- data/LICENSE.md +24 -0
- data/README.md +476 -0
- data/backup_checksum.gemspec +32 -0
- data/bin/backup +11 -0
- data/lib/backup.rb +217 -0
- data/lib/backup/archive.rb +117 -0
- data/lib/backup/binder.rb +22 -0
- data/lib/backup/checksum/base.rb +44 -0
- data/lib/backup/checksum/shasum.rb +16 -0
- data/lib/backup/cleaner.rb +121 -0
- data/lib/backup/cli/helpers.rb +88 -0
- data/lib/backup/cli/utility.rb +247 -0
- data/lib/backup/compressor/base.rb +29 -0
- data/lib/backup/compressor/bzip2.rb +50 -0
- data/lib/backup/compressor/gzip.rb +47 -0
- data/lib/backup/compressor/lzma.rb +50 -0
- data/lib/backup/compressor/pbzip2.rb +56 -0
- data/lib/backup/config.rb +173 -0
- data/lib/backup/configuration/base.rb +15 -0
- data/lib/backup/configuration/checksum/base.rb +9 -0
- data/lib/backup/configuration/checksum/shasum.rb +9 -0
- data/lib/backup/configuration/compressor/base.rb +9 -0
- data/lib/backup/configuration/compressor/bzip2.rb +23 -0
- data/lib/backup/configuration/compressor/gzip.rb +23 -0
- data/lib/backup/configuration/compressor/lzma.rb +23 -0
- data/lib/backup/configuration/compressor/pbzip2.rb +28 -0
- data/lib/backup/configuration/database/base.rb +19 -0
- data/lib/backup/configuration/database/mongodb.rb +49 -0
- data/lib/backup/configuration/database/mysql.rb +42 -0
- data/lib/backup/configuration/database/postgresql.rb +41 -0
- data/lib/backup/configuration/database/redis.rb +39 -0
- data/lib/backup/configuration/database/riak.rb +29 -0
- data/lib/backup/configuration/encryptor/base.rb +9 -0
- data/lib/backup/configuration/encryptor/gpg.rb +17 -0
- data/lib/backup/configuration/encryptor/open_ssl.rb +32 -0
- data/lib/backup/configuration/helpers.rb +52 -0
- data/lib/backup/configuration/notifier/base.rb +28 -0
- data/lib/backup/configuration/notifier/campfire.rb +25 -0
- data/lib/backup/configuration/notifier/hipchat.rb +41 -0
- data/lib/backup/configuration/notifier/mail.rb +112 -0
- data/lib/backup/configuration/notifier/presently.rb +25 -0
- data/lib/backup/configuration/notifier/prowl.rb +23 -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 +25 -0
- data/lib/backup/configuration/storage/dropbox.rb +58 -0
- data/lib/backup/configuration/storage/ftp.rb +29 -0
- data/lib/backup/configuration/storage/local.rb +17 -0
- data/lib/backup/configuration/storage/ninefold.rb +20 -0
- data/lib/backup/configuration/storage/rsync.rb +29 -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/base.rb +10 -0
- data/lib/backup/configuration/syncer/cloud.rb +23 -0
- data/lib/backup/configuration/syncer/cloud_files.rb +30 -0
- data/lib/backup/configuration/syncer/rsync/base.rb +28 -0
- data/lib/backup/configuration/syncer/rsync/local.rb +11 -0
- data/lib/backup/configuration/syncer/rsync/pull.rb +11 -0
- data/lib/backup/configuration/syncer/rsync/push.rb +31 -0
- data/lib/backup/configuration/syncer/s3.rb +23 -0
- data/lib/backup/database/base.rb +59 -0
- data/lib/backup/database/mongodb.rb +232 -0
- data/lib/backup/database/mysql.rb +163 -0
- data/lib/backup/database/postgresql.rb +146 -0
- data/lib/backup/database/redis.rb +139 -0
- data/lib/backup/database/riak.rb +69 -0
- data/lib/backup/dependency.rb +114 -0
- data/lib/backup/encryptor/base.rb +29 -0
- data/lib/backup/encryptor/gpg.rb +80 -0
- data/lib/backup/encryptor/open_ssl.rb +72 -0
- data/lib/backup/errors.rb +124 -0
- data/lib/backup/logger.rb +152 -0
- data/lib/backup/model.rb +386 -0
- data/lib/backup/notifier/base.rb +81 -0
- data/lib/backup/notifier/campfire.rb +168 -0
- data/lib/backup/notifier/hipchat.rb +99 -0
- data/lib/backup/notifier/mail.rb +206 -0
- data/lib/backup/notifier/presently.rb +88 -0
- data/lib/backup/notifier/prowl.rb +65 -0
- data/lib/backup/notifier/twitter.rb +70 -0
- data/lib/backup/package.rb +51 -0
- data/lib/backup/packager.rb +108 -0
- data/lib/backup/pipeline.rb +107 -0
- data/lib/backup/splitter.rb +75 -0
- data/lib/backup/storage/base.rb +119 -0
- data/lib/backup/storage/cloudfiles.rb +87 -0
- data/lib/backup/storage/cycler.rb +117 -0
- data/lib/backup/storage/dropbox.rb +181 -0
- data/lib/backup/storage/ftp.rb +119 -0
- data/lib/backup/storage/local.rb +82 -0
- data/lib/backup/storage/ninefold.rb +116 -0
- data/lib/backup/storage/rsync.rb +149 -0
- data/lib/backup/storage/s3.rb +94 -0
- data/lib/backup/storage/scp.rb +99 -0
- data/lib/backup/storage/sftp.rb +108 -0
- data/lib/backup/syncer/base.rb +42 -0
- data/lib/backup/syncer/cloud.rb +190 -0
- data/lib/backup/syncer/cloud_files.rb +56 -0
- data/lib/backup/syncer/rsync/base.rb +52 -0
- data/lib/backup/syncer/rsync/local.rb +53 -0
- data/lib/backup/syncer/rsync/pull.rb +38 -0
- data/lib/backup/syncer/rsync/push.rb +113 -0
- data/lib/backup/syncer/s3.rb +47 -0
- data/lib/backup/template.rb +46 -0
- data/lib/backup/version.rb +43 -0
- data/spec/archive_spec.rb +335 -0
- data/spec/cleaner_spec.rb +304 -0
- data/spec/cli/helpers_spec.rb +176 -0
- data/spec/cli/utility_spec.rb +363 -0
- data/spec/compressor/base_spec.rb +31 -0
- data/spec/compressor/bzip2_spec.rb +83 -0
- data/spec/compressor/gzip_spec.rb +83 -0
- data/spec/compressor/lzma_spec.rb +83 -0
- data/spec/compressor/pbzip2_spec.rb +124 -0
- data/spec/config_spec.rb +321 -0
- data/spec/configuration/base_spec.rb +35 -0
- data/spec/configuration/compressor/bzip2_spec.rb +29 -0
- data/spec/configuration/compressor/gzip_spec.rb +29 -0
- data/spec/configuration/compressor/lzma_spec.rb +29 -0
- data/spec/configuration/compressor/pbzip2_spec.rb +32 -0
- data/spec/configuration/database/base_spec.rb +17 -0
- data/spec/configuration/database/mongodb_spec.rb +56 -0
- data/spec/configuration/database/mysql_spec.rb +53 -0
- data/spec/configuration/database/postgresql_spec.rb +53 -0
- data/spec/configuration/database/redis_spec.rb +50 -0
- data/spec/configuration/database/riak_spec.rb +35 -0
- data/spec/configuration/encryptor/gpg_spec.rb +26 -0
- data/spec/configuration/encryptor/open_ssl_spec.rb +35 -0
- data/spec/configuration/notifier/base_spec.rb +32 -0
- data/spec/configuration/notifier/campfire_spec.rb +32 -0
- data/spec/configuration/notifier/hipchat_spec.rb +44 -0
- data/spec/configuration/notifier/mail_spec.rb +71 -0
- data/spec/configuration/notifier/presently_spec.rb +35 -0
- data/spec/configuration/notifier/prowl_spec.rb +29 -0
- data/spec/configuration/notifier/twitter_spec.rb +35 -0
- data/spec/configuration/storage/cloudfiles_spec.rb +41 -0
- data/spec/configuration/storage/dropbox_spec.rb +38 -0
- data/spec/configuration/storage/ftp_spec.rb +44 -0
- data/spec/configuration/storage/local_spec.rb +29 -0
- data/spec/configuration/storage/ninefold_spec.rb +32 -0
- data/spec/configuration/storage/rsync_spec.rb +41 -0
- data/spec/configuration/storage/s3_spec.rb +38 -0
- data/spec/configuration/storage/scp_spec.rb +41 -0
- data/spec/configuration/storage/sftp_spec.rb +41 -0
- data/spec/configuration/syncer/cloud_files_spec.rb +44 -0
- data/spec/configuration/syncer/rsync/base_spec.rb +33 -0
- data/spec/configuration/syncer/rsync/local_spec.rb +10 -0
- data/spec/configuration/syncer/rsync/pull_spec.rb +10 -0
- data/spec/configuration/syncer/rsync/push_spec.rb +43 -0
- data/spec/configuration/syncer/s3_spec.rb +38 -0
- data/spec/database/base_spec.rb +54 -0
- data/spec/database/mongodb_spec.rb +428 -0
- data/spec/database/mysql_spec.rb +335 -0
- data/spec/database/postgresql_spec.rb +278 -0
- data/spec/database/redis_spec.rb +260 -0
- data/spec/database/riak_spec.rb +108 -0
- data/spec/dependency_spec.rb +49 -0
- data/spec/encryptor/base_spec.rb +30 -0
- data/spec/encryptor/gpg_spec.rb +134 -0
- data/spec/encryptor/open_ssl_spec.rb +129 -0
- data/spec/errors_spec.rb +306 -0
- data/spec/logger_spec.rb +363 -0
- data/spec/model_spec.rb +649 -0
- data/spec/notifier/base_spec.rb +89 -0
- data/spec/notifier/campfire_spec.rb +199 -0
- data/spec/notifier/hipchat_spec.rb +188 -0
- data/spec/notifier/mail_spec.rb +280 -0
- data/spec/notifier/presently_spec.rb +181 -0
- data/spec/notifier/prowl_spec.rb +117 -0
- data/spec/notifier/twitter_spec.rb +132 -0
- data/spec/package_spec.rb +61 -0
- data/spec/packager_spec.rb +225 -0
- data/spec/pipeline_spec.rb +257 -0
- data/spec/spec_helper.rb +59 -0
- data/spec/splitter_spec.rb +120 -0
- data/spec/storage/base_spec.rb +160 -0
- data/spec/storage/cloudfiles_spec.rb +230 -0
- data/spec/storage/cycler_spec.rb +239 -0
- data/spec/storage/dropbox_spec.rb +370 -0
- data/spec/storage/ftp_spec.rb +247 -0
- data/spec/storage/local_spec.rb +235 -0
- data/spec/storage/ninefold_spec.rb +319 -0
- data/spec/storage/rsync_spec.rb +345 -0
- data/spec/storage/s3_spec.rb +221 -0
- data/spec/storage/scp_spec.rb +209 -0
- data/spec/storage/sftp_spec.rb +220 -0
- data/spec/syncer/base_spec.rb +22 -0
- data/spec/syncer/cloud_files_spec.rb +192 -0
- data/spec/syncer/rsync/base_spec.rb +118 -0
- data/spec/syncer/rsync/local_spec.rb +121 -0
- data/spec/syncer/rsync/pull_spec.rb +90 -0
- data/spec/syncer/rsync/push_spec.rb +327 -0
- data/spec/syncer/s3_spec.rb +192 -0
- data/spec/version_spec.rb +21 -0
- data/templates/cli/utility/archive +25 -0
- data/templates/cli/utility/compressor/bzip2 +7 -0
- data/templates/cli/utility/compressor/gzip +7 -0
- data/templates/cli/utility/compressor/lzma +7 -0
- data/templates/cli/utility/compressor/pbzip2 +7 -0
- data/templates/cli/utility/config +31 -0
- data/templates/cli/utility/database/mongodb +18 -0
- data/templates/cli/utility/database/mysql +21 -0
- data/templates/cli/utility/database/postgresql +17 -0
- data/templates/cli/utility/database/redis +16 -0
- data/templates/cli/utility/database/riak +11 -0
- data/templates/cli/utility/encryptor/gpg +12 -0
- data/templates/cli/utility/encryptor/openssl +9 -0
- data/templates/cli/utility/model.erb +23 -0
- data/templates/cli/utility/notifier/campfire +12 -0
- data/templates/cli/utility/notifier/hipchat +15 -0
- data/templates/cli/utility/notifier/mail +22 -0
- data/templates/cli/utility/notifier/presently +13 -0
- data/templates/cli/utility/notifier/prowl +11 -0
- data/templates/cli/utility/notifier/twitter +13 -0
- data/templates/cli/utility/splitter +7 -0
- data/templates/cli/utility/storage/cloud_files +22 -0
- data/templates/cli/utility/storage/dropbox +20 -0
- data/templates/cli/utility/storage/ftp +12 -0
- data/templates/cli/utility/storage/local +7 -0
- data/templates/cli/utility/storage/ninefold +9 -0
- data/templates/cli/utility/storage/rsync +11 -0
- data/templates/cli/utility/storage/s3 +19 -0
- data/templates/cli/utility/storage/scp +11 -0
- data/templates/cli/utility/storage/sftp +11 -0
- data/templates/cli/utility/syncer/cloud_files +48 -0
- data/templates/cli/utility/syncer/rsync_local +12 -0
- data/templates/cli/utility/syncer/rsync_pull +17 -0
- data/templates/cli/utility/syncer/rsync_push +17 -0
- data/templates/cli/utility/syncer/s3 +45 -0
- data/templates/general/links +11 -0
- data/templates/general/version.erb +2 -0
- data/templates/notifier/mail/failure.erb +9 -0
- data/templates/notifier/mail/success.erb +7 -0
- data/templates/notifier/mail/warning.erb +9 -0
- data/templates/storage/dropbox/authorization_url.erb +6 -0
- data/templates/storage/dropbox/authorized.erb +4 -0
- data/templates/storage/dropbox/cache_file_written.erb +10 -0
- metadata +311 -0
@@ -0,0 +1,29 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Backup
|
4
|
+
module Compressor
|
5
|
+
class Base
|
6
|
+
include Backup::CLI::Helpers
|
7
|
+
include Backup::Configuration::Helpers
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
load_defaults!
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
##
|
16
|
+
# Return the encryptor name, with Backup namespace removed
|
17
|
+
def compressor_name
|
18
|
+
self.class.to_s.sub('Backup::', '')
|
19
|
+
end
|
20
|
+
|
21
|
+
##
|
22
|
+
# Logs a message to the console and log file to inform
|
23
|
+
# the client that Backup is using the compressor
|
24
|
+
def log!
|
25
|
+
Logger.message "Using #{ compressor_name } for compression."
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Backup
|
4
|
+
module Compressor
|
5
|
+
class Bzip2 < Base
|
6
|
+
|
7
|
+
##
|
8
|
+
# Tells Backup::Compressor::Bzip2 to compress
|
9
|
+
# better (-9) rather than faster when set to true
|
10
|
+
attr_accessor :best
|
11
|
+
|
12
|
+
##
|
13
|
+
# Tells Backup::Compressor::Bzip2 to compress
|
14
|
+
# faster (-1) rather than better when set to true
|
15
|
+
attr_accessor :fast
|
16
|
+
|
17
|
+
##
|
18
|
+
# Creates a new instance of Backup::Compressor::Bzip2 and
|
19
|
+
# configures it to either compress faster or better
|
20
|
+
# bzip2 compresses by default with -9 (best compression)
|
21
|
+
# and lower block sizes don't make things significantly faster
|
22
|
+
# (according to official bzip2 docs)
|
23
|
+
def initialize(&block)
|
24
|
+
super
|
25
|
+
|
26
|
+
@best ||= false
|
27
|
+
@fast ||= false
|
28
|
+
|
29
|
+
instance_eval(&block) if block_given?
|
30
|
+
end
|
31
|
+
|
32
|
+
##
|
33
|
+
# Yields to the block the compressor command with options
|
34
|
+
# and it's filename extension.
|
35
|
+
def compress_with
|
36
|
+
log!
|
37
|
+
yield "#{ utility(:bzip2) }#{ options }", '.bz2'
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
##
|
43
|
+
# Returns the option syntax for compressing
|
44
|
+
def options
|
45
|
+
" #{ '--best ' if @best }#{ '--fast' if @fast }".rstrip
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Backup
|
4
|
+
module Compressor
|
5
|
+
class Gzip < Base
|
6
|
+
|
7
|
+
##
|
8
|
+
# Tells Backup::Compressor::Gzip to compress
|
9
|
+
# better rather than faster when set to true
|
10
|
+
attr_accessor :best
|
11
|
+
|
12
|
+
##
|
13
|
+
# Tells Backup::Compressor::Gzip to compress
|
14
|
+
# faster rather than better when set to true
|
15
|
+
attr_accessor :fast
|
16
|
+
|
17
|
+
##
|
18
|
+
# Creates a new instance of Backup::Compressor::Gzip and
|
19
|
+
# configures it to either compress faster or better
|
20
|
+
def initialize(&block)
|
21
|
+
super
|
22
|
+
|
23
|
+
@best ||= false
|
24
|
+
@fast ||= false
|
25
|
+
|
26
|
+
instance_eval(&block) if block_given?
|
27
|
+
end
|
28
|
+
|
29
|
+
##
|
30
|
+
# Yields to the block the compressor command with options
|
31
|
+
# and it's filename extension.
|
32
|
+
def compress_with
|
33
|
+
log!
|
34
|
+
yield "#{ utility(:gzip) }#{ options }", '.gz'
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
##
|
40
|
+
# Returns the gzip option syntax for compressing
|
41
|
+
def options
|
42
|
+
" #{ '--best ' if @best }#{ '--fast' if @fast }".rstrip
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Backup
|
4
|
+
module Compressor
|
5
|
+
class Lzma < Base
|
6
|
+
|
7
|
+
##
|
8
|
+
# Tells Backup::Compressor::Lzma to compress
|
9
|
+
# better (-9) rather than faster when set to true
|
10
|
+
attr_accessor :best
|
11
|
+
|
12
|
+
##
|
13
|
+
# Tells Backup::Compressor::Lzma to compress
|
14
|
+
# faster (-1) rather than better when set to true
|
15
|
+
attr_accessor :fast
|
16
|
+
|
17
|
+
##
|
18
|
+
# Creates a new instance of Backup::Compressor::Lzma and
|
19
|
+
# configures it to either compress faster or better
|
20
|
+
# Lzma compresses by default with -9 (best compression)
|
21
|
+
# and lower block sizes don't make things significantly faster
|
22
|
+
# (according to official bzip2 docs)
|
23
|
+
def initialize(&block)
|
24
|
+
super
|
25
|
+
|
26
|
+
@best ||= false
|
27
|
+
@fast ||= false
|
28
|
+
|
29
|
+
instance_eval(&block) if block_given?
|
30
|
+
end
|
31
|
+
|
32
|
+
##
|
33
|
+
# Yields to the block the compressor command with options
|
34
|
+
# and it's filename extension.
|
35
|
+
def compress_with
|
36
|
+
log!
|
37
|
+
yield "#{ utility(:lzma) }#{ options }", '.lzma'
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
##
|
43
|
+
# Returns the option syntax for compressing
|
44
|
+
def options
|
45
|
+
" #{ '--best ' if @best }#{ '--fast' if @fast }".rstrip
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Backup
|
4
|
+
module Compressor
|
5
|
+
class Pbzip2 < Base
|
6
|
+
|
7
|
+
##
|
8
|
+
# Tells Backup::Compressor::Pbzip2 to compress
|
9
|
+
# better (-9) rather than faster when set to true
|
10
|
+
attr_accessor :best
|
11
|
+
|
12
|
+
##
|
13
|
+
# Tells Backup::Compressor::Pbzip2 to compress
|
14
|
+
# faster (-1) rather than better when set to true
|
15
|
+
attr_accessor :fast
|
16
|
+
|
17
|
+
##
|
18
|
+
# Tells Backup::Compressor::Pbzip2 how many processors
|
19
|
+
# use, by default autodetect is used
|
20
|
+
attr_accessor :processors
|
21
|
+
|
22
|
+
##
|
23
|
+
# Creates a new instance of Backup::Compressor::Pbzip2 and
|
24
|
+
# configures it to either compress faster or better
|
25
|
+
# bzip2 compresses by default with -9 (best compression)
|
26
|
+
# and lower block sizes don't make things significantly faster
|
27
|
+
# (according to official bzip2 docs)
|
28
|
+
def initialize(&block)
|
29
|
+
super
|
30
|
+
|
31
|
+
@best ||= false
|
32
|
+
@fast ||= false
|
33
|
+
@processors ||= false
|
34
|
+
|
35
|
+
instance_eval(&block) if block_given?
|
36
|
+
end
|
37
|
+
|
38
|
+
##
|
39
|
+
# Yields to the block the compressor command with options
|
40
|
+
# and it's filename extension.
|
41
|
+
def compress_with
|
42
|
+
log!
|
43
|
+
yield "#{ utility(:pbzip2) }#{ options }", '.bz2'
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
##
|
49
|
+
# Returns the gzip option syntax for compressing
|
50
|
+
def options
|
51
|
+
" #{ '--best ' if @best }#{ '--fast ' if @fast }#{ "-p#{@processors}" if @processors }".rstrip
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,173 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Backup
|
4
|
+
module Config
|
5
|
+
DEFAULTS = {
|
6
|
+
:config_file => 'config.rb',
|
7
|
+
:data_path => 'data',
|
8
|
+
:log_path => 'log',
|
9
|
+
:cache_path => '.cache',
|
10
|
+
:tmp_path => '.tmp'
|
11
|
+
}
|
12
|
+
|
13
|
+
class << self
|
14
|
+
attr_reader :user, :root_path, :config_file,
|
15
|
+
:data_path, :log_path, :cache_path, :tmp_path
|
16
|
+
|
17
|
+
##
|
18
|
+
# Setup required paths based on the given options
|
19
|
+
def update(options = {})
|
20
|
+
root_path = options[:root_path].to_s.strip
|
21
|
+
new_root = root_path.empty? ? false : set_root_path(root_path)
|
22
|
+
|
23
|
+
DEFAULTS.each do |name, ending|
|
24
|
+
set_path_variable(name, options[name], ending, new_root)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
##
|
29
|
+
# Tries to find and load the configuration file
|
30
|
+
def load_config!
|
31
|
+
unless File.exist?(@config_file)
|
32
|
+
raise Errors::Config::NotFoundError,
|
33
|
+
"Could not find configuration file: '#{@config_file}'."
|
34
|
+
end
|
35
|
+
|
36
|
+
module_eval(File.read(@config_file), @config_file)
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
##
|
42
|
+
# Sets the @root_path to the given +path+ and returns it.
|
43
|
+
# Raises an error if the given +path+ does not exist.
|
44
|
+
def set_root_path(path)
|
45
|
+
# allows #reset! to set the default @root_path,
|
46
|
+
# then use #update to set all other paths,
|
47
|
+
# without requiring that @root_path exist.
|
48
|
+
return @root_path if path == @root_path
|
49
|
+
|
50
|
+
path = File.expand_path(path)
|
51
|
+
unless File.directory?(path)
|
52
|
+
raise Errors::Config::NotFoundError, <<-EOS
|
53
|
+
Root Path Not Found
|
54
|
+
When specifying a --root-path, the path must exist.
|
55
|
+
Path was: #{ path }
|
56
|
+
EOS
|
57
|
+
end
|
58
|
+
@root_path = path
|
59
|
+
end
|
60
|
+
|
61
|
+
def set_path_variable(name, path, ending, root_path)
|
62
|
+
# strip any trailing '/' in case the user supplied this as part of
|
63
|
+
# an absolute path, so we can match it against File.expand_path()
|
64
|
+
path = path.to_s.sub(/\/\s*$/, '').lstrip
|
65
|
+
new_path = false
|
66
|
+
if path.empty?
|
67
|
+
new_path = File.join(root_path, ending) if root_path
|
68
|
+
else
|
69
|
+
new_path = File.expand_path(path)
|
70
|
+
unless path == new_path
|
71
|
+
new_path = File.join(root_path, path) if root_path
|
72
|
+
end
|
73
|
+
end
|
74
|
+
instance_variable_set(:"@#{name}", new_path) if new_path
|
75
|
+
end
|
76
|
+
|
77
|
+
##
|
78
|
+
# Set default values for accessors
|
79
|
+
def reset!
|
80
|
+
@user = ENV['USER'] || Etc.getpwuid.name
|
81
|
+
@root_path = File.join(File.expand_path(ENV['HOME'] || ''), 'Backup')
|
82
|
+
update(:root_path => @root_path)
|
83
|
+
end
|
84
|
+
|
85
|
+
##
|
86
|
+
# List the available database, storage, syncer, compressor, encryptor
|
87
|
+
# and notifier constants. These are used to dynamically define these
|
88
|
+
# constant names inside Backup::Config to provide a nicer configuration
|
89
|
+
# file DSL syntax to the users. Adding existing constants to the arrays
|
90
|
+
# below will enable the user to use a constant instead of a string.
|
91
|
+
# Nested namespaces are represented using Hashs. Deep nesting supported.
|
92
|
+
#
|
93
|
+
# Example, instead of:
|
94
|
+
# database "MySQL" do |mysql|
|
95
|
+
# sync_with "RSync::Local" do |rsync|
|
96
|
+
#
|
97
|
+
# You can do:
|
98
|
+
# database MySQL do |mysql|
|
99
|
+
# sync_with RSync::Local do |rsync|
|
100
|
+
#
|
101
|
+
def add_dsl_constants!
|
102
|
+
create_modules(
|
103
|
+
self,
|
104
|
+
[ # Databases
|
105
|
+
['MySQL', 'PostgreSQL', 'MongoDB', 'Redis', 'Riak'],
|
106
|
+
# Storages
|
107
|
+
['S3', 'CloudFiles', 'Ninefold', 'Dropbox', 'FTP',
|
108
|
+
'SFTP', 'SCP', 'RSync', 'Local'],
|
109
|
+
# Compressors
|
110
|
+
['Gzip', 'Bzip2', 'Pbzip2', 'Lzma'],
|
111
|
+
# Encryptors
|
112
|
+
['OpenSSL', 'GPG'],
|
113
|
+
# Checksum
|
114
|
+
['Shasum'],
|
115
|
+
# Syncers
|
116
|
+
['Rackspace', 'S3', { 'RSync' => ['Push', 'Pull', 'Local'] }],
|
117
|
+
# Notifiers
|
118
|
+
['Mail', 'Twitter', 'Campfire', 'Presently', 'Prowl', 'Hipchat']
|
119
|
+
]
|
120
|
+
)
|
121
|
+
end
|
122
|
+
|
123
|
+
def create_modules(scope, names)
|
124
|
+
names.flatten.each do |name|
|
125
|
+
if name.is_a?(Hash)
|
126
|
+
name.each do |key, val|
|
127
|
+
create_modules(get_or_create_empty_module(scope, key), [val])
|
128
|
+
end
|
129
|
+
else
|
130
|
+
get_or_create_empty_module(scope, name)
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
def get_or_create_empty_module(scope, const)
|
136
|
+
if scope.const_defined?(const)
|
137
|
+
scope.const_get(const)
|
138
|
+
else
|
139
|
+
scope.const_set(const, Module.new)
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
##
|
145
|
+
# Add the DSL constants and set default values for accessors when loaded.
|
146
|
+
add_dsl_constants!
|
147
|
+
reset!
|
148
|
+
end
|
149
|
+
|
150
|
+
##
|
151
|
+
# Warn user of deprecated Backup::CONFIG_FILE constant reference
|
152
|
+
# in older config.rb files and return the proper Config.config_file value.
|
153
|
+
class << self
|
154
|
+
def const_missing(const)
|
155
|
+
if const.to_s == 'CONFIG_FILE'
|
156
|
+
Logger.warn Errors::ConfigError.new(<<-EOS)
|
157
|
+
Configuration File Upgrade Needed
|
158
|
+
Your configuration file, located at #{ Config.config_file }
|
159
|
+
needs to be upgraded for this version of Backup.
|
160
|
+
The reference to 'Backup::CONFIG_FILE' in your current config.rb file
|
161
|
+
has been deprecated and needs to be replaced with 'Config.config_file'.
|
162
|
+
You may update this reference in your config.rb manually,
|
163
|
+
or generate a new config.rb using 'backup generate:config'.
|
164
|
+
* Note: if you have global configuration defaults set in config.rb,
|
165
|
+
be sure to transfer them to your new config.rb, should you choose
|
166
|
+
to generate a new config.rb file.
|
167
|
+
EOS
|
168
|
+
return Config.config_file
|
169
|
+
end
|
170
|
+
super
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|