backup-agoddard 3.0.27

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 (190) hide show
  1. data/.gitignore +8 -0
  2. data/.travis.yml +10 -0
  3. data/Gemfile +28 -0
  4. data/Guardfile +23 -0
  5. data/LICENSE.md +24 -0
  6. data/README.md +478 -0
  7. data/backup.gemspec +32 -0
  8. data/bin/backup +11 -0
  9. data/lib/backup.rb +133 -0
  10. data/lib/backup/archive.rb +117 -0
  11. data/lib/backup/binder.rb +22 -0
  12. data/lib/backup/cleaner.rb +121 -0
  13. data/lib/backup/cli/helpers.rb +93 -0
  14. data/lib/backup/cli/utility.rb +255 -0
  15. data/lib/backup/compressor/base.rb +35 -0
  16. data/lib/backup/compressor/bzip2.rb +50 -0
  17. data/lib/backup/compressor/custom.rb +53 -0
  18. data/lib/backup/compressor/gzip.rb +50 -0
  19. data/lib/backup/compressor/lzma.rb +52 -0
  20. data/lib/backup/compressor/pbzip2.rb +59 -0
  21. data/lib/backup/config.rb +174 -0
  22. data/lib/backup/configuration.rb +33 -0
  23. data/lib/backup/configuration/helpers.rb +130 -0
  24. data/lib/backup/configuration/store.rb +24 -0
  25. data/lib/backup/database/base.rb +53 -0
  26. data/lib/backup/database/mongodb.rb +230 -0
  27. data/lib/backup/database/mysql.rb +160 -0
  28. data/lib/backup/database/postgresql.rb +144 -0
  29. data/lib/backup/database/redis.rb +136 -0
  30. data/lib/backup/database/riak.rb +67 -0
  31. data/lib/backup/dependency.rb +108 -0
  32. data/lib/backup/encryptor/base.rb +29 -0
  33. data/lib/backup/encryptor/gpg.rb +760 -0
  34. data/lib/backup/encryptor/open_ssl.rb +72 -0
  35. data/lib/backup/errors.rb +124 -0
  36. data/lib/backup/hooks.rb +68 -0
  37. data/lib/backup/logger.rb +152 -0
  38. data/lib/backup/model.rb +409 -0
  39. data/lib/backup/notifier/base.rb +81 -0
  40. data/lib/backup/notifier/campfire.rb +155 -0
  41. data/lib/backup/notifier/hipchat.rb +93 -0
  42. data/lib/backup/notifier/mail.rb +206 -0
  43. data/lib/backup/notifier/prowl.rb +65 -0
  44. data/lib/backup/notifier/pushover.rb +88 -0
  45. data/lib/backup/notifier/twitter.rb +70 -0
  46. data/lib/backup/package.rb +47 -0
  47. data/lib/backup/packager.rb +100 -0
  48. data/lib/backup/pipeline.rb +110 -0
  49. data/lib/backup/splitter.rb +75 -0
  50. data/lib/backup/storage/base.rb +99 -0
  51. data/lib/backup/storage/cloudfiles.rb +87 -0
  52. data/lib/backup/storage/cycler.rb +117 -0
  53. data/lib/backup/storage/dropbox.rb +178 -0
  54. data/lib/backup/storage/ftp.rb +119 -0
  55. data/lib/backup/storage/local.rb +82 -0
  56. data/lib/backup/storage/ninefold.rb +116 -0
  57. data/lib/backup/storage/rsync.rb +149 -0
  58. data/lib/backup/storage/s3.rb +94 -0
  59. data/lib/backup/storage/scp.rb +99 -0
  60. data/lib/backup/storage/sftp.rb +108 -0
  61. data/lib/backup/syncer/base.rb +46 -0
  62. data/lib/backup/syncer/cloud/base.rb +247 -0
  63. data/lib/backup/syncer/cloud/cloud_files.rb +78 -0
  64. data/lib/backup/syncer/cloud/s3.rb +68 -0
  65. data/lib/backup/syncer/rsync/base.rb +49 -0
  66. data/lib/backup/syncer/rsync/local.rb +55 -0
  67. data/lib/backup/syncer/rsync/pull.rb +36 -0
  68. data/lib/backup/syncer/rsync/push.rb +116 -0
  69. data/lib/backup/template.rb +46 -0
  70. data/lib/backup/version.rb +43 -0
  71. data/spec-live/.gitignore +6 -0
  72. data/spec-live/README +7 -0
  73. data/spec-live/backups/config.rb +83 -0
  74. data/spec-live/backups/config.yml.template +46 -0
  75. data/spec-live/backups/models.rb +184 -0
  76. data/spec-live/compressor/custom_spec.rb +30 -0
  77. data/spec-live/compressor/gzip_spec.rb +30 -0
  78. data/spec-live/encryptor/gpg_keys.rb +239 -0
  79. data/spec-live/encryptor/gpg_spec.rb +287 -0
  80. data/spec-live/notifier/mail_spec.rb +121 -0
  81. data/spec-live/spec_helper.rb +151 -0
  82. data/spec-live/storage/dropbox_spec.rb +151 -0
  83. data/spec-live/storage/local_spec.rb +83 -0
  84. data/spec-live/storage/scp_spec.rb +193 -0
  85. data/spec-live/syncer/cloud/s3_spec.rb +124 -0
  86. data/spec/archive_spec.rb +335 -0
  87. data/spec/cleaner_spec.rb +312 -0
  88. data/spec/cli/helpers_spec.rb +301 -0
  89. data/spec/cli/utility_spec.rb +411 -0
  90. data/spec/compressor/base_spec.rb +52 -0
  91. data/spec/compressor/bzip2_spec.rb +217 -0
  92. data/spec/compressor/custom_spec.rb +106 -0
  93. data/spec/compressor/gzip_spec.rb +217 -0
  94. data/spec/compressor/lzma_spec.rb +123 -0
  95. data/spec/compressor/pbzip2_spec.rb +165 -0
  96. data/spec/config_spec.rb +321 -0
  97. data/spec/configuration/helpers_spec.rb +247 -0
  98. data/spec/configuration/store_spec.rb +39 -0
  99. data/spec/configuration_spec.rb +62 -0
  100. data/spec/database/base_spec.rb +63 -0
  101. data/spec/database/mongodb_spec.rb +510 -0
  102. data/spec/database/mysql_spec.rb +411 -0
  103. data/spec/database/postgresql_spec.rb +353 -0
  104. data/spec/database/redis_spec.rb +334 -0
  105. data/spec/database/riak_spec.rb +176 -0
  106. data/spec/dependency_spec.rb +51 -0
  107. data/spec/encryptor/base_spec.rb +40 -0
  108. data/spec/encryptor/gpg_spec.rb +909 -0
  109. data/spec/encryptor/open_ssl_spec.rb +148 -0
  110. data/spec/errors_spec.rb +306 -0
  111. data/spec/hooks_spec.rb +35 -0
  112. data/spec/logger_spec.rb +367 -0
  113. data/spec/model_spec.rb +694 -0
  114. data/spec/notifier/base_spec.rb +104 -0
  115. data/spec/notifier/campfire_spec.rb +217 -0
  116. data/spec/notifier/hipchat_spec.rb +211 -0
  117. data/spec/notifier/mail_spec.rb +316 -0
  118. data/spec/notifier/prowl_spec.rb +138 -0
  119. data/spec/notifier/pushover_spec.rb +123 -0
  120. data/spec/notifier/twitter_spec.rb +153 -0
  121. data/spec/package_spec.rb +61 -0
  122. data/spec/packager_spec.rb +213 -0
  123. data/spec/pipeline_spec.rb +259 -0
  124. data/spec/spec_helper.rb +60 -0
  125. data/spec/splitter_spec.rb +120 -0
  126. data/spec/storage/base_spec.rb +166 -0
  127. data/spec/storage/cloudfiles_spec.rb +254 -0
  128. data/spec/storage/cycler_spec.rb +247 -0
  129. data/spec/storage/dropbox_spec.rb +480 -0
  130. data/spec/storage/ftp_spec.rb +271 -0
  131. data/spec/storage/local_spec.rb +259 -0
  132. data/spec/storage/ninefold_spec.rb +343 -0
  133. data/spec/storage/rsync_spec.rb +362 -0
  134. data/spec/storage/s3_spec.rb +245 -0
  135. data/spec/storage/scp_spec.rb +233 -0
  136. data/spec/storage/sftp_spec.rb +244 -0
  137. data/spec/syncer/base_spec.rb +109 -0
  138. data/spec/syncer/cloud/base_spec.rb +515 -0
  139. data/spec/syncer/cloud/cloud_files_spec.rb +181 -0
  140. data/spec/syncer/cloud/s3_spec.rb +174 -0
  141. data/spec/syncer/rsync/base_spec.rb +98 -0
  142. data/spec/syncer/rsync/local_spec.rb +149 -0
  143. data/spec/syncer/rsync/pull_spec.rb +98 -0
  144. data/spec/syncer/rsync/push_spec.rb +333 -0
  145. data/spec/version_spec.rb +21 -0
  146. data/templates/cli/utility/archive +25 -0
  147. data/templates/cli/utility/compressor/bzip2 +4 -0
  148. data/templates/cli/utility/compressor/custom +11 -0
  149. data/templates/cli/utility/compressor/gzip +4 -0
  150. data/templates/cli/utility/compressor/lzma +10 -0
  151. data/templates/cli/utility/compressor/pbzip2 +10 -0
  152. data/templates/cli/utility/config +32 -0
  153. data/templates/cli/utility/database/mongodb +18 -0
  154. data/templates/cli/utility/database/mysql +21 -0
  155. data/templates/cli/utility/database/postgresql +17 -0
  156. data/templates/cli/utility/database/redis +16 -0
  157. data/templates/cli/utility/database/riak +11 -0
  158. data/templates/cli/utility/encryptor/gpg +27 -0
  159. data/templates/cli/utility/encryptor/openssl +9 -0
  160. data/templates/cli/utility/model.erb +23 -0
  161. data/templates/cli/utility/notifier/campfire +12 -0
  162. data/templates/cli/utility/notifier/hipchat +15 -0
  163. data/templates/cli/utility/notifier/mail +22 -0
  164. data/templates/cli/utility/notifier/prowl +11 -0
  165. data/templates/cli/utility/notifier/pushover +11 -0
  166. data/templates/cli/utility/notifier/twitter +13 -0
  167. data/templates/cli/utility/splitter +7 -0
  168. data/templates/cli/utility/storage/cloud_files +22 -0
  169. data/templates/cli/utility/storage/dropbox +20 -0
  170. data/templates/cli/utility/storage/ftp +12 -0
  171. data/templates/cli/utility/storage/local +7 -0
  172. data/templates/cli/utility/storage/ninefold +9 -0
  173. data/templates/cli/utility/storage/rsync +11 -0
  174. data/templates/cli/utility/storage/s3 +19 -0
  175. data/templates/cli/utility/storage/scp +11 -0
  176. data/templates/cli/utility/storage/sftp +11 -0
  177. data/templates/cli/utility/syncer/cloud_files +46 -0
  178. data/templates/cli/utility/syncer/rsync_local +12 -0
  179. data/templates/cli/utility/syncer/rsync_pull +17 -0
  180. data/templates/cli/utility/syncer/rsync_push +17 -0
  181. data/templates/cli/utility/syncer/s3 +43 -0
  182. data/templates/general/links +11 -0
  183. data/templates/general/version.erb +2 -0
  184. data/templates/notifier/mail/failure.erb +9 -0
  185. data/templates/notifier/mail/success.erb +7 -0
  186. data/templates/notifier/mail/warning.erb +9 -0
  187. data/templates/storage/dropbox/authorization_url.erb +6 -0
  188. data/templates/storage/dropbox/authorized.erb +4 -0
  189. data/templates/storage/dropbox/cache_file_written.erb +10 -0
  190. metadata +277 -0
@@ -0,0 +1,255 @@
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
@@ -0,0 +1,35 @@
1
+ # encoding: utf-8
2
+
3
+ module Backup
4
+ module Compressor
5
+ class Base
6
+ include Backup::CLI::Helpers
7
+ include Backup::Configuration::Helpers
8
+
9
+ ##
10
+ # Yields to the block the compressor command and filename extension.
11
+ def compress_with
12
+ log!
13
+ yield @cmd, @ext
14
+ end
15
+
16
+ private
17
+
18
+ ##
19
+ # Return the compressor name, with Backup namespace removed
20
+ def compressor_name
21
+ self.class.to_s.sub('Backup::', '')
22
+ end
23
+
24
+ ##
25
+ # Logs a message to the console and log file to inform
26
+ # the client that Backup is using the compressor
27
+ def log!
28
+ Logger.message "Using #{ compressor_name } for compression.\n" +
29
+ " Command: '#{ @cmd }'\n" +
30
+ " Ext: '#{ @ext }'"
31
+ end
32
+
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,50 @@
1
+ # encoding: utf-8
2
+
3
+ module Backup
4
+ module Compressor
5
+ class Bzip2 < Base
6
+
7
+ ##
8
+ # Specify the level of compression to use.
9
+ #
10
+ # Values should be a single digit from 1 to 9.
11
+ # Note that setting the level to either extreme may or may not
12
+ # give the desired result. Be sure to check the documentation
13
+ # for the compressor being used.
14
+ #
15
+ # The default `level` is 9.
16
+ attr_accessor :level
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
+ ##
30
+ # Creates a new instance of Backup::Compressor::Bzip2
31
+ def initialize(&block)
32
+ load_defaults!
33
+
34
+ @level ||= false
35
+
36
+ instance_eval(&block) if block_given?
37
+
38
+ @cmd = "#{ utility(:bzip2) }#{ options }"
39
+ @ext = '.bz2'
40
+ end
41
+
42
+ private
43
+
44
+ def options
45
+ " -#{ @level }" if @level
46
+ end
47
+
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,53 @@
1
+ # encoding: utf-8
2
+
3
+ module Backup
4
+ module Compressor
5
+ class Custom < Base
6
+
7
+ ##
8
+ # Specify the system command to invoke a compressor,
9
+ # including any command-line arguments.
10
+ # e.g. @compressor.command = 'pbzip2 -p2 -4'
11
+ #
12
+ # The data to be compressed will be piped to the command's STDIN,
13
+ # and it should write the compressed data to STDOUT.
14
+ # i.e. `cat file.tar | %command% > file.tar.%extension%`
15
+ attr_accessor :command
16
+
17
+ ##
18
+ # File extension to append to the compressed file's filename.
19
+ # e.g. @compressor.extension = '.bz2'
20
+ attr_accessor :extension
21
+
22
+ ##
23
+ # Initializes a new custom compressor.
24
+ def initialize(&block)
25
+ load_defaults!
26
+
27
+ instance_eval(&block) if block_given?
28
+
29
+ @cmd = set_cmd
30
+ @ext = set_ext
31
+ end
32
+
33
+ private
34
+
35
+ ##
36
+ # Return the command line using the full path.
37
+ # Ensures the command exists and is executable.
38
+ def set_cmd
39
+ parts = @command.to_s.split(' ')
40
+ parts[0] = utility(parts[0])
41
+ parts.join(' ')
42
+ end
43
+
44
+ ##
45
+ # Return the extension given without whitespace.
46
+ # If extension was not set, return an empty string
47
+ def set_ext
48
+ @extension.to_s.strip
49
+ end
50
+
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,50 @@
1
+ # encoding: utf-8
2
+
3
+ module Backup
4
+ module Compressor
5
+ class Gzip < Base
6
+
7
+ ##
8
+ # Specify the level of compression to use.
9
+ #
10
+ # Values should be a single digit from 1 to 9.
11
+ # Note that setting the level to either extreme may or may not
12
+ # give the desired result. Be sure to check the documentation
13
+ # for the compressor being used.
14
+ #
15
+ # The default `level` is 6.
16
+ attr_accessor :level
17
+
18
+ attr_deprecate :fast, :version => '3.0.24',
19
+ :message => 'Use Gzip#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 Gzip#level instead.',
25
+ :action => lambda {|klass, val|
26
+ klass.level = 9 if val
27
+ }
28
+
29
+ ##
30
+ # Creates a new instance of Backup::Compressor::Gzip
31
+ def initialize(&block)
32
+ load_defaults!
33
+
34
+ @level ||= false
35
+
36
+ instance_eval(&block) if block_given?
37
+
38
+ @cmd = "#{ utility(:gzip) }#{ options }"
39
+ @ext = '.gz'
40
+ end
41
+
42
+ private
43
+
44
+ def options
45
+ " -#{ @level }" if @level
46
+ end
47
+
48
+ end
49
+ end
50
+ end