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
@@ -1,36 +1,121 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module Backup
4
- class Cleaner
5
- include Backup::CLI::Helpers
4
+ module Cleaner
5
+ class << self
6
6
 
7
- ##
8
- # Holds an instance of the current Backup model
9
- attr_accessor :model
7
+ ##
8
+ # Logs warnings if any temporary files still exist
9
+ # from the last time this model/trigger was run,
10
+ # then removes the files.
11
+ def prepare(model)
12
+ @model = model
10
13
 
11
- ##
12
- # Creates a new instance of Backup::Cleaner
13
- def initialize(model)
14
- @model = model
15
- end
14
+ messages = []
15
+ if packaging_folder_dirty?
16
+ messages << <<-EOS
17
+ The temporary backup folder still contains files!
18
+ '#{ File.join(Config.tmp_path, @model.trigger) }'
19
+ These files will now be removed.
20
+ EOS
21
+ FileUtils.rm_rf(File.join(Config.tmp_path, @model.trigger))
22
+ end
16
23
 
17
- ##
18
- # Runs the cleaner object which removes all the tmp files generated by Backup
19
- def clean!
20
- Logger.message "#{self.class} started cleaning up the temporary files."
21
- run("#{ utility(:rm) } -rf #{ paths.map { |path| "'#{ path }'" }.join(" ") }")
22
- end
24
+ package_files = tmp_path_package_files
25
+ unless package_files.empty?
26
+ # the chances that tmp_path would be dirty
27
+ # AND package files exist are practically nil
28
+ messages << ('-' * 74) unless messages.empty?
29
+
30
+ messages << <<-EOS
31
+ The temporary backup folder '#{ Config.tmp_path }'
32
+ appears to contain the package files from the previous backup!
33
+ #{ package_files.join("\n") }
34
+ These files will now be removed.
35
+ EOS
36
+ package_files.each {|file| FileUtils.rm_f(file) }
37
+ end
38
+
39
+ unless messages.empty?
40
+ Logger.warn Errors::CleanerError.new(<<-EOS)
41
+ Cleanup Warning
42
+ #{ messages.join("\n") }
43
+ Please check the log for messages and/or your notifications
44
+ concerning this backup: '#{ @model.label } (#{ @model.trigger })'
45
+ The temporary files which had to be removed should not have existed.
46
+ EOS
47
+ end
48
+ end
49
+
50
+ ##
51
+ # Remove the temporary folder used during packaging
52
+ def remove_packaging(model)
53
+ Logger.message "Cleaning up the temporary files..."
54
+ FileUtils.rm_rf(File.join(Config.tmp_path, model.trigger))
55
+ end
56
+
57
+ ##
58
+ # Remove the final package files from tmp_path
59
+ # Note: 'force' is used, since a Local Storage may *move* these files.
60
+ def remove_package(package)
61
+ Logger.message "Cleaning up the package files..."
62
+ package.filenames.each do |file|
63
+ FileUtils.rm_f(File.join(Config.tmp_path, file))
64
+ end
65
+ end
66
+
67
+ ##
68
+ # Logs warnings if any temporary files still exist
69
+ # when errors occur during the backup
70
+ def warnings(model)
71
+ @model = model
72
+
73
+ messages = []
74
+ if packaging_folder_dirty?
75
+ messages << <<-EOS
76
+ The temporary backup folder still contains files!
77
+ '#{ File.join(Config.tmp_path, @model.trigger) }'
78
+ This folder may contain completed Archives and/or Database backups.
79
+ EOS
80
+ end
81
+
82
+ package_files = tmp_path_package_files
83
+ unless package_files.empty?
84
+ # the chances that tmp_path would be dirty
85
+ # AND package files exist are practically nil
86
+ messages << ('-' * 74) unless messages.empty?
87
+
88
+ messages << <<-EOS
89
+ The temporary backup folder '#{ Config.tmp_path }'
90
+ appears to contain the backup files which were to be stored:
91
+ #{ package_files.join("\n") }
92
+ EOS
93
+ end
94
+
95
+ unless messages.empty?
96
+ Logger.warn Errors::CleanerError.new(<<-EOS)
97
+ Cleanup Warning
98
+ #{ messages.join("\n") }
99
+ Make sure you check these files before the next scheduled backup for
100
+ '#{ @model.label } (#{ @model.trigger })'
101
+ These files will be removed at that time!
102
+ EOS
103
+ end
104
+ end
105
+
106
+ private
107
+
108
+ def packaging_folder_dirty?
109
+ !Dir[File.join(Config.tmp_path, @model.trigger, '*')].empty?
110
+ end
23
111
 
24
- private
112
+ def tmp_path_package_files
113
+ Dir[File.join(
114
+ Config.tmp_path,
115
+ "????.??.??.??.??.??.#{ @model.trigger }.tar{,[.-]*}"
116
+ )]
117
+ end
25
118
 
26
- ##
27
- # Returns an Array of paths to temporary files generated by Backup that need to be removed
28
- def paths
29
- Array.new([
30
- File.join(TMP_PATH, TRIGGER),
31
- Backup::Model.file,
32
- Backup::Model.chunk_suffixes.map { |chunk_suffix| "#{Backup::Model.file}-#{chunk_suffix}" }
33
- ]).flatten
34
119
  end
35
120
  end
36
121
  end
@@ -3,6 +3,7 @@
3
3
  module Backup
4
4
  module CLI
5
5
  module Helpers
6
+ UTILITY = {}
6
7
 
7
8
  ##
8
9
  # Runs a given command in an isolated (sub) process using POpen4.
@@ -33,44 +34,28 @@ module Backup
33
34
  end
34
35
 
35
36
  ##
36
- # Wrapper method for FileUtils.mkdir_p to create directories
37
- # through a ruby method. This helps with test coverage and
38
- # improves readability
39
- def mkdir(path)
40
- FileUtils.mkdir_p(path)
41
- end
42
-
43
- ##
44
- # Wrapper for the FileUtils.rm_rf to remove files and folders
45
- # through a ruby method. This helps with test coverage and
46
- # improves readability
47
- def rm(path)
48
- FileUtils.rm_rf(path)
49
- end
50
-
51
- ##
52
- # Tries to find the full path of the specified utility. If the full
53
- # path is found, it'll return that. Otherwise it'll just return the
54
- # name of the utility. If the 'utility_path' is defined, it'll check
55
- # to see if it isn't an empty string, and if it isn't, it'll go ahead and
56
- # always use that path rather than auto-detecting it
37
+ # Returns the full path to the specified utility.
38
+ # Raises an error if utility can not be found in the system's $PATH
57
39
  def utility(name)
58
- if respond_to?(:utility_path)
59
- if utility_path.is_a?(String) and not utility_path.empty?
60
- return utility_path
61
- end
62
- end
63
-
64
- if path = %x[which #{name} 2>/dev/null].chomp and not path.empty?
65
- return path
40
+ path = UTILITY[name] || %x[which #{name} 2>/dev/null].chomp
41
+ if path.empty?
42
+ raise Errors::CLI::UtilityNotFoundError, <<-EOS
43
+ Path to '#{ name }' could not be found.
44
+ Make sure the specified utility is installed
45
+ and available in your system's $PATH.
46
+ If this is a database utility, you may need to specify the full path
47
+ using the Database's '<utility_name>_utility' configuration setting.
48
+ EOS
66
49
  end
67
- name
50
+ UTILITY[name] = path
68
51
  end
69
52
 
70
53
  ##
71
- # Returns the name of the command
54
+ # Returns the name of the command name from the given command line
72
55
  def command_name(command)
73
- command.slice(0, command.index(/\s/)).split('/')[-1]
56
+ i = command =~ /\s/
57
+ command = command.slice(0, i) if i
58
+ command.split('/')[-1]
74
59
  end
75
60
 
76
61
  ##
@@ -13,7 +13,7 @@ module Backup
13
13
  # If the other options (--config-file, --data-path, --cache--path, --tmp-path) aren't specified
14
14
  # they will fallback to the (good) defaults
15
15
  #
16
- # If --root-path is given, it will be used as the base (Backup::PATH) for our defaults,
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".
19
19
  method_option :trigger, :type => :string, :required => true, :aliases => ['-t', '--triggers']
@@ -30,71 +30,56 @@ module Backup
30
30
  "This will invoke 4 backups, and they will run in the order specified (not asynchronous)."
31
31
  def perform
32
32
  ##
33
- # Setup required paths based on the given options
34
- setup_paths(options)
33
+ # Silence Backup::Logger from printing to STDOUT, if --quiet was specified
34
+ Logger.quiet = options[:quiet]
35
35
 
36
36
  ##
37
- # Silence Backup::Logger from printing to STDOUT, if --quiet was specified
38
- Logger.send(:const_set, :QUIET, options[:quiet])
37
+ # Update Config variables based on the given options
38
+ Config.update(options)
39
+
40
+ ##
41
+ # Load the configuration file
42
+ Config.load_config!
43
+
44
+ ##
45
+ # Ensure the :log_path, :cache_path and :tmp_path are created
46
+ # if they do not yet exist
47
+ [Config.log_path, Config.cache_path, Config.tmp_path].each do |path|
48
+ FileUtils.mkdir_p(path)
49
+ end
50
+
51
+ ##
52
+ # Truncate log file if needed
53
+ Logger.truncate!
39
54
 
40
55
  ##
41
56
  # Prepare all trigger names by splitting them by ','
42
57
  # and finding trigger names matching wildcard
43
58
  triggers = options[:trigger].split(",")
44
- triggers.map!(&:strip).map!{ |t|
45
- t.include?(Backup::Finder::WILDCARD) ?
46
- Backup::Finder.new(t).matching : t
59
+ triggers.map!(&:strip).map! {|t|
60
+ t.include?('*') ? Model.find_matching(t) : t
47
61
  }.flatten!
48
62
 
49
63
  ##
50
64
  # Process each trigger
51
65
  triggers.each do |trigger|
52
-
53
- ##
54
- # Defines the TRIGGER constant
55
- Backup.send(:const_set, :TRIGGER, trigger)
56
-
57
66
  ##
58
- # Define the TIME constants
59
- Backup.send(:const_set, :TIME, Time.now.strftime("%Y.%m.%d.%H.%M.%S"))
67
+ # Find the model for this trigger
68
+ # Will raise an error if not found
69
+ model = Model.find(trigger)
60
70
 
61
71
  ##
62
- # Ensure DATA_PATH and DATA_PATH/TRIGGER are created if they do not yet exist
63
- FileUtils.mkdir_p(File.join(Backup::DATA_PATH, Backup::TRIGGER))
64
-
65
- ##
66
- # Parses the backup configuration file and returns the model instance by trigger
67
- model = Backup::Finder.new(trigger).find
68
-
69
- ##
70
- # Runs the returned model
71
- Logger.message "Performing backup for #{model.label}!"
72
+ # Prepare and Perform the backup
73
+ model.prepare!
72
74
  model.perform!
73
75
 
74
- ##
75
- # Removes the TRIGGER constant
76
- Backup.send(:remove_const, :TRIGGER) if defined? Backup::TRIGGER
77
-
78
- ##
79
- # Removes the TIME constant
80
- Backup.send(:remove_const, :TIME) if defined? Backup::TIME
81
-
82
- ##
83
- # Reset the Backup::Model.current to nil for the next potential run
84
- Backup::Model.current = nil
85
-
86
76
  ##
87
77
  # Clear the Log Messages for the next potential run
88
78
  Logger.clear!
89
-
90
- ##
91
- # Reset the Backup::Model.extension to 'tar' so it's at its
92
- # initial state when the next Backup::Model initializes
93
- Backup::Model.extension = 'tar'
94
79
  end
95
80
 
96
81
  rescue => err
97
- Logger.error Backup::Errors::CLIError.wrap(err)
82
+ Logger.error Errors::CLIError.wrap(err)
98
83
  exit(1)
99
84
  end
100
85
 
@@ -104,14 +89,15 @@ module Backup
104
89
  # For example:
105
90
  # $ backup generate:model --trigger my_backup --databases='mongodb'
106
91
  # will generate a pre-populated model with a base MongoDB setup
107
- method_option :trigger, :type => :string, :required => true
108
- method_option :config_path, :type => :string,
109
- :desc => 'Path to your Backup configuration directory'
110
92
  desc 'generate:model', "Generates a Backup model file\n\n" +
111
93
  "Note:\n" +
112
94
  "\s\s'--config-path' is the path to the directory where 'config.rb' is located.\n" +
113
95
  "\s\sThe model file will be created as '<config_path>/models/<trigger>.rb'\n" +
114
- "\s\sDefault: #{Backup::PATH}\n"
96
+ "\s\sDefault: #{Config.root_path}\n"
97
+
98
+ method_option :trigger, :type => :string, :required => true
99
+ method_option :config_path, :type => :string,
100
+ :desc => 'Path to your Backup configuration directory'
115
101
 
116
102
  # options with their available values
117
103
  %w{ databases storages syncers
@@ -127,10 +113,11 @@ module Backup
127
113
 
128
114
  define_method "generate:model" do
129
115
  opts = options.merge(
130
- :trigger => options[:trigger].gsub(/[\W\s]/, '_'),
131
- :config_path => options[:config_path] ? File.expand_path(options[:config_path]) : nil
116
+ :trigger => options[:trigger].gsub(/[\W\s]/, '_'),
117
+ :config_path => options[:config_path] ?
118
+ File.expand_path(options[:config_path]) : nil
132
119
  )
133
- config_path = opts[:config_path] || Backup::PATH
120
+ config_path = opts[:config_path] || Config.root_path
134
121
  models_path = File.join(config_path, "models")
135
122
  config = File.join(config_path, "config.rb")
136
123
  model = File.join(models_path, "#{opts[:trigger]}.rb")
@@ -141,14 +128,14 @@ module Backup
141
128
  file.write(Backup::Template.new({:options => opts}).
142
129
  result("cli/utility/model.erb"))
143
130
  end
144
- puts "Generated model file in '#{ model }'."
131
+ puts "Generated model file: '#{ model }'."
145
132
  end
146
133
 
147
134
  if not File.exist?(config)
148
135
  File.open(config, "w") do |file|
149
136
  file.write(Backup::Template.new.result("cli/utility/config"))
150
137
  end
151
- puts "Generated configuration file in '#{ config }'."
138
+ puts "Generated configuration file: '#{ config }'."
152
139
  end
153
140
  end
154
141
 
@@ -156,18 +143,19 @@ module Backup
156
143
  # [Generate:Config]
157
144
  # Generates the main configuration file
158
145
  desc 'generate:config', 'Generates the main Backup bootstrap/configuration file'
159
- method_option :path, :type => :string
146
+ method_option :config_path, :type => :string,
147
+ :desc => 'Path to your Backup configuration directory'
160
148
  define_method 'generate:config' do
161
- path = options[:path] ? File.expand_path(options[:path]) : nil
162
- config_path = path || Backup::PATH
163
- config = File.join(config_path, "config.rb")
149
+ config_path = options[:config_path] ?
150
+ File.expand_path(options[:config_path]) : Config.root_path
151
+ config = File.join(config_path, "config.rb")
164
152
 
165
153
  FileUtils.mkdir_p(config_path)
166
154
  if overwrite?(config)
167
155
  File.open(config, "w") do |file|
168
156
  file.write(Backup::Template.new.result("cli/utility/config"))
169
157
  end
170
- puts "Generated configuration file in '#{ config }'"
158
+ puts "Generated configuration file: '#{ config }'."
171
159
  end
172
160
  end
173
161
 
@@ -192,7 +180,7 @@ module Backup
192
180
  %x[gpg -o '#{options[:out]}' -d '#{options[:in]}']
193
181
  else
194
182
  puts "Unknown encryptor: #{options[:encryptor]}"
195
- puts "Use either 'openssl' or 'gpg'"
183
+ puts "Use either 'openssl' or 'gpg'."
196
184
  end
197
185
  end
198
186
 
@@ -245,55 +233,6 @@ module Backup
245
233
 
246
234
  private
247
235
 
248
- ##
249
- # Setup required paths based on the given options
250
- #
251
- def setup_paths(options)
252
- ##
253
- # Set PATH if --root-path is given and the directory exists
254
- root_path = false
255
- root_given = options[:root_path].strip
256
- if !root_given.empty? && File.directory?(root_given)
257
- root_path = File.expand_path(root_given)
258
- Backup.send(:remove_const, :PATH)
259
- Backup.send(:const_set, :PATH, root_path)
260
- end
261
-
262
- ##
263
- # Update all defaults and given paths to use root_path (if given).
264
- # Paths given as an absolute path will be used 'as-is'
265
- { :config_file => 'config.rb',
266
- :data_path => 'data',
267
- :log_path => 'log',
268
- :cache_path => '.cache',
269
- :tmp_path => '.tmp' }.each do |key, name|
270
- # strip any trailing '/' in case the user supplied this as part of
271
- # an absolute path, so we can match it against File.expand_path()
272
- given = options[key].sub(/\/\s*$/, '').lstrip
273
- path = false
274
- if given.empty?
275
- path = File.join(root_path, name) if root_path
276
- else
277
- path = File.expand_path(given)
278
- unless given == path
279
- path = File.join(root_path, given) if root_path
280
- end
281
- end
282
-
283
- const = key.to_s.upcase
284
- if path
285
- Backup.send(:remove_const, const)
286
- Backup.send(:const_set, const, path)
287
- else
288
- path = Backup.const_get(const)
289
- end
290
-
291
- ##
292
- # Ensure the LOG_PATH, CACHE_PATH and TMP_PATH are created if they do not yet exist
293
- FileUtils.mkdir_p(path) if [:log_path, :cache_path, :tmp_path].include?(key)
294
- end
295
- end
296
-
297
236
  ##
298
237
  # Helper method for asking the user if he/she wants to overwrite the file
299
238
  def overwrite?(path)