backup 3.0.27 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (166) hide show
  1. data/LICENSE.md +1 -1
  2. data/README.md +139 -386
  3. data/bin/backup +1 -7
  4. data/lib/backup.rb +3 -9
  5. data/lib/backup/archive.rb +26 -20
  6. data/lib/backup/cleaner.rb +2 -2
  7. data/lib/backup/cli.rb +366 -0
  8. data/lib/backup/compressor/base.rb +2 -2
  9. data/lib/backup/compressor/gzip.rb +35 -1
  10. data/lib/backup/config.rb +1 -2
  11. data/lib/backup/database/base.rb +2 -2
  12. data/lib/backup/database/mongodb.rb +3 -3
  13. data/lib/backup/database/mysql.rb +3 -2
  14. data/lib/backup/database/postgresql.rb +3 -2
  15. data/lib/backup/database/riak.rb +18 -5
  16. data/lib/backup/dependency.rb +144 -93
  17. data/lib/backup/encryptor/base.rb +2 -2
  18. data/lib/backup/logger.rb +108 -110
  19. data/lib/backup/logger/console.rb +51 -0
  20. data/lib/backup/logger/logfile.rb +113 -0
  21. data/lib/backup/logger/syslog.rb +116 -0
  22. data/lib/backup/model.rb +67 -65
  23. data/lib/backup/notifier/base.rb +1 -1
  24. data/lib/backup/notifier/hipchat.rb +1 -1
  25. data/lib/backup/notifier/mail.rb +1 -1
  26. data/lib/backup/notifier/pushover.rb +6 -3
  27. data/lib/backup/packager.rb +4 -4
  28. data/lib/backup/pipeline.rb +17 -3
  29. data/lib/backup/splitter.rb +2 -2
  30. data/lib/backup/storage/base.rb +2 -2
  31. data/lib/backup/storage/cloudfiles.rb +2 -2
  32. data/lib/backup/storage/dropbox.rb +4 -4
  33. data/lib/backup/storage/ftp.rb +2 -2
  34. data/lib/backup/storage/local.rb +2 -2
  35. data/lib/backup/storage/ninefold.rb +2 -2
  36. data/lib/backup/storage/rsync.rb +3 -3
  37. data/lib/backup/storage/s3.rb +2 -2
  38. data/lib/backup/storage/scp.rb +2 -6
  39. data/lib/backup/storage/sftp.rb +2 -5
  40. data/lib/backup/syncer/base.rb +1 -1
  41. data/lib/backup/syncer/cloud/base.rb +15 -8
  42. data/lib/backup/syncer/rsync/local.rb +1 -1
  43. data/lib/backup/syncer/rsync/pull.rb +1 -1
  44. data/lib/backup/syncer/rsync/push.rb +1 -1
  45. data/lib/backup/utilities.rb +211 -0
  46. data/lib/backup/version.rb +1 -1
  47. data/templates/cli/{utility/archive → archive} +4 -8
  48. data/templates/cli/{utility/compressor → compressor}/bzip2 +0 -0
  49. data/templates/cli/{utility/compressor → compressor}/custom +0 -0
  50. data/templates/cli/{utility/compressor → compressor}/gzip +0 -0
  51. data/templates/cli/{utility/compressor → compressor}/lzma +0 -0
  52. data/templates/cli/{utility/compressor → compressor}/pbzip2 +0 -0
  53. data/templates/cli/config +68 -0
  54. data/templates/cli/{utility/database → database}/mongodb +1 -1
  55. data/templates/cli/{utility/database → database}/mysql +1 -1
  56. data/templates/cli/{utility/database → database}/postgresql +1 -1
  57. data/templates/cli/{utility/database → database}/redis +0 -0
  58. data/templates/cli/database/riak +20 -0
  59. data/templates/cli/{utility/encryptor → encryptor}/gpg +0 -0
  60. data/templates/cli/{utility/encryptor → encryptor}/openssl +0 -0
  61. data/templates/cli/{utility/model.erb → model.erb} +4 -4
  62. data/templates/cli/{utility/notifier → notifier}/campfire +0 -0
  63. data/templates/cli/{utility/notifier → notifier}/hipchat +0 -0
  64. data/templates/cli/{utility/notifier → notifier}/mail +0 -0
  65. data/templates/cli/{utility/notifier → notifier}/prowl +0 -0
  66. data/templates/cli/{utility/notifier → notifier}/pushover +0 -0
  67. data/templates/cli/{utility/notifier → notifier}/twitter +0 -0
  68. data/templates/cli/{utility/splitter → splitter} +0 -0
  69. data/templates/cli/{utility/storage → storage}/cloud_files +0 -0
  70. data/templates/cli/{utility/storage → storage}/dropbox +0 -0
  71. data/templates/cli/{utility/storage → storage}/ftp +0 -0
  72. data/templates/cli/{utility/storage → storage}/local +0 -0
  73. data/templates/cli/{utility/storage → storage}/ninefold +0 -0
  74. data/templates/cli/{utility/storage → storage}/rsync +0 -0
  75. data/templates/cli/{utility/storage → storage}/s3 +0 -0
  76. data/templates/cli/{utility/storage → storage}/scp +0 -0
  77. data/templates/cli/{utility/storage → storage}/sftp +0 -0
  78. data/templates/cli/{utility/syncer → syncer}/cloud_files +0 -0
  79. data/templates/cli/{utility/syncer → syncer}/rsync_local +0 -0
  80. data/templates/cli/{utility/syncer → syncer}/rsync_pull +0 -0
  81. data/templates/cli/{utility/syncer → syncer}/rsync_push +0 -0
  82. data/templates/cli/{utility/syncer → syncer}/s3 +0 -0
  83. metadata +55 -131
  84. data/.gitignore +0 -8
  85. data/.travis.yml +0 -10
  86. data/Gemfile +0 -28
  87. data/Guardfile +0 -23
  88. data/backup.gemspec +0 -32
  89. data/lib/backup/cli/helpers.rb +0 -93
  90. data/lib/backup/cli/utility.rb +0 -255
  91. data/spec-live/.gitignore +0 -6
  92. data/spec-live/README +0 -7
  93. data/spec-live/backups/config.rb +0 -83
  94. data/spec-live/backups/config.yml.template +0 -46
  95. data/spec-live/backups/models.rb +0 -184
  96. data/spec-live/compressor/custom_spec.rb +0 -30
  97. data/spec-live/compressor/gzip_spec.rb +0 -30
  98. data/spec-live/encryptor/gpg_keys.rb +0 -239
  99. data/spec-live/encryptor/gpg_spec.rb +0 -287
  100. data/spec-live/notifier/mail_spec.rb +0 -121
  101. data/spec-live/spec_helper.rb +0 -151
  102. data/spec-live/storage/dropbox_spec.rb +0 -151
  103. data/spec-live/storage/local_spec.rb +0 -83
  104. data/spec-live/storage/scp_spec.rb +0 -193
  105. data/spec-live/syncer/cloud/s3_spec.rb +0 -124
  106. data/spec/archive_spec.rb +0 -335
  107. data/spec/cleaner_spec.rb +0 -312
  108. data/spec/cli/helpers_spec.rb +0 -301
  109. data/spec/cli/utility_spec.rb +0 -411
  110. data/spec/compressor/base_spec.rb +0 -52
  111. data/spec/compressor/bzip2_spec.rb +0 -217
  112. data/spec/compressor/custom_spec.rb +0 -106
  113. data/spec/compressor/gzip_spec.rb +0 -217
  114. data/spec/compressor/lzma_spec.rb +0 -123
  115. data/spec/compressor/pbzip2_spec.rb +0 -165
  116. data/spec/config_spec.rb +0 -321
  117. data/spec/configuration/helpers_spec.rb +0 -247
  118. data/spec/configuration/store_spec.rb +0 -39
  119. data/spec/configuration_spec.rb +0 -62
  120. data/spec/database/base_spec.rb +0 -63
  121. data/spec/database/mongodb_spec.rb +0 -510
  122. data/spec/database/mysql_spec.rb +0 -411
  123. data/spec/database/postgresql_spec.rb +0 -353
  124. data/spec/database/redis_spec.rb +0 -334
  125. data/spec/database/riak_spec.rb +0 -176
  126. data/spec/dependency_spec.rb +0 -51
  127. data/spec/encryptor/base_spec.rb +0 -40
  128. data/spec/encryptor/gpg_spec.rb +0 -909
  129. data/spec/encryptor/open_ssl_spec.rb +0 -148
  130. data/spec/errors_spec.rb +0 -306
  131. data/spec/logger_spec.rb +0 -367
  132. data/spec/model_spec.rb +0 -666
  133. data/spec/notifier/base_spec.rb +0 -104
  134. data/spec/notifier/campfire_spec.rb +0 -217
  135. data/spec/notifier/hipchat_spec.rb +0 -211
  136. data/spec/notifier/mail_spec.rb +0 -316
  137. data/spec/notifier/prowl_spec.rb +0 -138
  138. data/spec/notifier/pushover_spec.rb +0 -123
  139. data/spec/notifier/twitter_spec.rb +0 -153
  140. data/spec/package_spec.rb +0 -61
  141. data/spec/packager_spec.rb +0 -213
  142. data/spec/pipeline_spec.rb +0 -259
  143. data/spec/spec_helper.rb +0 -60
  144. data/spec/splitter_spec.rb +0 -120
  145. data/spec/storage/base_spec.rb +0 -166
  146. data/spec/storage/cloudfiles_spec.rb +0 -254
  147. data/spec/storage/cycler_spec.rb +0 -247
  148. data/spec/storage/dropbox_spec.rb +0 -480
  149. data/spec/storage/ftp_spec.rb +0 -271
  150. data/spec/storage/local_spec.rb +0 -259
  151. data/spec/storage/ninefold_spec.rb +0 -343
  152. data/spec/storage/rsync_spec.rb +0 -362
  153. data/spec/storage/s3_spec.rb +0 -245
  154. data/spec/storage/scp_spec.rb +0 -233
  155. data/spec/storage/sftp_spec.rb +0 -244
  156. data/spec/syncer/base_spec.rb +0 -109
  157. data/spec/syncer/cloud/base_spec.rb +0 -515
  158. data/spec/syncer/cloud/cloud_files_spec.rb +0 -181
  159. data/spec/syncer/cloud/s3_spec.rb +0 -174
  160. data/spec/syncer/rsync/base_spec.rb +0 -98
  161. data/spec/syncer/rsync/local_spec.rb +0 -149
  162. data/spec/syncer/rsync/pull_spec.rb +0 -98
  163. data/spec/syncer/rsync/push_spec.rb +0 -333
  164. data/spec/version_spec.rb +0 -21
  165. data/templates/cli/utility/config +0 -32
  166. data/templates/cli/utility/database/riak +0 -11
data/.gitignore DELETED
@@ -1,8 +0,0 @@
1
- .DS_Store
2
- *.gem
3
- .rvmrc
4
- .bundle/
5
- vendor/bundle
6
- *.swp
7
- *.swo
8
- Gemfile.lock
data/.travis.yml DELETED
@@ -1,10 +0,0 @@
1
- script: "bundle exec rspec ./spec/"
2
- rvm:
3
- - 1.8.7
4
- - 1.9.2
5
- - 1.9.3
6
- - ree
7
- branches:
8
- only:
9
- - master
10
- - develop
data/Gemfile DELETED
@@ -1,28 +0,0 @@
1
- # encoding: utf-8
2
-
3
- # RubyGems Source
4
- source 'http://rubygems.org'
5
-
6
- # Include gem dependencies from the gemspec for development purposes
7
- gemspec
8
-
9
- # Dynamically define the dependencies specified in Backup::Dependency.all
10
- require File.expand_path("../lib/backup/dependency", __FILE__)
11
- Backup::Dependency.all.each do |name, gemspec|
12
- gem(name, gemspec[:version])
13
- end
14
-
15
- # Define gems to be used in the 'test' environment
16
- group :test do
17
- gem 'rspec'
18
- gem 'mocha', '0.12.7'
19
- gem 'timecop'
20
- gem 'fuubar'
21
-
22
- gem 'guard'
23
- gem 'guard-rspec'
24
- gem 'rb-fsevent' # guard notifications for osx
25
- gem 'growl' # $ brew install growlnotify
26
- gem 'rb-inotify' # guard notifications for linux
27
- gem 'libnotify' # $ apt-get install ???
28
- end
data/Guardfile DELETED
@@ -1,23 +0,0 @@
1
- # encoding: utf-8
2
-
3
- # To run the test suite against all 3 rubies: 1.9.3, 1.9.2, and 1.8.7, simply run the following command:
4
- #
5
- # $ guard start
6
- #
7
- # Be use you are using RVM and have Ruby 1.9.3, 1.9.2, 1.8.7 installed as well as all of Backup's gem
8
- # dependencies for each of these Ruby versions.
9
- #
10
- # Be sure to run `bundle install` against every Ruby version, as well as `gem install thor POpen4`
11
-
12
- guard "rspec",
13
- :rvm => ["1.9.3", "1.9.2", "1.8.7"],
14
- :cli => "--color --format Fuubar",
15
- :notification => false,
16
- :all_after_pass => false,
17
- :all_on_start => false do
18
-
19
- watch("lib/backup.rb") { "spec" }
20
- watch("spec/spec_helper.rb") { "spec" }
21
- watch(%r{^lib/backup/(.+)\.rb}) {|m| "spec/#{ m[1] }_spec.rb" }
22
- watch(%r{^spec/.+_spec\.rb})
23
- end
data/backup.gemspec DELETED
@@ -1,32 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require File.expand_path('lib/backup/version')
4
-
5
- Gem::Specification.new do |gem|
6
-
7
- ##
8
- # General configuration / information
9
- gem.name = 'backup'
10
- gem.version = Backup::Version.current
11
- gem.platform = Gem::Platform::RUBY
12
- gem.authors = 'Michael van Rooijen'
13
- gem.email = 'meskyanichi@gmail.com'
14
- gem.homepage = 'http://rubygems.org/gems/backup'
15
- gem.summary = 'Backup is a RubyGem, written for UNIX-like operating systems, that allows you to easily perform backup operations on both your remote and local environments. It provides you with an elegant DSL in Ruby for modeling your backups. Backup has built-in support for various databases, storage protocols/services, syncers, compressors, encryptors and notifiers which you can mix and match. It was built with modularity, extensibility and simplicity in mind.'
16
-
17
- ##
18
- # Files and folder that need to be compiled in to the Ruby Gem
19
- gem.files = %x[git ls-files].split("\n")
20
- gem.test_files = %x[git ls-files -- {spec}/*].split("\n")
21
- gem.require_path = 'lib'
22
-
23
- ##
24
- # The Backup CLI executable
25
- gem.executables = ['backup']
26
-
27
- ##
28
- # Gem dependencies
29
- gem.add_dependency 'thor', ['>= 0.15.4', '< 2']
30
- gem.add_dependency 'open4', ['~> 1.3.0']
31
-
32
- end
@@ -1,93 +0,0 @@
1
- # encoding: utf-8
2
-
3
- module Backup
4
- module CLI
5
- module Helpers
6
- UTILITY = {}
7
-
8
- private
9
-
10
- ##
11
- # Runs a system command
12
- #
13
- # All messages generated by the command will be logged.
14
- # Messages on STDERR will be logged as warnings.
15
- #
16
- # If the command fails to execute, or returns a non-zero exit status
17
- # an Error will be raised.
18
- #
19
- # Returns STDOUT
20
- def run(command)
21
- name = command_name(command)
22
- Logger.message "Running system utility '#{ name }'..."
23
-
24
- begin
25
- out, err = '', ''
26
- ps = Open4.popen4(command) do |pid, stdin, stdout, stderr|
27
- stdin.close
28
- out, err = stdout.read.strip, stderr.read.strip
29
- end
30
- rescue Exception => e
31
- raise Errors::CLI::SystemCallError.wrap(e, <<-EOS)
32
- Failed to execute system command on #{ RUBY_PLATFORM }
33
- Command was: #{ command }
34
- EOS
35
- end
36
-
37
- if ps.success?
38
- unless out.empty?
39
- Logger.message(
40
- out.lines.map {|line| "#{ name }:STDOUT: #{ line }" }.join
41
- )
42
- end
43
-
44
- unless err.empty?
45
- Logger.warn(
46
- err.lines.map {|line| "#{ name }:STDERR: #{ line }" }.join
47
- )
48
- end
49
-
50
- return out
51
- else
52
- raise Errors::CLI::SystemCallError, <<-EOS
53
- '#{ name }' Failed on #{ RUBY_PLATFORM }
54
- The following information should help to determine the problem:
55
- Command was: #{ command }
56
- Exit Status: #{ ps.exitstatus }
57
- STDOUT Messages: #{ out.empty? ? 'None' : "\n#{ out }" }
58
- STDERR Messages: #{ err.empty? ? 'None' : "\n#{ err }" }
59
- EOS
60
- end
61
- end
62
-
63
-
64
- ##
65
- # Returns the full path to the specified utility.
66
- # Raises an error if utility can not be found in the system's $PATH
67
- def utility(name)
68
- name = name.to_s.strip
69
- raise Errors::CLI::UtilityNotFoundError,
70
- 'Utility Name Empty' if name.empty?
71
-
72
- path = UTILITY[name] || %x[which #{ name } 2>/dev/null].chomp
73
- if path.empty?
74
- raise Errors::CLI::UtilityNotFoundError, <<-EOS
75
- Could not locate '#{ name }'.
76
- Make sure the specified utility is installed
77
- and available in your system's $PATH.
78
- EOS
79
- end
80
- UTILITY[name] = path
81
- end
82
-
83
- ##
84
- # Returns the name of the command name from the given command line
85
- def command_name(command)
86
- i = command =~ /\s/
87
- command = command.slice(0, i) if i
88
- command.split('/')[-1]
89
- end
90
-
91
- end
92
- end
93
- end
@@ -1,255 +0,0 @@
1
- # encoding: utf-8
2
-
3
- ##
4
- # Build the Backup Command Line Interface using Thor
5
- module Backup
6
- module CLI
7
- class Utility < Thor
8
- include Thor::Actions
9
-
10
- ##
11
- # [Perform]
12
- # Performs the backup process. The only required option is the --trigger [-t].
13
- # If the other options (--config-file, --data-path, --cache--path, --tmp-path) aren't specified
14
- # they will fallback to the (good) defaults
15
- #
16
- # If --root-path is given, it will be used as the base path for our defaults,
17
- # as well as the base path for any option specified as a relative path.
18
- # Any option given as an absolute path will be used "as-is".
19
- method_option :trigger, :type => :string, :required => true, :aliases => ['-t', '--triggers']
20
- method_option :config_file, :type => :string, :default => '', :aliases => '-c'
21
- method_option :root_path, :type => :string, :default => '', :aliases => '-r'
22
- method_option :data_path, :type => :string, :default => '', :aliases => '-d'
23
- method_option :log_path, :type => :string, :default => '', :aliases => '-l'
24
- method_option :cache_path, :type => :string, :default => ''
25
- method_option :tmp_path, :type => :string, :default => ''
26
- method_option :quiet, :type => :boolean, :default => false, :aliases => '-q'
27
- desc 'perform', "Performs the backup for the specified trigger.\n" +
28
- "You may perform multiple backups by providing multiple triggers, separated by commas.\n\n" +
29
- "Example:\n\s\s$ backup perform --triggers backup1,backup2,backup3,backup4\n\n" +
30
- "This will invoke 4 backups, and they will run in the order specified (not asynchronous)."
31
- def perform
32
- ##
33
- # Silence Backup::Logger from printing to STDOUT, if --quiet was specified
34
- Logger.quiet = options[:quiet]
35
-
36
- ##
37
- # Update Config variables based on the given options
38
- Config.update(options)
39
-
40
- ##
41
- # Ensure the :log_path, :cache_path and :tmp_path are created
42
- # if they do not yet exist
43
- [Config.log_path, Config.cache_path, Config.tmp_path].each do |path|
44
- FileUtils.mkdir_p(path)
45
- end
46
-
47
- ##
48
- # Load the configuration file
49
- Config.load_config!
50
-
51
- ##
52
- # Truncate log file if needed
53
- Logger.truncate!
54
-
55
- ##
56
- # Prepare all trigger names by splitting them by ','
57
- # and finding trigger names matching wildcard
58
- triggers = options[:trigger].split(",")
59
- triggers.map!(&:strip).map! {|t|
60
- t.include?('*') ? Model.find_matching(t).map(&:trigger) : t
61
- }.flatten!
62
-
63
- ##
64
- # Process each trigger
65
- triggers.each do |trigger|
66
- ##
67
- # Find the model for this trigger
68
- # Will raise an error if not found
69
- model = Model.find(trigger)
70
-
71
- ##
72
- # Prepare and Perform the backup
73
- model.prepare!
74
- model.perform!
75
-
76
- ##
77
- # Clear the Log Messages for the next potential run
78
- Logger.clear!
79
- end
80
-
81
- rescue => err
82
- Logger.error Errors::CLIError.wrap(err)
83
- exit(1)
84
- end
85
-
86
- ##
87
- # [Generate:Model]
88
- # Generates a model configuration file based on the arguments passed in.
89
- # For example:
90
- # $ backup generate:model --trigger my_backup --databases='mongodb'
91
- # will generate a pre-populated model with a base MongoDB setup
92
- desc 'generate:model', "Generates a Backup model file\n\n" +
93
- "Note:\n" +
94
- "\s\s'--config-path' is the path to the directory where 'config.rb' is located.\n" +
95
- "\s\sThe model file will be created as '<config_path>/models/<trigger>.rb'\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'
101
-
102
- # options with their available values
103
- %w{ databases storages syncers
104
- encryptors compressors notifiers }.map(&:to_sym).each do |name|
105
- path = File.join(Backup::TEMPLATE_PATH, 'cli', 'utility', name.to_s[0..-2])
106
- method_option name, :type => :string, :desc =>
107
- "(#{Dir[path + '/*'].sort.map {|p| File.basename(p) }.join(', ')})"
108
- end
109
-
110
- method_option :archives, :type => :boolean
111
- method_option :splitter, :type => :boolean, :default => true,
112
- :desc => "use `--no-splitter` to disable"
113
-
114
- define_method "generate:model" do
115
- opts = options.merge(
116
- :trigger => options[:trigger].gsub(/[\W\s]/, '_'),
117
- :config_path => options[:config_path] ?
118
- File.expand_path(options[:config_path]) : nil
119
- )
120
- config_path = opts[:config_path] || Config.root_path
121
- models_path = File.join(config_path, "models")
122
- config = File.join(config_path, "config.rb")
123
- model = File.join(models_path, "#{opts[:trigger]}.rb")
124
-
125
- FileUtils.mkdir_p(models_path)
126
- if overwrite?(model)
127
- File.open(model, 'w') do |file|
128
- file.write(Backup::Template.new({:options => opts}).
129
- result("cli/utility/model.erb"))
130
- end
131
- puts "Generated model file: '#{ model }'."
132
- end
133
-
134
- if not File.exist?(config)
135
- File.open(config, "w") do |file|
136
- file.write(Backup::Template.new.result("cli/utility/config"))
137
- end
138
- puts "Generated configuration file: '#{ config }'."
139
- end
140
- end
141
-
142
- ##
143
- # [Generate:Config]
144
- # Generates the main configuration file
145
- desc 'generate:config', 'Generates the main Backup bootstrap/configuration file'
146
- method_option :config_path, :type => :string,
147
- :desc => 'Path to your Backup configuration directory'
148
- define_method 'generate:config' do
149
- config_path = options[:config_path] ?
150
- File.expand_path(options[:config_path]) : Config.root_path
151
- config = File.join(config_path, "config.rb")
152
-
153
- FileUtils.mkdir_p(config_path)
154
- if overwrite?(config)
155
- File.open(config, "w") do |file|
156
- file.write(Backup::Template.new.result("cli/utility/config"))
157
- end
158
- puts "Generated configuration file: '#{ config }'."
159
- end
160
- end
161
-
162
- ##
163
- # [Decrypt]
164
- # Shorthand for decrypting encrypted files
165
- desc 'decrypt', 'Decrypts encrypted files'
166
- method_option :encryptor, :type => :string, :required => true
167
- method_option :in, :type => :string, :required => true
168
- method_option :out, :type => :string, :required => true
169
- method_option :base64, :type => :boolean, :default => false
170
- method_option :password_file, :type => :string, :default => ''
171
- method_option :salt, :type => :boolean, :default => false
172
- def decrypt
173
- case options[:encryptor].downcase
174
- when 'openssl'
175
- base64 = options[:base64] ? '-base64' : ''
176
- password = options[:password_file].empty? ? '' : "-pass file:#{options[:password_file]}"
177
- salt = options[:salt] ? '-salt' : ''
178
- %x[openssl aes-256-cbc -d #{base64} #{password} #{salt} -in '#{options[:in]}' -out '#{options[:out]}']
179
- when 'gpg'
180
- %x[gpg -o '#{options[:out]}' -d '#{options[:in]}']
181
- else
182
- puts "Unknown encryptor: #{options[:encryptor]}"
183
- puts "Use either 'openssl' or 'gpg'."
184
- end
185
- end
186
-
187
- ##
188
- # [Dependencies]
189
- # Returns a list of Backup's dependencies
190
- desc 'dependencies', 'Display the list of dependencies for Backup, check the installation status, or install them through Backup.'
191
- method_option :install, :type => :string
192
- method_option :list, :type => :boolean
193
- method_option :installed, :type => :string
194
- def dependencies
195
- unless options.any?
196
- puts
197
- puts "To display a list of available dependencies, run:\n\n"
198
- puts " backup dependencies --list"
199
- puts
200
- puts "To install one of these dependencies (with the correct version), run:\n\n"
201
- puts " backup dependencies --install <name>"
202
- puts
203
- puts "To check if a dependency is already installed, run:\n\n"
204
- puts " backup dependencies --installed <name>"
205
- exit
206
- end
207
-
208
- if options[:list]
209
- Backup::Dependency.all.each do |name, gemspec|
210
- puts
211
- puts name
212
- puts "--------------------------------------------------"
213
- puts "version: #{gemspec[:version]}"
214
- puts "lib required: #{gemspec[:require]}"
215
- puts "used for: #{gemspec[:for]}"
216
- end
217
- end
218
-
219
- if options[:install]
220
- puts
221
- puts "Installing \"#{options[:install]}\" version \"#{Backup::Dependency.all[options[:install]][:version]}\".."
222
- puts "If this doesn't work, please issue the following command yourself:\n\n"
223
- puts " gem install #{options[:install]} -v '#{Backup::Dependency.all[options[:install]][:version]}'\n\n"
224
- puts "Please wait..\n\n"
225
- puts %x[gem install #{options[:install]} -v '#{Backup::Dependency.all[options[:install]][:version]}']
226
- end
227
-
228
- if options[:installed]
229
- puts %x[gem list -i -v '#{Backup::Dependency.all[options[:installed]][:version]}' #{options[:installed]}]
230
- end
231
- end
232
-
233
- ##
234
- # [Version]
235
- # Returns the current version of the Backup gem
236
- map '-v' => :version
237
- desc 'version', 'Display installed Backup version'
238
- def version
239
- puts "Backup #{Backup::Version.current}"
240
- end
241
-
242
- private
243
-
244
- ##
245
- # Helper method for asking the user if he/she wants to overwrite the file
246
- def overwrite?(path)
247
- if File.exist?(path)
248
- return yes? "A file already exists at '#{ path }'. Do you want to overwrite? [y/n]"
249
- end
250
- true
251
- end
252
-
253
- end
254
- end
255
- end