backup 3.0.20 → 3.0.21

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.
Files changed (178) hide show
  1. data/Gemfile +1 -5
  2. data/Gemfile.lock +46 -50
  3. data/README.md +54 -27
  4. data/lib/backup.rb +16 -39
  5. data/lib/backup/archive.rb +42 -18
  6. data/lib/backup/cleaner.rb +110 -25
  7. data/lib/backup/cli/helpers.rb +17 -32
  8. data/lib/backup/cli/utility.rb +46 -107
  9. data/lib/backup/compressor/base.rb +14 -2
  10. data/lib/backup/compressor/bzip2.rb +10 -24
  11. data/lib/backup/compressor/gzip.rb +10 -24
  12. data/lib/backup/compressor/lzma.rb +10 -23
  13. data/lib/backup/compressor/pbzip2.rb +12 -32
  14. data/lib/backup/config.rb +171 -0
  15. data/lib/backup/configuration/compressor/base.rb +1 -2
  16. data/lib/backup/configuration/compressor/pbzip2.rb +4 -4
  17. data/lib/backup/configuration/database/base.rb +2 -1
  18. data/lib/backup/configuration/database/mongodb.rb +8 -0
  19. data/lib/backup/configuration/database/mysql.rb +4 -0
  20. data/lib/backup/configuration/database/postgresql.rb +4 -0
  21. data/lib/backup/configuration/database/redis.rb +4 -0
  22. data/lib/backup/configuration/database/riak.rb +5 -1
  23. data/lib/backup/configuration/encryptor/base.rb +1 -2
  24. data/lib/backup/configuration/encryptor/open_ssl.rb +1 -1
  25. data/lib/backup/configuration/helpers.rb +7 -2
  26. data/lib/backup/configuration/notifier/base.rb +4 -28
  27. data/lib/backup/configuration/storage/base.rb +1 -1
  28. data/lib/backup/configuration/storage/dropbox.rb +14 -4
  29. data/lib/backup/configuration/syncer/base.rb +10 -0
  30. data/lib/backup/configuration/syncer/rsync/base.rb +28 -0
  31. data/lib/backup/configuration/syncer/rsync/local.rb +11 -0
  32. data/lib/backup/configuration/syncer/rsync/pull.rb +11 -0
  33. data/lib/backup/configuration/syncer/rsync/push.rb +31 -0
  34. data/lib/backup/configuration/syncer/s3.rb +0 -4
  35. data/lib/backup/database/base.rb +25 -7
  36. data/lib/backup/database/mongodb.rb +112 -75
  37. data/lib/backup/database/mysql.rb +54 -29
  38. data/lib/backup/database/postgresql.rb +60 -42
  39. data/lib/backup/database/redis.rb +61 -39
  40. data/lib/backup/database/riak.rb +35 -11
  41. data/lib/backup/dependency.rb +4 -5
  42. data/lib/backup/encryptor/base.rb +13 -1
  43. data/lib/backup/encryptor/gpg.rb +39 -39
  44. data/lib/backup/encryptor/open_ssl.rb +28 -38
  45. data/lib/backup/logger.rb +20 -11
  46. data/lib/backup/model.rb +206 -163
  47. data/lib/backup/notifier/base.rb +27 -25
  48. data/lib/backup/notifier/campfire.rb +7 -13
  49. data/lib/backup/notifier/hipchat.rb +28 -28
  50. data/lib/backup/notifier/mail.rb +24 -26
  51. data/lib/backup/notifier/presently.rb +10 -18
  52. data/lib/backup/notifier/prowl.rb +9 -17
  53. data/lib/backup/notifier/twitter.rb +11 -18
  54. data/lib/backup/package.rb +47 -0
  55. data/lib/backup/packager.rb +81 -16
  56. data/lib/backup/splitter.rb +48 -35
  57. data/lib/backup/storage/base.rb +44 -172
  58. data/lib/backup/storage/cloudfiles.rb +31 -46
  59. data/lib/backup/storage/cycler.rb +117 -0
  60. data/lib/backup/storage/dropbox.rb +92 -76
  61. data/lib/backup/storage/ftp.rb +30 -40
  62. data/lib/backup/storage/local.rb +44 -45
  63. data/lib/backup/storage/ninefold.rb +55 -49
  64. data/lib/backup/storage/rsync.rb +49 -56
  65. data/lib/backup/storage/s3.rb +33 -44
  66. data/lib/backup/storage/scp.rb +21 -48
  67. data/lib/backup/storage/sftp.rb +26 -40
  68. data/lib/backup/syncer/base.rb +7 -0
  69. data/lib/backup/syncer/rsync/base.rb +78 -0
  70. data/lib/backup/syncer/rsync/local.rb +53 -0
  71. data/lib/backup/syncer/rsync/pull.rb +38 -0
  72. data/lib/backup/syncer/rsync/push.rb +113 -0
  73. data/lib/backup/syncer/s3.rb +42 -32
  74. data/lib/backup/version.rb +1 -1
  75. data/spec/archive_spec.rb +235 -69
  76. data/spec/cleaner_spec.rb +304 -0
  77. data/spec/cli/helpers_spec.rb +142 -1
  78. data/spec/cli/utility_spec.rb +338 -13
  79. data/spec/compressor/base_spec.rb +31 -0
  80. data/spec/compressor/bzip2_spec.rb +60 -35
  81. data/spec/compressor/gzip_spec.rb +60 -35
  82. data/spec/compressor/lzma_spec.rb +60 -35
  83. data/spec/compressor/pbzip2_spec.rb +98 -37
  84. data/spec/config_spec.rb +321 -0
  85. data/spec/configuration/base_spec.rb +4 -4
  86. data/spec/configuration/compressor/bzip2_spec.rb +1 -0
  87. data/spec/configuration/compressor/gzip_spec.rb +1 -0
  88. data/spec/configuration/compressor/lzma_spec.rb +1 -0
  89. data/spec/configuration/compressor/pbzip2_spec.rb +32 -0
  90. data/spec/configuration/database/base_spec.rb +2 -1
  91. data/spec/configuration/database/mongodb_spec.rb +26 -16
  92. data/spec/configuration/database/mysql_spec.rb +4 -0
  93. data/spec/configuration/database/postgresql_spec.rb +4 -0
  94. data/spec/configuration/database/redis_spec.rb +4 -0
  95. data/spec/configuration/database/riak_spec.rb +4 -0
  96. data/spec/configuration/encryptor/gpg_spec.rb +1 -0
  97. data/spec/configuration/encryptor/open_ssl_spec.rb +1 -0
  98. data/spec/configuration/notifier/base_spec.rb +32 -0
  99. data/spec/configuration/notifier/campfire_spec.rb +1 -0
  100. data/spec/configuration/notifier/hipchat_spec.rb +1 -0
  101. data/spec/configuration/notifier/mail_spec.rb +1 -0
  102. data/spec/configuration/notifier/presently_spec.rb +1 -0
  103. data/spec/configuration/notifier/prowl_spec.rb +1 -0
  104. data/spec/configuration/notifier/twitter_spec.rb +1 -0
  105. data/spec/configuration/storage/cloudfiles_spec.rb +1 -0
  106. data/spec/configuration/storage/dropbox_spec.rb +4 -3
  107. data/spec/configuration/storage/ftp_spec.rb +1 -0
  108. data/spec/configuration/storage/local_spec.rb +1 -0
  109. data/spec/configuration/storage/ninefold_spec.rb +1 -0
  110. data/spec/configuration/storage/rsync_spec.rb +3 -1
  111. data/spec/configuration/storage/s3_spec.rb +1 -0
  112. data/spec/configuration/storage/scp_spec.rb +1 -0
  113. data/spec/configuration/storage/sftp_spec.rb +1 -0
  114. data/spec/configuration/syncer/rsync/base_spec.rb +33 -0
  115. data/spec/configuration/syncer/rsync/local_spec.rb +10 -0
  116. data/spec/configuration/syncer/rsync/pull_spec.rb +10 -0
  117. data/spec/configuration/syncer/{rsync_spec.rb → rsync/push_spec.rb} +12 -15
  118. data/spec/configuration/syncer/s3_spec.rb +2 -3
  119. data/spec/database/base_spec.rb +35 -20
  120. data/spec/database/mongodb_spec.rb +298 -119
  121. data/spec/database/mysql_spec.rb +147 -72
  122. data/spec/database/postgresql_spec.rb +155 -100
  123. data/spec/database/redis_spec.rb +200 -97
  124. data/spec/database/riak_spec.rb +82 -24
  125. data/spec/dependency_spec.rb +49 -0
  126. data/spec/encryptor/base_spec.rb +30 -0
  127. data/spec/encryptor/gpg_spec.rb +105 -28
  128. data/spec/encryptor/open_ssl_spec.rb +85 -114
  129. data/spec/logger_spec.rb +74 -8
  130. data/spec/model_spec.rb +528 -220
  131. data/spec/notifier/base_spec.rb +89 -0
  132. data/spec/notifier/campfire_spec.rb +147 -119
  133. data/spec/notifier/hipchat_spec.rb +140 -145
  134. data/spec/notifier/mail_spec.rb +190 -248
  135. data/spec/notifier/presently_spec.rb +147 -282
  136. data/spec/notifier/prowl_spec.rb +79 -111
  137. data/spec/notifier/twitter_spec.rb +87 -106
  138. data/spec/package_spec.rb +61 -0
  139. data/spec/packager_spec.rb +154 -0
  140. data/spec/spec_helper.rb +36 -13
  141. data/spec/splitter_spec.rb +90 -41
  142. data/spec/storage/base_spec.rb +95 -239
  143. data/spec/storage/cloudfiles_spec.rb +185 -75
  144. data/spec/storage/cycler_spec.rb +239 -0
  145. data/spec/storage/dropbox_spec.rb +318 -87
  146. data/spec/storage/ftp_spec.rb +165 -152
  147. data/spec/storage/local_spec.rb +206 -54
  148. data/spec/storage/ninefold_spec.rb +264 -128
  149. data/spec/storage/rsync_spec.rb +244 -163
  150. data/spec/storage/s3_spec.rb +175 -64
  151. data/spec/storage/scp_spec.rb +156 -150
  152. data/spec/storage/sftp_spec.rb +153 -135
  153. data/spec/syncer/base_spec.rb +22 -0
  154. data/spec/syncer/rsync/base_spec.rb +118 -0
  155. data/spec/syncer/rsync/local_spec.rb +121 -0
  156. data/spec/syncer/rsync/pull_spec.rb +90 -0
  157. data/spec/syncer/rsync/push_spec.rb +327 -0
  158. data/spec/syncer/s3_spec.rb +180 -91
  159. data/templates/cli/utility/config +1 -1
  160. data/templates/cli/utility/database/mongodb +4 -0
  161. data/templates/cli/utility/database/mysql +3 -0
  162. data/templates/cli/utility/database/postgresql +3 -0
  163. data/templates/cli/utility/database/redis +3 -0
  164. data/templates/cli/utility/database/riak +3 -0
  165. data/templates/cli/utility/storage/dropbox +4 -1
  166. data/templates/cli/utility/syncer/rsync_local +12 -0
  167. data/templates/cli/utility/syncer/{rsync → rsync_pull} +2 -2
  168. data/templates/cli/utility/syncer/rsync_push +17 -0
  169. data/templates/storage/dropbox/authorization_url.erb +1 -1
  170. metadata +42 -17
  171. data/lib/backup/configuration/syncer/rsync.rb +0 -45
  172. data/lib/backup/finder.rb +0 -87
  173. data/lib/backup/storage/object.rb +0 -47
  174. data/lib/backup/syncer/rsync.rb +0 -152
  175. data/spec/backup_spec.rb +0 -11
  176. data/spec/finder_spec.rb +0 -91
  177. data/spec/storage/object_spec.rb +0 -74
  178. data/spec/syncer/rsync_spec.rb +0 -195
@@ -6,11 +6,23 @@ module Backup
6
6
  include Backup::CLI::Helpers
7
7
  include Backup::Configuration::Helpers
8
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
+
9
21
  ##
10
22
  # Logs a message to the console and log file to inform
11
- # the client that Backup is compressing the archive
23
+ # the client that Backup is using the compressor
12
24
  def log!
13
- Logger.message "#{ self.class } started compressing the archive."
25
+ Logger.message "Using #{ compressor_name } for compression."
14
26
  end
15
27
  end
16
28
  end
@@ -7,12 +7,12 @@ module Backup
7
7
  ##
8
8
  # Tells Backup::Compressor::Bzip2 to compress
9
9
  # better (-9) rather than faster when set to true
10
- attr_writer :best
10
+ attr_accessor :best
11
11
 
12
12
  ##
13
13
  # Tells Backup::Compressor::Bzip2 to compress
14
14
  # faster (-1) rather than better when set to true
15
- attr_writer :fast
15
+ attr_accessor :fast
16
16
 
17
17
  ##
18
18
  # Creates a new instance of Backup::Compressor::Bzip2 and
@@ -21,7 +21,7 @@ module Backup
21
21
  # and lower block sizes don't make things significantly faster
22
22
  # (according to official bzip2 docs)
23
23
  def initialize(&block)
24
- load_defaults!
24
+ super
25
25
 
26
26
  @best ||= false
27
27
  @fast ||= false
@@ -30,33 +30,19 @@ module Backup
30
30
  end
31
31
 
32
32
  ##
33
- # Performs the compression of the packages backup file
34
- def perform!
33
+ # Yields to the block the compressor command with options
34
+ # and it's filename extension.
35
+ def compress_with
35
36
  log!
36
- run("#{ utility(:bzip2) } #{ options } '#{ Backup::Model.file }'")
37
- Backup::Model.extension += '.bz2'
37
+ yield "#{ utility(:bzip2) }#{ options }", '.bz2'
38
38
  end
39
39
 
40
- private
40
+ private
41
41
 
42
42
  ##
43
- # Combines the provided options and returns a bzip2 options string
43
+ # Returns the option syntax for compressing
44
44
  def options
45
- (best + fast).join("\s")
46
- end
47
-
48
- ##
49
- # Returns the bzip2 option syntax for compressing
50
- # setting @best to true is redundant, as bzip2 compresses best by default
51
- def best
52
- return ['--best'] if @best; []
53
- end
54
-
55
- ##
56
- # Returns the bzip2 option syntax for compressing
57
- # (not significantly) faster when @fast is set to true
58
- def fast
59
- return ['--fast'] if @fast; []
45
+ " #{ '--best ' if @best }#{ '--fast' if @fast }".rstrip
60
46
  end
61
47
 
62
48
  end
@@ -7,18 +7,18 @@ module Backup
7
7
  ##
8
8
  # Tells Backup::Compressor::Gzip to compress
9
9
  # better rather than faster when set to true
10
- attr_writer :best
10
+ attr_accessor :best
11
11
 
12
12
  ##
13
13
  # Tells Backup::Compressor::Gzip to compress
14
14
  # faster rather than better when set to true
15
- attr_writer :fast
15
+ attr_accessor :fast
16
16
 
17
17
  ##
18
18
  # Creates a new instance of Backup::Compressor::Gzip and
19
19
  # configures it to either compress faster or better
20
20
  def initialize(&block)
21
- load_defaults!
21
+ super
22
22
 
23
23
  @best ||= false
24
24
  @fast ||= false
@@ -27,33 +27,19 @@ module Backup
27
27
  end
28
28
 
29
29
  ##
30
- # Performs the compression of the packages backup file
31
- def perform!
30
+ # Yields to the block the compressor command with options
31
+ # and it's filename extension.
32
+ def compress_with
32
33
  log!
33
- run("#{ utility(:gzip) } #{ options } '#{ Backup::Model.file }'")
34
- Backup::Model.extension += '.gz'
34
+ yield "#{ utility(:gzip) }#{ options }", '.gz'
35
35
  end
36
36
 
37
- private
38
-
39
- ##
40
- # Combines the provided options and returns a gzip options string
41
- def options
42
- (best + fast).join("\s")
43
- end
37
+ private
44
38
 
45
39
  ##
46
40
  # Returns the gzip option syntax for compressing
47
- # better when @best is set to true
48
- def best
49
- return ['--best'] if @best; []
50
- end
51
-
52
- ##
53
- # Returns the gzip option syntax for compressing
54
- # faster when @fast is set to true
55
- def fast
56
- return ['--fast'] if @fast; []
41
+ def options
42
+ " #{ '--best ' if @best }#{ '--fast' if @fast }".rstrip
57
43
  end
58
44
 
59
45
  end
@@ -7,12 +7,12 @@ module Backup
7
7
  ##
8
8
  # Tells Backup::Compressor::Lzma to compress
9
9
  # better (-9) rather than faster when set to true
10
- attr_writer :best
10
+ attr_accessor :best
11
11
 
12
12
  ##
13
13
  # Tells Backup::Compressor::Lzma to compress
14
14
  # faster (-1) rather than better when set to true
15
- attr_writer :fast
15
+ attr_accessor :fast
16
16
 
17
17
  ##
18
18
  # Creates a new instance of Backup::Compressor::Lzma and
@@ -21,7 +21,7 @@ module Backup
21
21
  # and lower block sizes don't make things significantly faster
22
22
  # (according to official bzip2 docs)
23
23
  def initialize(&block)
24
- load_defaults!
24
+ super
25
25
 
26
26
  @best ||= false
27
27
  @fast ||= false
@@ -30,34 +30,21 @@ module Backup
30
30
  end
31
31
 
32
32
  ##
33
- # Performs the compression of the packages backup file
34
- def perform!
33
+ # Yields to the block the compressor command with options
34
+ # and it's filename extension.
35
+ def compress_with
35
36
  log!
36
- run("#{ utility(:lzma) } #{ options } '#{ Backup::Model.file }'")
37
- Backup::Model.extension += '.lzma'
37
+ yield "#{ utility(:lzma) }#{ options }", '.lzma'
38
38
  end
39
39
 
40
- private
40
+ private
41
41
 
42
42
  ##
43
- # Combines the provided options and returns a bzip2 options string
43
+ # Returns the option syntax for compressing
44
44
  def options
45
- (best + fast).join("\s")
45
+ " #{ '--best ' if @best }#{ '--fast' if @fast }".rstrip
46
46
  end
47
47
 
48
- ##
49
- # Returns the lzma option syntax for compressing
50
- # setting @best to true is redundant, as lzma compresses best by default
51
- def best
52
- return ['--best'] if @best; []
53
- end
54
-
55
- ##
56
- # Returns the lzma option syntax for compressing
57
- # (not significantly) faster when @fast is set to true
58
- def fast
59
- return ['--fast'] if @fast; []
60
- end
61
48
  end
62
49
  end
63
50
  end
@@ -7,17 +7,17 @@ module Backup
7
7
  ##
8
8
  # Tells Backup::Compressor::Pbzip2 to compress
9
9
  # better (-9) rather than faster when set to true
10
- attr_writer :best
10
+ attr_accessor :best
11
11
 
12
12
  ##
13
13
  # Tells Backup::Compressor::Pbzip2 to compress
14
14
  # faster (-1) rather than better when set to true
15
- attr_writer :fast
15
+ attr_accessor :fast
16
16
 
17
17
  ##
18
18
  # Tells Backup::Compressor::Pbzip2 how many processors
19
19
  # use, by default autodetect is used
20
- attr_writer :processors
20
+ attr_accessor :processors
21
21
 
22
22
  ##
23
23
  # Creates a new instance of Backup::Compressor::Pbzip2 and
@@ -26,51 +26,31 @@ module Backup
26
26
  # and lower block sizes don't make things significantly faster
27
27
  # (according to official bzip2 docs)
28
28
  def initialize(&block)
29
- load_defaults!
29
+ super
30
30
 
31
31
  @best ||= false
32
32
  @fast ||= false
33
- @processors ||= nil
33
+ @processors ||= false
34
34
 
35
35
  instance_eval(&block) if block_given?
36
36
  end
37
37
 
38
38
  ##
39
- # Performs the compression of the packages backup file
40
- def perform!
39
+ # Yields to the block the compressor command with options
40
+ # and it's filename extension.
41
+ def compress_with
41
42
  log!
42
- run("#{ utility(:pbzip2) } #{ options } '#{ Backup::Model.file }'")
43
- Backup::Model.extension += '.bz2'
43
+ yield "#{ utility(:pbzip2) }#{ options }", '.bz2'
44
44
  end
45
45
 
46
- private
46
+ private
47
47
 
48
48
  ##
49
- # Combines the provided options and returns a pbzip2 options string
49
+ # Returns the gzip option syntax for compressing
50
50
  def options
51
- (best + fast + processors).join("\s")
51
+ " #{ '--best ' if @best }#{ '--fast ' if @fast }#{ "-p#{@processors}" if @processors }".rstrip
52
52
  end
53
53
 
54
- ##
55
- # Returns the pbzip2 option syntax for compressing
56
- # setting @best to true is redundant, as pbzip2 compresses best by default
57
- def best
58
- return ['--best'] if @best; []
59
- end
60
-
61
- ##
62
- # Returns the pbzip2 option syntax for compressing
63
- # (not significantly) faster when @fast is set to true
64
- def fast
65
- return ['--fast'] if @fast; []
66
- end
67
-
68
- ##
69
- # Returns the pbzip2 option syntax for compressing
70
- # using given count of cpus
71
- def processors
72
- return ['-p' + @processors.to_s] if @processors; []
73
- end
74
54
  end
75
55
  end
76
56
  end
@@ -0,0 +1,171 @@
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
+ # Syncers
114
+ ['S3', { 'RSync' => ['Push', 'Pull', 'Local'] }],
115
+ # Notifiers
116
+ ['Mail', 'Twitter', 'Campfire', 'Presently', 'Prowl', 'Hipchat']
117
+ ]
118
+ )
119
+ end
120
+
121
+ def create_modules(scope, names)
122
+ names.flatten.each do |name|
123
+ if name.is_a?(Hash)
124
+ name.each do |key, val|
125
+ create_modules(get_or_create_empty_module(scope, key), [val])
126
+ end
127
+ else
128
+ get_or_create_empty_module(scope, name)
129
+ end
130
+ end
131
+ end
132
+
133
+ def get_or_create_empty_module(scope, const)
134
+ if scope.const_defined?(const)
135
+ scope.const_get(const)
136
+ else
137
+ scope.const_set(const, Module.new)
138
+ end
139
+ end
140
+ end
141
+
142
+ ##
143
+ # Add the DSL constants and set default values for accessors when loaded.
144
+ add_dsl_constants!
145
+ reset!
146
+ end
147
+
148
+ ##
149
+ # Warn user of deprecated Backup::CONFIG_FILE constant reference
150
+ # in older config.rb files and return the proper Config.config_file value.
151
+ class << self
152
+ def const_missing(const)
153
+ if const.to_s == 'CONFIG_FILE'
154
+ Logger.warn Errors::ConfigError.new(<<-EOS)
155
+ Configuration File Upgrade Needed
156
+ Your configuration file, located at #{ Config.config_file }
157
+ needs to be upgraded for this version of Backup.
158
+ The reference to 'Backup::CONFIG_FILE' in your current config.rb file
159
+ has been deprecated and needs to be replaced with 'Config.config_file'.
160
+ You may update this reference in your config.rb manually,
161
+ or generate a new config.rb using 'backup generate:config'.
162
+ * Note: if you have global configuration defaults set in config.rb,
163
+ be sure to transfer them to your new config.rb, should you choose
164
+ to generate a new config.rb file.
165
+ EOS
166
+ return Config.config_file
167
+ end
168
+ super
169
+ end
170
+ end
171
+ end