backup 3.0.23 → 3.0.24

Sign up to get free protection for your applications and to get access to all the features.
Files changed (197) hide show
  1. data/Gemfile.lock +42 -45
  2. data/Guardfile +7 -4
  3. data/README.md +10 -7
  4. data/backup.gemspec +2 -2
  5. data/lib/backup.rb +27 -97
  6. data/lib/backup/archive.rb +14 -6
  7. data/lib/backup/cli/helpers.rb +52 -49
  8. data/lib/backup/cli/utility.rb +9 -1
  9. data/lib/backup/compressor/base.rb +10 -4
  10. data/lib/backup/compressor/bzip2.rb +22 -26
  11. data/lib/backup/compressor/custom.rb +53 -0
  12. data/lib/backup/compressor/gzip.rb +22 -23
  13. data/lib/backup/compressor/lzma.rb +15 -13
  14. data/lib/backup/compressor/pbzip2.rb +20 -17
  15. data/lib/backup/config.rb +6 -3
  16. data/lib/backup/configuration.rb +33 -0
  17. data/lib/backup/configuration/helpers.rb +114 -28
  18. data/lib/backup/configuration/store.rb +24 -0
  19. data/lib/backup/database/base.rb +0 -6
  20. data/lib/backup/database/mongodb.rb +27 -11
  21. data/lib/backup/database/mysql.rb +19 -14
  22. data/lib/backup/database/postgresql.rb +16 -11
  23. data/lib/backup/database/redis.rb +7 -11
  24. data/lib/backup/database/riak.rb +3 -6
  25. data/lib/backup/dependency.rb +5 -11
  26. data/lib/backup/model.rb +14 -5
  27. data/lib/backup/notifier/campfire.rb +3 -16
  28. data/lib/backup/notifier/hipchat.rb +1 -7
  29. data/lib/backup/notifier/mail.rb +1 -1
  30. data/lib/backup/packager.rb +29 -19
  31. data/lib/backup/pipeline.rb +110 -0
  32. data/lib/backup/storage/dropbox.rb +4 -7
  33. data/lib/backup/syncer/base.rb +8 -4
  34. data/lib/backup/syncer/cloud/base.rb +247 -0
  35. data/lib/backup/syncer/cloud/cloud_files.rb +78 -0
  36. data/lib/backup/syncer/cloud/s3.rb +68 -0
  37. data/lib/backup/syncer/rsync/base.rb +1 -4
  38. data/lib/backup/syncer/rsync/local.rb +9 -5
  39. data/lib/backup/syncer/rsync/pull.rb +1 -1
  40. data/lib/backup/syncer/rsync/push.rb +10 -5
  41. data/lib/backup/version.rb +1 -1
  42. data/spec-live/.gitignore +6 -0
  43. data/spec-live/README +7 -0
  44. data/spec-live/backups/config.rb +153 -0
  45. data/spec-live/backups/config.yml.template +43 -0
  46. data/spec-live/compressor/custom_spec.rb +30 -0
  47. data/spec-live/compressor/gzip_spec.rb +30 -0
  48. data/spec-live/notifier/mail_spec.rb +85 -0
  49. data/spec-live/spec_helper.rb +85 -0
  50. data/spec-live/storage/dropbox_spec.rb +151 -0
  51. data/spec-live/storage/local_spec.rb +83 -0
  52. data/spec-live/storage/scp_spec.rb +193 -0
  53. data/spec-live/syncer/cloud/s3_spec.rb +124 -0
  54. data/spec/archive_spec.rb +86 -31
  55. data/spec/cleaner_spec.rb +8 -0
  56. data/spec/cli/helpers_spec.rb +200 -75
  57. data/spec/cli/utility_spec.rb +11 -3
  58. data/spec/compressor/base_spec.rb +31 -10
  59. data/spec/compressor/bzip2_spec.rb +212 -57
  60. data/spec/compressor/custom_spec.rb +106 -0
  61. data/spec/compressor/gzip_spec.rb +212 -57
  62. data/spec/compressor/lzma_spec.rb +75 -35
  63. data/spec/compressor/pbzip2_spec.rb +93 -52
  64. data/spec/configuration/helpers_spec.rb +406 -0
  65. data/spec/configuration/store_spec.rb +39 -0
  66. data/spec/configuration_spec.rb +62 -0
  67. data/spec/database/base_spec.rb +19 -10
  68. data/spec/database/mongodb_spec.rb +195 -70
  69. data/spec/database/mysql_spec.rb +183 -64
  70. data/spec/database/postgresql_spec.rb +167 -53
  71. data/spec/database/redis_spec.rb +121 -46
  72. data/spec/database/riak_spec.rb +96 -27
  73. data/spec/dependency_spec.rb +2 -0
  74. data/spec/encryptor/base_spec.rb +10 -0
  75. data/spec/encryptor/gpg_spec.rb +29 -13
  76. data/spec/encryptor/open_ssl_spec.rb +40 -21
  77. data/spec/logger_spec.rb +4 -0
  78. data/spec/model_spec.rb +19 -2
  79. data/spec/notifier/base_spec.rb +32 -17
  80. data/spec/notifier/campfire_spec.rb +63 -45
  81. data/spec/notifier/hipchat_spec.rb +79 -56
  82. data/spec/notifier/mail_spec.rb +82 -46
  83. data/spec/notifier/prowl_spec.rb +53 -32
  84. data/spec/notifier/twitter_spec.rb +62 -41
  85. data/spec/packager_spec.rb +95 -36
  86. data/spec/pipeline_spec.rb +259 -0
  87. data/spec/spec_helper.rb +6 -5
  88. data/spec/storage/base_spec.rb +61 -41
  89. data/spec/storage/cloudfiles_spec.rb +69 -45
  90. data/spec/storage/dropbox_spec.rb +158 -36
  91. data/spec/storage/ftp_spec.rb +69 -45
  92. data/spec/storage/local_spec.rb +47 -23
  93. data/spec/storage/ninefold_spec.rb +55 -31
  94. data/spec/storage/rsync_spec.rb +67 -50
  95. data/spec/storage/s3_spec.rb +65 -41
  96. data/spec/storage/scp_spec.rb +65 -41
  97. data/spec/storage/sftp_spec.rb +65 -41
  98. data/spec/syncer/base_spec.rb +91 -4
  99. data/spec/syncer/cloud/base_spec.rb +511 -0
  100. data/spec/syncer/cloud/cloud_files_spec.rb +181 -0
  101. data/spec/syncer/cloud/s3_spec.rb +174 -0
  102. data/spec/syncer/rsync/base_spec.rb +46 -66
  103. data/spec/syncer/rsync/local_spec.rb +55 -26
  104. data/spec/syncer/rsync/pull_spec.rb +15 -4
  105. data/spec/syncer/rsync/push_spec.rb +59 -52
  106. data/templates/cli/utility/compressor/bzip2 +1 -4
  107. data/templates/cli/utility/compressor/custom +11 -0
  108. data/templates/cli/utility/compressor/gzip +1 -4
  109. data/templates/cli/utility/compressor/lzma +3 -0
  110. data/templates/cli/utility/compressor/pbzip2 +3 -0
  111. data/templates/cli/utility/database/mysql +4 -1
  112. data/templates/cli/utility/syncer/cloud_files +17 -19
  113. data/templates/cli/utility/syncer/s3 +18 -20
  114. metadata +38 -92
  115. data/lib/backup/configuration/base.rb +0 -15
  116. data/lib/backup/configuration/compressor/base.rb +0 -9
  117. data/lib/backup/configuration/compressor/bzip2.rb +0 -23
  118. data/lib/backup/configuration/compressor/gzip.rb +0 -23
  119. data/lib/backup/configuration/compressor/lzma.rb +0 -23
  120. data/lib/backup/configuration/compressor/pbzip2.rb +0 -28
  121. data/lib/backup/configuration/database/base.rb +0 -19
  122. data/lib/backup/configuration/database/mongodb.rb +0 -49
  123. data/lib/backup/configuration/database/mysql.rb +0 -42
  124. data/lib/backup/configuration/database/postgresql.rb +0 -41
  125. data/lib/backup/configuration/database/redis.rb +0 -39
  126. data/lib/backup/configuration/database/riak.rb +0 -29
  127. data/lib/backup/configuration/encryptor/base.rb +0 -9
  128. data/lib/backup/configuration/encryptor/gpg.rb +0 -17
  129. data/lib/backup/configuration/encryptor/open_ssl.rb +0 -32
  130. data/lib/backup/configuration/notifier/base.rb +0 -28
  131. data/lib/backup/configuration/notifier/campfire.rb +0 -25
  132. data/lib/backup/configuration/notifier/hipchat.rb +0 -41
  133. data/lib/backup/configuration/notifier/mail.rb +0 -112
  134. data/lib/backup/configuration/notifier/presently.rb +0 -25
  135. data/lib/backup/configuration/notifier/prowl.rb +0 -23
  136. data/lib/backup/configuration/notifier/twitter.rb +0 -21
  137. data/lib/backup/configuration/storage/base.rb +0 -18
  138. data/lib/backup/configuration/storage/cloudfiles.rb +0 -25
  139. data/lib/backup/configuration/storage/dropbox.rb +0 -58
  140. data/lib/backup/configuration/storage/ftp.rb +0 -29
  141. data/lib/backup/configuration/storage/local.rb +0 -17
  142. data/lib/backup/configuration/storage/ninefold.rb +0 -20
  143. data/lib/backup/configuration/storage/rsync.rb +0 -29
  144. data/lib/backup/configuration/storage/s3.rb +0 -25
  145. data/lib/backup/configuration/storage/scp.rb +0 -25
  146. data/lib/backup/configuration/storage/sftp.rb +0 -25
  147. data/lib/backup/configuration/syncer/base.rb +0 -10
  148. data/lib/backup/configuration/syncer/cloud.rb +0 -23
  149. data/lib/backup/configuration/syncer/cloud_files.rb +0 -30
  150. data/lib/backup/configuration/syncer/rsync/base.rb +0 -28
  151. data/lib/backup/configuration/syncer/rsync/local.rb +0 -11
  152. data/lib/backup/configuration/syncer/rsync/pull.rb +0 -11
  153. data/lib/backup/configuration/syncer/rsync/push.rb +0 -31
  154. data/lib/backup/configuration/syncer/s3.rb +0 -23
  155. data/lib/backup/notifier/presently.rb +0 -88
  156. data/lib/backup/syncer/cloud.rb +0 -187
  157. data/lib/backup/syncer/cloud_files.rb +0 -56
  158. data/lib/backup/syncer/s3.rb +0 -47
  159. data/spec/configuration/base_spec.rb +0 -35
  160. data/spec/configuration/compressor/bzip2_spec.rb +0 -29
  161. data/spec/configuration/compressor/gzip_spec.rb +0 -29
  162. data/spec/configuration/compressor/lzma_spec.rb +0 -29
  163. data/spec/configuration/compressor/pbzip2_spec.rb +0 -32
  164. data/spec/configuration/database/base_spec.rb +0 -17
  165. data/spec/configuration/database/mongodb_spec.rb +0 -56
  166. data/spec/configuration/database/mysql_spec.rb +0 -53
  167. data/spec/configuration/database/postgresql_spec.rb +0 -53
  168. data/spec/configuration/database/redis_spec.rb +0 -50
  169. data/spec/configuration/database/riak_spec.rb +0 -35
  170. data/spec/configuration/encryptor/gpg_spec.rb +0 -26
  171. data/spec/configuration/encryptor/open_ssl_spec.rb +0 -35
  172. data/spec/configuration/notifier/base_spec.rb +0 -32
  173. data/spec/configuration/notifier/campfire_spec.rb +0 -32
  174. data/spec/configuration/notifier/hipchat_spec.rb +0 -44
  175. data/spec/configuration/notifier/mail_spec.rb +0 -71
  176. data/spec/configuration/notifier/presently_spec.rb +0 -35
  177. data/spec/configuration/notifier/prowl_spec.rb +0 -29
  178. data/spec/configuration/notifier/twitter_spec.rb +0 -35
  179. data/spec/configuration/storage/cloudfiles_spec.rb +0 -41
  180. data/spec/configuration/storage/dropbox_spec.rb +0 -38
  181. data/spec/configuration/storage/ftp_spec.rb +0 -44
  182. data/spec/configuration/storage/local_spec.rb +0 -29
  183. data/spec/configuration/storage/ninefold_spec.rb +0 -32
  184. data/spec/configuration/storage/rsync_spec.rb +0 -41
  185. data/spec/configuration/storage/s3_spec.rb +0 -38
  186. data/spec/configuration/storage/scp_spec.rb +0 -41
  187. data/spec/configuration/storage/sftp_spec.rb +0 -41
  188. data/spec/configuration/syncer/cloud_files_spec.rb +0 -44
  189. data/spec/configuration/syncer/rsync/base_spec.rb +0 -33
  190. data/spec/configuration/syncer/rsync/local_spec.rb +0 -10
  191. data/spec/configuration/syncer/rsync/pull_spec.rb +0 -10
  192. data/spec/configuration/syncer/rsync/push_spec.rb +0 -43
  193. data/spec/configuration/syncer/s3_spec.rb +0 -38
  194. data/spec/notifier/presently_spec.rb +0 -181
  195. data/spec/syncer/cloud_files_spec.rb +0 -192
  196. data/spec/syncer/s3_spec.rb +0 -192
  197. data/templates/cli/utility/notifier/presently +0 -13
@@ -187,9 +187,10 @@ module Backup
187
187
  ##
188
188
  # [Dependencies]
189
189
  # Returns a list of Backup's dependencies
190
- desc 'dependencies', 'Display the list of dependencies for Backup, or install them through Backup.'
190
+ desc 'dependencies', 'Display the list of dependencies for Backup, check the installation status, or install them through Backup.'
191
191
  method_option :install, :type => :string
192
192
  method_option :list, :type => :boolean
193
+ method_option :installed, :type => :string
193
194
  def dependencies
194
195
  unless options.any?
195
196
  puts
@@ -198,6 +199,9 @@ module Backup
198
199
  puts
199
200
  puts "To install one of these dependencies (with the correct version), run:\n\n"
200
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>"
201
205
  exit
202
206
  end
203
207
 
@@ -220,6 +224,10 @@ module Backup
220
224
  puts "Please wait..\n\n"
221
225
  puts %x[gem install #{options[:install]} -v '#{Backup::Dependency.all[options[:install]][:version]}']
222
226
  end
227
+
228
+ if options[:installed]
229
+ puts %x[gem list -i -v '#{Backup::Dependency.all[options[:installed]][:version]}' #{options[:installed]}]
230
+ end
223
231
  end
224
232
 
225
233
  ##
@@ -6,14 +6,17 @@ module Backup
6
6
  include Backup::CLI::Helpers
7
7
  include Backup::Configuration::Helpers
8
8
 
9
- def initialize
10
- load_defaults!
9
+ ##
10
+ # Yields to the block the compressor command and filename extension.
11
+ def compress_with
12
+ log!
13
+ yield @cmd, @ext
11
14
  end
12
15
 
13
16
  private
14
17
 
15
18
  ##
16
- # Return the encryptor name, with Backup namespace removed
19
+ # Return the compressor name, with Backup namespace removed
17
20
  def compressor_name
18
21
  self.class.to_s.sub('Backup::', '')
19
22
  end
@@ -22,8 +25,11 @@ module Backup
22
25
  # Logs a message to the console and log file to inform
23
26
  # the client that Backup is using the compressor
24
27
  def log!
25
- Logger.message "Using #{ compressor_name } for compression."
28
+ Logger.message "Using #{ compressor_name } for compression.\n" +
29
+ " Command: '#{ @cmd }'\n" +
30
+ " Ext: '#{ @ext }'"
26
31
  end
32
+
27
33
  end
28
34
  end
29
35
  end
@@ -5,44 +5,40 @@ module Backup
5
5
  class Bzip2 < Base
6
6
 
7
7
  ##
8
- # Tells Backup::Compressor::Bzip2 to compress
9
- # better (-9) rather than faster when set to true
10
- attr_accessor :best
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
+ :replacement => :level,
20
+ :value => lambda {|val| val ? 1 : nil }
21
+ attr_deprecate :best, :version => '3.0.24',
22
+ :replacement => :level,
23
+ :value => lambda {|val| val ? 9 : nil }
11
24
 
12
25
  ##
13
- # Tells Backup::Compressor::Bzip2 to compress
14
- # faster (-1) rather than better when set to true
15
- attr_accessor :fast
16
-
17
- ##
18
- # Creates a new instance of Backup::Compressor::Bzip2 and
19
- # configures it to either compress faster or better
20
- # bzip2 compresses by default with -9 (best compression)
21
- # and lower block sizes don't make things significantly faster
22
- # (according to official bzip2 docs)
26
+ # Creates a new instance of Backup::Compressor::Bzip2
23
27
  def initialize(&block)
24
- super
28
+ load_defaults!
25
29
 
26
- @best ||= false
27
- @fast ||= false
30
+ @level ||= false
28
31
 
29
32
  instance_eval(&block) if block_given?
30
- end
31
33
 
32
- ##
33
- # Yields to the block the compressor command with options
34
- # and it's filename extension.
35
- def compress_with
36
- log!
37
- yield "#{ utility(:bzip2) }#{ options }", '.bz2'
34
+ @cmd = "#{ utility(:bzip2) }#{ options }"
35
+ @ext = '.bz2'
38
36
  end
39
37
 
40
38
  private
41
39
 
42
- ##
43
- # Returns the option syntax for compressing
44
40
  def options
45
- " #{ '--best ' if @best }#{ '--fast' if @fast }".rstrip
41
+ " -#{ @level }" if @level
46
42
  end
47
43
 
48
44
  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
@@ -5,41 +5,40 @@ module Backup
5
5
  class Gzip < Base
6
6
 
7
7
  ##
8
- # Tells Backup::Compressor::Gzip to compress
9
- # better rather than faster when set to true
10
- attr_accessor :best
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
+ :replacement => :level,
20
+ :value => lambda {|val| val ? 1 : nil }
21
+ attr_deprecate :best, :version => '3.0.24',
22
+ :replacement => :level,
23
+ :value => lambda {|val| val ? 9 : nil }
11
24
 
12
25
  ##
13
- # Tells Backup::Compressor::Gzip to compress
14
- # faster rather than better when set to true
15
- attr_accessor :fast
16
-
17
- ##
18
- # Creates a new instance of Backup::Compressor::Gzip and
19
- # configures it to either compress faster or better
26
+ # Creates a new instance of Backup::Compressor::Gzip
20
27
  def initialize(&block)
21
- super
28
+ load_defaults!
22
29
 
23
- @best ||= false
24
- @fast ||= false
30
+ @level ||= false
25
31
 
26
32
  instance_eval(&block) if block_given?
27
- end
28
33
 
29
- ##
30
- # Yields to the block the compressor command with options
31
- # and it's filename extension.
32
- def compress_with
33
- log!
34
- yield "#{ utility(:gzip) }#{ options }", '.gz'
34
+ @cmd = "#{ utility(:gzip) }#{ options }"
35
+ @ext = '.gz'
35
36
  end
36
37
 
37
38
  private
38
39
 
39
- ##
40
- # Returns the gzip option syntax for compressing
41
40
  def options
42
- " #{ '--best ' if @best }#{ '--fast' if @fast }".rstrip
41
+ " -#{ @level }" if @level
43
42
  end
44
43
 
45
44
  end
@@ -15,34 +15,36 @@ module Backup
15
15
  attr_accessor :fast
16
16
 
17
17
  ##
18
- # Creates a new instance of Backup::Compressor::Lzma and
19
- # configures it to either compress faster or better
20
- # Lzma compresses by default with -9 (best compression)
21
- # and lower block sizes don't make things significantly faster
22
- # (according to official bzip2 docs)
18
+ # Creates a new instance of Backup::Compressor::Lzma
23
19
  def initialize(&block)
24
- super
20
+ load_defaults!
25
21
 
26
22
  @best ||= false
27
23
  @fast ||= false
28
24
 
29
25
  instance_eval(&block) if block_given?
26
+
27
+ @cmd = "#{ utility(:lzma) }#{ options }"
28
+ @ext = '.lzma'
30
29
  end
31
30
 
31
+
32
32
  ##
33
- # Yields to the block the compressor command with options
34
- # and it's filename extension.
33
+ # Yields to the block the compressor command and filename extension.
35
34
  def compress_with
36
- log!
37
- yield "#{ utility(:lzma) }#{ options }", '.lzma'
35
+ Backup::Logger.warn(
36
+ "[DEPRECATION WARNING]\n" +
37
+ " Compressor::Lzma is being deprecated as of backup v.3.0.24\n" +
38
+ " and will soon be removed. Please see the Compressors wiki page at\n" +
39
+ " https://github.com/meskyanichi/backup/wiki/Compressors"
40
+ )
41
+ super
38
42
  end
39
43
 
40
44
  private
41
45
 
42
- ##
43
- # Returns the option syntax for compressing
44
46
  def options
45
- " #{ '--best ' if @best }#{ '--fast' if @fast }".rstrip
47
+ (' --best' if @best) || (' --fast' if @fast)
46
48
  end
47
49
 
48
50
  end
@@ -5,50 +5,53 @@ module Backup
5
5
  class Pbzip2 < Base
6
6
 
7
7
  ##
8
- # Tells Backup::Compressor::Pbzip2 to compress
8
+ # Tells Backup::Compressor::Lzma to compress
9
9
  # better (-9) rather than faster when set to true
10
10
  attr_accessor :best
11
11
 
12
12
  ##
13
- # Tells Backup::Compressor::Pbzip2 to compress
13
+ # Tells Backup::Compressor::Lzma to compress
14
14
  # faster (-1) rather than better when set to true
15
15
  attr_accessor :fast
16
16
 
17
17
  ##
18
- # Tells Backup::Compressor::Pbzip2 how many processors
19
- # use, by default autodetect is used
18
+ # Tells Backup::Compressor::Pbzip2 how many processors to use.
19
+ # Autodetects the number of active CPUs by default.
20
20
  attr_accessor :processors
21
21
 
22
22
  ##
23
- # Creates a new instance of Backup::Compressor::Pbzip2 and
24
- # configures it to either compress faster or better
25
- # bzip2 compresses by default with -9 (best compression)
26
- # and lower block sizes don't make things significantly faster
27
- # (according to official bzip2 docs)
23
+ # Creates a new instance of Backup::Compressor::Pbzip2
28
24
  def initialize(&block)
29
- super
25
+ load_defaults!
30
26
 
31
27
  @best ||= false
32
28
  @fast ||= false
33
29
  @processors ||= false
34
30
 
35
31
  instance_eval(&block) if block_given?
32
+
33
+ @cmd = "#{ utility(:pbzip2) }#{ options }"
34
+ @ext = '.bz2'
36
35
  end
37
36
 
38
37
  ##
39
- # Yields to the block the compressor command with options
40
- # and it's filename extension.
38
+ # Yields to the block the compressor command and filename extension.
41
39
  def compress_with
42
- log!
43
- yield "#{ utility(:pbzip2) }#{ options }", '.bz2'
40
+ Backup::Logger.warn(
41
+ "[DEPRECATION WARNING]\n" +
42
+ " Compressor::Pbzip2 is being deprecated as of backup v.3.0.24\n" +
43
+ " and will soon be removed. Please see the Compressors wiki page at\n" +
44
+ " https://github.com/meskyanichi/backup/wiki/Compressors"
45
+ )
46
+ super
44
47
  end
45
48
 
46
49
  private
47
50
 
48
- ##
49
- # Returns the gzip option syntax for compressing
50
51
  def options
51
- " #{ '--best ' if @best }#{ '--fast ' if @fast }#{ "-p#{@processors}" if @processors }".rstrip
52
+ level = (' --best' if @best) || (' --fast' if @fast)
53
+ cpus = " -p#{ @processors }" if @processors
54
+ "#{ level }#{ cpus }"
52
55
  end
53
56
 
54
57
  end
data/lib/backup/config.rb CHANGED
@@ -107,13 +107,16 @@ module Backup
107
107
  ['S3', 'CloudFiles', 'Ninefold', 'Dropbox', 'FTP',
108
108
  'SFTP', 'SCP', 'RSync', 'Local'],
109
109
  # Compressors
110
- ['Gzip', 'Bzip2', 'Pbzip2', 'Lzma'],
110
+ ['Gzip', 'Bzip2', 'Custom', 'Pbzip2', 'Lzma'],
111
111
  # Encryptors
112
112
  ['OpenSSL', 'GPG'],
113
113
  # Syncers
114
- ['Rackspace', 'S3', { 'RSync' => ['Push', 'Pull', 'Local'] }],
114
+ [
115
+ { 'Cloud' => ['CloudFiles', 'S3'] },
116
+ { 'RSync' => ['Push', 'Pull', 'Local'] }
117
+ ],
115
118
  # Notifiers
116
- ['Mail', 'Twitter', 'Campfire', 'Presently', 'Prowl', 'Hipchat']
119
+ ['Mail', 'Twitter', 'Campfire', 'Prowl', 'Hipchat']
117
120
  ]
118
121
  )
119
122
  end
@@ -0,0 +1,33 @@
1
+ # encoding: utf-8
2
+
3
+ %w[helpers store].each do |file|
4
+ require File.expand_path("../configuration/#{file}", __FILE__)
5
+ end
6
+
7
+ # Temporary measure for deprecating the use of Configuration
8
+ # namespaced classes for setting pre-configured defaults.
9
+ module Backup
10
+ module Configuration
11
+ extend self
12
+
13
+ ##
14
+ # Pass calls on to the proper class and log a warning
15
+ def defaults(&block)
16
+ klass = eval(self.to_s.sub('Configuration::', ''))
17
+ Logger.warn Errors::ConfigurationError.new <<-EOS
18
+ [DEPRECATION WARNING]
19
+ #{ self }.defaults is being deprecated.
20
+ To set pre-configured defaults for #{ klass }, use:
21
+ #{ klass }.defaults
22
+ EOS
23
+ klass.defaults(&block)
24
+ end
25
+
26
+ private
27
+
28
+ def const_missing(const)
29
+ const_set(const, Module.new { extend Configuration })
30
+ end
31
+
32
+ end
33
+ end
@@ -4,47 +4,133 @@ module Backup
4
4
  module Configuration
5
5
  module Helpers
6
6
 
7
- ##
8
- # Finds all the object's getter methods and checks the global
9
- # configuration for these methods, if they respond then they will
10
- # assign the object's attribute(s) to that particular global configuration's attribute
11
- def load_defaults!
12
- module_names = self.class.name.split('::')[1..-1]
13
- configuration = Backup::Configuration
14
- module_names.each do |module_name|
15
- configuration = configuration.const_get(module_name)
7
+ def self.included(klass)
8
+ klass.extend ClassMethods
9
+ end
10
+
11
+ module ClassMethods
12
+
13
+ ##
14
+ # Returns or yields the Configuration::Store
15
+ # for storing pre-configured defaults for the class.
16
+ def defaults
17
+ @configuration ||= Configuration::Store.new
18
+
19
+ if block_given?
20
+ yield @configuration
21
+ else
22
+ @configuration
23
+ end
24
+ end
25
+
26
+ ##
27
+ # Used only within the specs
28
+ def clear_defaults!
29
+ defaults.reset!
16
30
  end
17
31
 
18
- getter_methods.each do |attribute|
19
- if configuration.respond_to?(attribute)
20
- self.send("#{attribute}=", configuration.send(attribute))
32
+ def deprecations
33
+ @deprecations ||= {}
34
+ end
35
+
36
+ def log_deprecation_warning(name, deprecation)
37
+ msg = "#{ self }.#{ name } has been deprecated as of " +
38
+ "backup v.#{ deprecation[:version] }"
39
+ if replacement = deprecation[:replacement]
40
+ msg << "\nThis setting has been replaced with:\n" +
41
+ "#{ self }.#{ replacement }"
21
42
  end
43
+ Logger.warn Backup::Errors::ConfigurationError.new <<-EOS
44
+ [DEPRECATION WARNING]
45
+ #{ msg }
46
+ EOS
22
47
  end
23
- end
24
48
 
25
- ##
26
- # Clears all the defaults that may have been set by the user
27
- def clear_defaults!
28
- setter_methods.each do |method|
29
- self.send(method, nil)
49
+ protected
50
+
51
+ ##
52
+ # Method to deprecate an attribute.
53
+ #
54
+ # :version should be set to the backup version which will first
55
+ # introduce the deprecation.
56
+ # :replacement may be set to another attr_accessor name to set
57
+ # the value for instead of the deprecated accessor
58
+ # :value may be used to specify the value set on :replacement.
59
+ # If :value is nil, the value set on the deprecated accessor
60
+ # will be used to set the value for the :replacement.
61
+ # If :value is a lambda, it will be passed the value the user
62
+ # set on the deprecated accessor, and should return the value
63
+ # to be set on the :replacement.
64
+ # Therefore, to cause the replacement accessor not to be set,
65
+ # use the lambda form to return nil. This is only way to specify
66
+ # a :replacement without transferring a value.
67
+ # e.g. :replacement => :new_attr, :value => Proc.new {}
68
+ def attr_deprecate(name, args = {})
69
+ deprecations[name] = {
70
+ :version => nil,
71
+ :replacement => nil,
72
+ :value => nil
73
+ }.merge(args)
30
74
  end
31
- end
75
+
76
+ end # ClassMethods
32
77
 
33
78
  private
34
79
 
35
80
  ##
36
- # Returns an Array of the setter methods (as String)
37
- def setter_methods
38
- methods.map do |method|
39
- method = method.to_s
40
- method if method =~ /^\w(\w|\d|\_)+\=$/ and method != 'taguri='
41
- end.compact
81
+ # Sets any pre-configured default values.
82
+ # If a default value was set for an invalid accessor,
83
+ # this will raise a NameError.
84
+ def load_defaults!
85
+ configuration = self.class.defaults
86
+ configuration._attributes.each do |name|
87
+ send(:"#{ name }=", configuration.send(name))
88
+ end
42
89
  end
43
90
 
44
91
  ##
45
- # Returns an Array of getter methods (as String)
46
- def getter_methods
47
- setter_methods.map {|method| method.sub('=','') }
92
+ # Check missing methods for deprecations
93
+ #
94
+ # Note that OpenStruct (used for setting defaults) does not allow
95
+ # multiple arguments when assigning values for members.
96
+ # So, we won't allow it here either, even though an attr_accessor
97
+ # will accept and convert them into an Array. Therefore, setting
98
+ # an option value using multiple values, whether as a default or
99
+ # directly on the class' accessor, should not be supported.
100
+ # i.e. if an option will accept being set as an Array, then it
101
+ # should be explicitly set as such. e.g. option = [val1, val2]
102
+ def method_missing(name, *args)
103
+ deprecation = nil
104
+ if method = name.to_s.chomp!('=')
105
+ if (len = args.count) != 1
106
+ raise ArgumentError,
107
+ "wrong number of arguments (#{ len } for 1)", caller(1)
108
+ end
109
+ deprecation = self.class.deprecations[method.to_sym]
110
+ end
111
+
112
+ if deprecation
113
+ self.class.log_deprecation_warning(method, deprecation)
114
+ if replacement = deprecation[:replacement]
115
+ value =
116
+ case deprecation[:value]
117
+ when nil
118
+ args[0]
119
+ when Proc
120
+ deprecation[:value].call(args[0])
121
+ else
122
+ deprecation[:value]
123
+ end
124
+ unless value.nil?
125
+ Logger.warn(
126
+ "#{ self.class }.#{ replacement } is being set to '#{ value }'"
127
+ )
128
+ send(:"#{ replacement }=", value)
129
+ end
130
+ end
131
+ else
132
+ super
133
+ end
48
134
  end
49
135
 
50
136
  end