backup 3.11.0 → 4.0.0rc1

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 (90) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +4 -4
  3. data/lib/backup.rb +1 -4
  4. data/lib/backup/archive.rb +1 -1
  5. data/lib/backup/cli.rb +51 -107
  6. data/lib/backup/compressor/base.rb +2 -2
  7. data/lib/backup/compressor/bzip2.rb +0 -11
  8. data/lib/backup/compressor/gzip.rb +0 -11
  9. data/lib/backup/config.rb +45 -123
  10. data/lib/backup/config/dsl.rb +102 -0
  11. data/lib/backup/{configuration → config}/helpers.rb +23 -14
  12. data/lib/backup/database/base.rb +2 -2
  13. data/lib/backup/database/mongodb.rb +0 -18
  14. data/lib/backup/database/mysql.rb +6 -75
  15. data/lib/backup/database/postgresql.rb +0 -12
  16. data/lib/backup/database/redis.rb +85 -47
  17. data/lib/backup/database/riak.rb +0 -19
  18. data/lib/backup/encryptor/base.rb +2 -2
  19. data/lib/backup/encryptor/gpg.rb +1 -12
  20. data/lib/backup/logger/fog_adapter.rb +1 -2
  21. data/lib/backup/model.rb +3 -24
  22. data/lib/backup/notifier/base.rb +2 -17
  23. data/lib/backup/notifier/http_post.rb +1 -1
  24. data/lib/backup/notifier/mail.rb +5 -47
  25. data/lib/backup/notifier/prowl.rb +1 -1
  26. data/lib/backup/notifier/pushover.rb +1 -1
  27. data/lib/backup/packager.rb +1 -1
  28. data/lib/backup/pipeline.rb +1 -1
  29. data/lib/backup/splitter.rb +1 -1
  30. data/lib/backup/storage/base.rb +2 -14
  31. data/lib/backup/storage/cloud_files.rb +1 -0
  32. data/lib/backup/storage/cycler.rb +33 -88
  33. data/lib/backup/storage/dropbox.rb +19 -12
  34. data/lib/backup/storage/ftp.rb +1 -0
  35. data/lib/backup/storage/local.rb +1 -0
  36. data/lib/backup/storage/ninefold.rb +1 -0
  37. data/lib/backup/storage/rsync.rb +7 -41
  38. data/lib/backup/storage/s3.rb +1 -0
  39. data/lib/backup/storage/scp.rb +1 -0
  40. data/lib/backup/storage/sftp.rb +1 -0
  41. data/lib/backup/syncer/base.rb +2 -2
  42. data/lib/backup/syncer/cloud/cloud_files.rb +0 -16
  43. data/lib/backup/syncer/cloud/s3.rb +0 -16
  44. data/lib/backup/syncer/rsync/local.rb +0 -5
  45. data/lib/backup/syncer/rsync/pull.rb +0 -21
  46. data/lib/backup/syncer/rsync/push.rb +0 -21
  47. data/lib/backup/utilities.rb +2 -22
  48. data/lib/backup/version.rb +1 -1
  49. data/templates/cli/archive +0 -3
  50. data/templates/cli/compressor/custom +0 -4
  51. data/templates/cli/config +39 -17
  52. data/templates/cli/{database → databases}/mongodb +0 -0
  53. data/templates/cli/{database → databases}/mysql +0 -0
  54. data/templates/cli/{database → databases}/postgresql +0 -0
  55. data/templates/cli/databases/redis +16 -0
  56. data/templates/cli/{database → databases}/riak +0 -0
  57. data/templates/cli/{model.erb → model} +8 -5
  58. data/templates/cli/{notifier → notifiers}/campfire +0 -0
  59. data/templates/cli/{notifier → notifiers}/hipchat +0 -0
  60. data/templates/cli/{notifier → notifiers}/http_post +0 -3
  61. data/templates/cli/{notifier → notifiers}/mail +1 -2
  62. data/templates/cli/notifiers/nagios +13 -0
  63. data/templates/cli/{notifier → notifiers}/prowl +0 -0
  64. data/templates/cli/{notifier → notifiers}/pushover +0 -0
  65. data/templates/cli/{notifier → notifiers}/twitter +0 -0
  66. data/templates/cli/{storage → storages}/cloud_files +0 -2
  67. data/templates/cli/storages/dropbox +19 -0
  68. data/templates/cli/{storage → storages}/ftp +0 -0
  69. data/templates/cli/{storage → storages}/local +0 -0
  70. data/templates/cli/{storage → storages}/ninefold +0 -0
  71. data/templates/cli/{storage → storages}/rsync +0 -2
  72. data/templates/cli/{storage → storages}/s3 +0 -2
  73. data/templates/cli/{storage → storages}/scp +0 -0
  74. data/templates/cli/{storage → storages}/sftp +0 -0
  75. data/templates/cli/{syncer → syncers}/cloud_files +0 -2
  76. data/templates/cli/{syncer → syncers}/rsync_local +0 -0
  77. data/templates/cli/{syncer → syncers}/rsync_pull +0 -2
  78. data/templates/cli/{syncer → syncers}/rsync_push +0 -2
  79. data/templates/cli/{syncer → syncers}/s3 +0 -2
  80. data/templates/general/links +1 -1
  81. metadata +241 -69
  82. data/lib/backup/compressor/lzma.rb +0 -52
  83. data/lib/backup/compressor/pbzip2.rb +0 -59
  84. data/lib/backup/configuration.rb +0 -33
  85. data/lib/backup/configuration/store.rb +0 -24
  86. data/templates/cli/compressor/lzma +0 -10
  87. data/templates/cli/compressor/pbzip2 +0 -10
  88. data/templates/cli/database/redis +0 -18
  89. data/templates/cli/notifier/nagios +0 -13
  90. data/templates/cli/storage/dropbox +0 -20
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 90a0ce4d50fcbf5dbc1ff35c6ceb182757b5b1ca
4
- data.tar.gz: e6cd5b21bed38cd91d97dad2489d38107e33a387
3
+ metadata.gz: d0de2d8ea6ab6e4fe90e28b7044b2fcf35d615ca
4
+ data.tar.gz: 0f484316e417073db7987f67a46b283e4cd90ab9
5
5
  SHA512:
6
- metadata.gz: dfec691ea4ad54ed847451247fbc26d8f476360075becea60416249a22805740284c18c5d5e6e16333dfa344402dd607feaf0d9b147b1763ff3ad580051d165c
7
- data.tar.gz: d0b6389c651ef00d14833b03830864b90e1c71cdae7dbc17bb6f308d58c4b03c68c716e32c58048a24e442a1ddfcd9087ec801a2b827a9632bdeb18af6965d75
6
+ metadata.gz: 76b53d8880bfdfd5d292f1ef42ee7c55abd25d548332c9b22e2006b7e1e56c1982986ad4caab35130949d67c73435351199a46c8fbfec7ffebea651df5fdfff2
7
+ data.tar.gz: 8ae5bc1f0bd537aad0eef034da5c0ebe65fd87a7ff8cc2e7963a07eb93c5b7715823d23d96338892ffe4895d6d2376c326487716bb96a2541da78ce59ae87603
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- Backup v3.x
1
+ Backup v4.x
2
2
  ===========
3
3
 
4
4
  Backup is a system utility for Linux and Mac OS X, distributed as a RubyGem, that allows you to easily perform backup
@@ -12,8 +12,8 @@ was built with modularity, extensibility and simplicity in mind.
12
12
  **Copyright (c) 2009-2014 [Michael van Rooijen][] ( [@meskyanichi][] )**
13
13
  Released under the **MIT** [License](LICENSE.md).
14
14
 
15
- [Installation]: http://meskyanichi.github.io/backup/v3/installation
16
- [Release Notes]: http://meskyanichi.github.io/backup/v3/release-notes
17
- [Documentation]: http://meskyanichi.github.io/backup/v3
15
+ [Installation]: http://meskyanichi.github.io/backup/v4/installation
16
+ [Release Notes]: http://meskyanichi.github.io/backup/v4/release-notes
17
+ [Documentation]: http://meskyanichi.github.io/backup/v4
18
18
  [Michael van Rooijen]: http://michaelvanrooijen.com
19
19
  [@meskyanichi]: http://twitter.com/#!/meskyanichi
data/lib/backup.rb CHANGED
@@ -85,8 +85,6 @@ module Backup
85
85
  autoload :Gzip, File.join(COMPRESSOR_PATH, 'gzip')
86
86
  autoload :Bzip2, File.join(COMPRESSOR_PATH, 'bzip2')
87
87
  autoload :Custom, File.join(COMPRESSOR_PATH, 'custom')
88
- autoload :Pbzip2, File.join(COMPRESSOR_PATH, 'pbzip2')
89
- autoload :Lzma, File.join(COMPRESSOR_PATH, 'lzma')
90
88
  end
91
89
 
92
90
  ##
@@ -120,10 +118,9 @@ module Backup
120
118
  archive
121
119
  binder
122
120
  cleaner
121
+ model
123
122
  config
124
123
  cli
125
- configuration
126
- model
127
124
  package
128
125
  packager
129
126
  pipeline
@@ -4,7 +4,7 @@ module Backup
4
4
  class Archive
5
5
  class Error < Backup::Error; end
6
6
 
7
- include Backup::Utilities::Helpers
7
+ include Utilities::Helpers
8
8
  attr_reader :name, :options
9
9
 
10
10
  ##
data/lib/backup/cli.rb CHANGED
@@ -11,8 +11,8 @@ module Backup
11
11
  # [Perform]
12
12
  #
13
13
  # The only required option is the --trigger [-t].
14
- # If --config-file, --data-path, --cache-path, --tmp-path aren't specified
15
- # they will fallback to defaults defined in Backup::Config.
14
+ # If --config-file, --data-path, --tmp-path or --log-path
15
+ # aren't specified they will fallback to defaults.
16
16
  # If --root-path is given, it will be used as the base path for our defaults,
17
17
  # as well as the base path for any option specified as a relative path.
18
18
  # Any option given as an absolute path will be used "as-is".
@@ -41,8 +41,8 @@ module Backup
41
41
 
42
42
  To use the current directory, use: `--root-path .`
43
43
 
44
- Relative paths given for --config-file, --data-path, --log-path,
45
- --cache-path and --tmp-path will be relative to --root-path.
44
+ Relative paths given for --config-file, --data-path, --tmp-path,
45
+ and --log-path will be relative to --root-path.
46
46
 
47
47
  Console log output may be forced using --no-quiet.
48
48
 
@@ -80,11 +80,6 @@ module Backup
80
80
  :default => '',
81
81
  :desc => "Path to store Backup's log file."
82
82
 
83
- method_option :cache_path,
84
- :type => :string,
85
- :default => '',
86
- :desc => "Path to store Dropbox's cached authorization."
87
-
88
83
  method_option :tmp_path,
89
84
  :type => :string,
90
85
  :default => '',
@@ -130,13 +125,8 @@ module Backup
130
125
  syslog.enabled = opts[:syslog]
131
126
  end
132
127
 
133
- # Update Config variables
134
- # (config_file, root_path, data_path, cache_path, tmp_path)
135
- Config.update(options)
136
-
137
- # Load the user's +config.rb+ file (and all their Models).
138
- # May update Logger (and Config) options.
139
- Config.load_config!
128
+ # Load the user's +config.rb+ file and all their Models
129
+ Config.load(options)
140
130
 
141
131
  # Identify all Models to be run for the given +triggers+.
142
132
  triggers = options[:trigger].split(',').map(&:strip)
@@ -226,8 +216,7 @@ module Backup
226
216
 
227
217
  def check
228
218
  begin
229
- Config.update(options)
230
- Config.load_config!
219
+ Config.load(options)
231
220
  rescue Exception => err
232
221
  Logger.error Error.wrap(err)
233
222
  end
@@ -255,13 +244,15 @@ module Backup
255
244
  long_desc <<-EOS.gsub(/^ +/, '')
256
245
  Generates a Backup model file.
257
246
 
258
- '--config-path' is the path to the *directory* where 'config.rb' is located.
247
+ If your configuration file is not in the default location at
248
+ #{ Config.config_file }
249
+ you must specify it's location using '--config-file'.
250
+ If no configuration file exists at this location, one will be created.
259
251
 
260
252
  The model file will be created as '<config_path>/models/<trigger>.rb'
261
-
262
- The default location would be:
263
-
264
- #{ Config.root_path }/models/
253
+ Your model file will be created in a 'models/' sub-directory
254
+ where your config file is located. The default location would be:
255
+ #{ Config.root_path }/models/<trigger>.rb
265
256
  EOS
266
257
 
267
258
  method_option :trigger,
@@ -270,120 +261,73 @@ module Backup
270
261
  :type => :string,
271
262
  :desc => 'Trigger name for the Backup model'
272
263
 
273
- method_option :config_path,
264
+ method_option :config_file,
274
265
  :type => :string,
275
- :desc => 'Path to your Backup configuration directory'
266
+ :desc => 'Path to your Backup configuration file'
276
267
 
277
268
  # options with their available values
278
- %w{ databases storages syncers
279
- encryptors compressors notifiers }.map(&:to_sym).each do |name|
280
- path = File.join(Backup::TEMPLATE_PATH, 'cli', name.to_s[0..-2])
281
- method_option name, :type => :string, :desc =>
282
- "(#{Dir[path + '/*'].sort.map {|p| File.basename(p) }.join(', ')})"
269
+ %w{ databases storages syncers encryptor compressor notifiers }.each do |name|
270
+ path = File.join(Backup::TEMPLATE_PATH, 'cli', name)
271
+ opts = Dir[path + '/*'].sort.map {|p| File.basename(p) }.join(', ')
272
+ method_option name, :type => :string, :desc => "(#{ opts })"
283
273
  end
284
274
 
285
275
  method_option :archives,
286
276
  :type => :boolean,
287
277
  :desc => 'Model will include tar archives.'
278
+
288
279
  method_option :splitter,
289
280
  :type => :boolean,
290
- :default => true,
291
- :desc => "Use `--no-splitter` to disable"
292
-
293
- define_method "generate:model" do
294
- opts = options.merge(
295
- :trigger => options[:trigger].gsub(/\W/, '_'),
296
- :config_path => options[:config_path] ?
297
- File.expand_path(options[:config_path]) : nil
298
- )
299
- config_path = opts[:config_path] || Config.root_path
300
- models_path = File.join(config_path, "models")
301
- config = File.join(config_path, "config.rb")
302
- model = File.join(models_path, "#{opts[:trigger]}.rb")
303
-
304
- if File.file?(config_path)
305
- abort('--config-path should be a directory, not a file.')
306
- end
281
+ :default => false,
282
+ :desc => 'Add Splitter to the model'
307
283
 
308
- FileUtils.mkdir_p(models_path)
309
- if Helpers.overwrite?(model)
310
- File.open(model, 'w') do |file|
311
- file.write(
312
- Backup::Template.new({:options => opts}).result("cli/model.erb")
313
- )
314
- end
315
- puts "Generated model file: '#{ model }'."
284
+ define_method 'generate:model' do
285
+ opts = options.merge(:trigger => options[:trigger].gsub(/\W/, '_'))
286
+ config_file = opts[:config_file] ?
287
+ File.expand_path(opts.delete(:config_file)) : Config.config_file
288
+ models_path = File.join(File.dirname(config_file), 'models')
289
+ model_file = File.join(models_path, "#{ opts[:trigger] }.rb")
290
+
291
+ unless File.exist?(config_file)
292
+ invoke 'generate:config', [], :config_file => config_file
316
293
  end
317
294
 
318
- unless File.exist?(config)
319
- File.open(config, "w") do |file|
320
- file.write(Backup::Template.new.result("cli/config"))
295
+ FileUtils.mkdir_p(models_path)
296
+ if Helpers.overwrite?(model_file)
297
+ File.open(model_file, 'w') do |file|
298
+ file.write(Backup::Template.new({:options => opts}).result('cli/model'))
321
299
  end
322
- puts "Generated configuration file: '#{ config }'."
300
+ puts "Generated model file: '#{ model_file }'."
323
301
  end
324
302
  end
325
303
 
326
304
  ##
327
305
  # [Generate:Config]
328
306
  # Generates the main configuration file
329
- desc 'generate:config', 'Generates the main Backup bootstrap/configuration file'
307
+ desc 'generate:config', 'Generates the main Backup configuration file'
330
308
 
331
309
  long_desc <<-EOS.gsub(/^ +/, '')
332
- Path to your Backup configuration directory.
310
+ Path to the Backup configuration file to generate.
333
311
 
334
- Default path would be:
312
+ Defaults to:
335
313
 
336
- #{ Config.root_path }
314
+ #{ Config.config_file }
337
315
  EOS
338
316
 
339
- method_option :config_path,
317
+ method_option :config_file,
340
318
  :type => :string,
341
- :desc => 'Path to your Backup configuration directory.'
319
+ :desc => 'Path to the Backup configuration file to generate.'
342
320
 
343
321
  define_method 'generate:config' do
344
- config_path = options[:config_path] ?
345
- File.expand_path(options[:config_path]) : Config.root_path
346
- config = File.join(config_path, "config.rb")
347
-
348
- FileUtils.mkdir_p(config_path)
349
- if Helpers.overwrite?(config)
350
- File.open(config, "w") do |file|
351
- file.write(Backup::Template.new.result("cli/config"))
352
- end
353
- puts "Generated configuration file: '#{ config }'."
354
- end
355
- end
322
+ config_file = options[:config_file] ?
323
+ File.expand_path(options[:config_file]) : Config.config_file
356
324
 
357
- ##
358
- # [Decrypt]
359
- # Shorthand for decrypting encrypted files
360
- desc 'decrypt', 'Decrypts encrypted files'
361
- method_option :encryptor, :type => :string, :required => true
362
- method_option :in, :type => :string, :required => true
363
- method_option :out, :type => :string, :required => true
364
- method_option :base64, :type => :boolean, :default => false
365
- method_option :password_file, :type => :string, :default => ''
366
- method_option :salt, :type => :boolean, :default => false
367
-
368
- def decrypt
369
- case options[:encryptor].downcase
370
- when 'openssl'
371
- base64 = options[:base64] ? '-base64' : ''
372
- password = options[:password_file].empty? ? '' :
373
- "-pass file:#{ options[:password_file] }"
374
- salt = options[:salt] ? '-salt' : ''
375
-
376
- Helpers.exec!(
377
- "openssl aes-256-cbc -d #{ base64 } #{ password } #{ salt } " +
378
- "-in '#{ options[:in] }' -out '#{ options[:out] }'"
379
- )
380
- when 'gpg'
381
- Helpers.exec!(
382
- "gpg -o '#{ options[:out] }' -d '#{ options[:in] }'"
383
- )
384
- else
385
- puts "Unknown encryptor: #{ options[:encryptor] }"
386
- puts "Use either 'openssl' or 'gpg'."
325
+ FileUtils.mkdir_p(File.dirname(config_file))
326
+ if Helpers.overwrite?(config_file)
327
+ File.open(config_file, 'w') do |file|
328
+ file.write(Backup::Template.new.result('cli/config'))
329
+ end
330
+ puts "Generated configuration file: '#{ config_file }'."
387
331
  end
388
332
  end
389
333
 
@@ -3,8 +3,8 @@
3
3
  module Backup
4
4
  module Compressor
5
5
  class Base
6
- include Backup::Utilities::Helpers
7
- include Backup::Configuration::Helpers
6
+ include Utilities::Helpers
7
+ include Config::Helpers
8
8
 
9
9
  ##
10
10
  # Yields to the block the compressor command and filename extension.
@@ -15,17 +15,6 @@ module Backup
15
15
  # The default `level` is 9.
16
16
  attr_accessor :level
17
17
 
18
- attr_deprecate :fast, :version => '3.0.24',
19
- :message => 'Use Bzip2#level instead.',
20
- :action => lambda {|klass, val|
21
- klass.level = 1 if val
22
- }
23
- attr_deprecate :best, :version => '3.0.24',
24
- :message => 'Use Bzip2#level instead.',
25
- :action => lambda {|klass, val|
26
- klass.level = 9 if val
27
- }
28
-
29
18
  ##
30
19
  # Creates a new instance of Backup::Compressor::Bzip2
31
20
  def initialize(&block)
@@ -17,17 +17,6 @@ module Backup
17
17
  # The default `level` is 6.
18
18
  attr_accessor :level
19
19
 
20
- attr_deprecate :fast, :version => '3.0.24',
21
- :message => 'Use Gzip#level instead.',
22
- :action => lambda {|klass, val|
23
- klass.level = 1 if val
24
- }
25
- attr_deprecate :best, :version => '3.0.24',
26
- :message => 'Use Gzip#level instead.',
27
- :action => lambda {|klass, val|
28
- klass.level = 9 if val
29
- }
30
-
31
20
  ##
32
21
  # Use the `--rsyncable` option with `gzip`.
33
22
  #
data/lib/backup/config.rb CHANGED
@@ -1,4 +1,6 @@
1
1
  # encoding: utf-8
2
+ require 'backup/config/dsl'
3
+ require 'backup/config/helpers'
2
4
 
3
5
  module Backup
4
6
  module Config
@@ -6,52 +8,45 @@ module Backup
6
8
 
7
9
  DEFAULTS = {
8
10
  :config_file => 'config.rb',
9
- :data_path => 'data',
10
- :cache_path => '.cache',
11
+ :data_path => '.data',
11
12
  :tmp_path => '.tmp'
12
13
  }
13
14
 
14
15
  class << self
15
- include Backup::Utilities::Helpers
16
+ include Utilities::Helpers
16
17
 
17
- attr_reader :user, :root_path, :config_file,
18
- :data_path, :cache_path, :tmp_path
18
+ attr_reader :user, :root_path, :config_file, :data_path, :tmp_path
19
19
 
20
- ##
21
- # Setup required paths based on the given options
22
- def update(options = {})
23
- root_path = options[:root_path].to_s.strip
24
- new_root = root_path.empty? ? false : set_root_path(root_path)
20
+ # Loads the user's +config.rb+ and all model files.
21
+ def load(options = {})
22
+ update(options) # from the command line
25
23
 
26
- DEFAULTS.each do |name, ending|
27
- set_path_variable(name, options[name], ending, new_root)
24
+ unless File.exist?(config_file)
25
+ raise Error, "Could not find configuration file: '#{config_file}'."
28
26
  end
29
- end
30
27
 
31
- ##
32
- # Tries to find and load the configuration file
33
- def load_config!
34
- unless File.exist?(@config_file)
35
- raise Error, "Could not find configuration file: '#{@config_file}'."
28
+ config = File.read(config_file)
29
+ version = Backup::VERSION.split('.').first
30
+ unless config =~ /^# Backup v#{ version }\.x Configuration$/
31
+ raise Error, <<-EOS
32
+ Invalid Configuration File
33
+ The configuration file at '#{ config_file }'
34
+ does not appear to be a Backup v#{ version }.x configuration file.
35
+ If you have upgraded to v#{ version }.x from a previous version,
36
+ you need to upgrade your configuration file.
37
+ Please see the instructions for upgrading in the Backup documentation.
38
+ EOS
36
39
  end
37
40
 
38
- module_eval(File.read(@config_file), @config_file)
39
- end
41
+ dsl = DSL.new
42
+ dsl.instance_eval(config, config_file)
40
43
 
41
- # Allows users to create preconfigured models.
42
- def preconfigure(name, &block)
43
- unless name.is_a?(String) && name =~ /^[A-Z]/
44
- raise Error, "Preconfigured model names must be given as a string " +
45
- " and start with a capital letter."
46
- end
44
+ update(dsl._config_options) # from config.rb
45
+ update(options) # command line takes precedence
47
46
 
48
- if Backup.const_defined?(name)
49
- raise Error, "'#{ name }' is already in use " +
50
- "and can not be used for a preconfigured model."
47
+ Dir[File.join(File.dirname(config_file), 'models', '*.rb')].each do |model|
48
+ dsl.instance_eval(File.read(model), model)
51
49
  end
52
-
53
- Backup.const_set(name, Class.new(Model))
54
- Backup.const_get(name).preconfigure(&block)
55
50
  end
56
51
 
57
52
  def hostname
@@ -60,7 +55,17 @@ module Backup
60
55
 
61
56
  private
62
57
 
63
- ##
58
+ # If :root_path is set in the options, all paths will be updated.
59
+ # Otherwise, only the paths given will be updated.
60
+ def update(options = {})
61
+ root_path = options[:root_path].to_s.strip
62
+ new_root = root_path.empty? ? false : set_root_path(root_path)
63
+
64
+ DEFAULTS.each do |name, ending|
65
+ set_path_variable(name, options[name], ending, new_root)
66
+ end
67
+ end
68
+
64
69
  # Sets the @root_path to the given +path+ and returns it.
65
70
  # Raises an error if the given +path+ does not exist.
66
71
  def set_root_path(path)
@@ -85,9 +90,15 @@ module Backup
85
90
  # an absolute path, so we can match it against File.expand_path()
86
91
  path = path.to_s.sub(/\/\s*$/, '').lstrip
87
92
  new_path = false
93
+ # If no path is given, the variable will not be set/updated
94
+ # unless a root_path was given. In which case the value will
95
+ # be updated with our default ending.
88
96
  if path.empty?
89
97
  new_path = File.join(root_path, ending) if root_path
90
98
  else
99
+ # When a path is given, the variable will be set/updated.
100
+ # If the path is relative, it will be joined with root_path (if given),
101
+ # or expanded relative to PWD.
91
102
  new_path = File.expand_path(path)
92
103
  unless path == new_path
93
104
  new_path = File.join(root_path, path) if root_path
@@ -96,102 +107,13 @@ module Backup
96
107
  instance_variable_set(:"@#{name}", new_path) if new_path
97
108
  end
98
109
 
99
- ##
100
- # Set default values for accessors
101
110
  def reset!
102
111
  @user = ENV['USER'] || Etc.getpwuid.name
103
112
  @root_path = File.join(File.expand_path(ENV['HOME'] || ''), 'Backup')
104
113
  update(:root_path => @root_path)
105
114
  end
106
-
107
- ##
108
- # List the available database, storage, syncer, compressor, encryptor
109
- # and notifier constants. These are used to dynamically define these
110
- # constant names inside Backup::Config to provide a nicer configuration
111
- # file DSL syntax to the users. Adding existing constants to the arrays
112
- # below will enable the user to use a constant instead of a string.
113
- # Nested namespaces are represented using Hashs. Deep nesting supported.
114
- #
115
- # Example, instead of:
116
- # database "MySQL" do |mysql|
117
- # sync_with "RSync::Local" do |rsync|
118
- #
119
- # You can do:
120
- # database MySQL do |mysql|
121
- # sync_with RSync::Local do |rsync|
122
- #
123
- def add_dsl_constants!
124
- create_modules(
125
- self,
126
- [ # Databases
127
- ['MySQL', 'PostgreSQL', 'MongoDB', 'Redis', 'Riak'],
128
- # Storages
129
- ['S3', 'CloudFiles', 'Ninefold', 'Dropbox', 'FTP',
130
- 'SFTP', 'SCP', 'RSync', 'Local'],
131
- # Compressors
132
- ['Gzip', 'Bzip2', 'Custom', 'Pbzip2', 'Lzma'],
133
- # Encryptors
134
- ['OpenSSL', 'GPG'],
135
- # Syncers
136
- [
137
- { 'Cloud' => ['CloudFiles', 'S3'] },
138
- { 'RSync' => ['Push', 'Pull', 'Local'] }
139
- ],
140
- # Notifiers
141
- ['Mail', 'Twitter', 'Campfire', 'Prowl',
142
- 'Hipchat', 'Pushover', 'HttpPost', 'Nagios']
143
- ]
144
- )
145
- end
146
-
147
- def create_modules(scope, names)
148
- names.flatten.each do |name|
149
- if name.is_a?(Hash)
150
- name.each do |key, val|
151
- create_modules(get_or_create_empty_module(scope, key), [val])
152
- end
153
- else
154
- get_or_create_empty_module(scope, name)
155
- end
156
- end
157
- end
158
-
159
- def get_or_create_empty_module(scope, const)
160
- if scope.const_defined?(const)
161
- scope.const_get(const)
162
- else
163
- scope.const_set(const, Module.new)
164
- end
165
- end
166
115
  end
167
116
 
168
- ##
169
- # Add the DSL constants and set default values for accessors when loaded.
170
- add_dsl_constants!
171
- reset!
172
- end
173
-
174
- ##
175
- # Warn user of deprecated Backup::CONFIG_FILE constant reference
176
- # in older config.rb files and return the proper Config.config_file value.
177
- class << self
178
- def const_missing(const)
179
- if const.to_s == 'CONFIG_FILE'
180
- Logger.warn Error.new(<<-EOS)
181
- Configuration File Upgrade Needed
182
- Your configuration file, located at #{ Config.config_file }
183
- needs to be upgraded for this version of Backup.
184
- The reference to 'Backup::CONFIG_FILE' in your current config.rb file
185
- has been deprecated and needs to be replaced with 'Config.config_file'.
186
- You may update this reference in your config.rb manually,
187
- or generate a new config.rb using 'backup generate:config'.
188
- * Note: if you have global configuration defaults set in config.rb,
189
- be sure to transfer them to your new config.rb, should you choose
190
- to generate a new config.rb file.
191
- EOS
192
- return Config.config_file
193
- end
194
- super
195
- end
117
+ reset! # set defaults on load
196
118
  end
197
119
  end