backup 3.0.19 → 3.0.20

Sign up to get free protection for your applications and to get access to all the features.
Files changed (188) hide show
  1. data/.gitignore +4 -0
  2. data/Gemfile +9 -8
  3. data/Gemfile.lock +19 -1
  4. data/Guardfile +13 -9
  5. data/README.md +93 -31
  6. data/backup.gemspec +3 -3
  7. data/bin/backup +6 -283
  8. data/lib/backup.rb +101 -72
  9. data/lib/backup/archive.rb +21 -9
  10. data/lib/backup/binder.rb +22 -0
  11. data/lib/backup/cleaner.rb +36 -0
  12. data/lib/backup/cli/helpers.rb +103 -0
  13. data/lib/backup/cli/utility.rb +308 -0
  14. data/lib/backup/compressor/base.rb +2 -2
  15. data/lib/backup/compressor/pbzip2.rb +76 -0
  16. data/lib/backup/configuration/compressor/pbzip2.rb +28 -0
  17. data/lib/backup/configuration/database/riak.rb +25 -0
  18. data/lib/backup/configuration/encryptor/open_ssl.rb +6 -0
  19. data/lib/backup/configuration/helpers.rb +5 -18
  20. data/lib/backup/configuration/notifier/base.rb +13 -0
  21. data/lib/backup/configuration/notifier/hipchat.rb +41 -0
  22. data/lib/backup/configuration/notifier/mail.rb +38 -0
  23. data/lib/backup/configuration/notifier/prowl.rb +23 -0
  24. data/lib/backup/configuration/storage/cloudfiles.rb +4 -0
  25. data/lib/backup/configuration/storage/dropbox.rb +8 -4
  26. data/lib/backup/database/base.rb +10 -2
  27. data/lib/backup/database/mongodb.rb +16 -19
  28. data/lib/backup/database/mysql.rb +2 -2
  29. data/lib/backup/database/postgresql.rb +2 -2
  30. data/lib/backup/database/redis.rb +15 -7
  31. data/lib/backup/database/riak.rb +45 -0
  32. data/lib/backup/dependency.rb +21 -7
  33. data/lib/backup/encryptor/base.rb +1 -1
  34. data/lib/backup/encryptor/open_ssl.rb +20 -5
  35. data/lib/backup/errors.rb +124 -0
  36. data/lib/backup/finder.rb +11 -3
  37. data/lib/backup/logger.rb +121 -82
  38. data/lib/backup/model.rb +103 -44
  39. data/lib/backup/notifier/base.rb +50 -0
  40. data/lib/backup/notifier/campfire.rb +32 -52
  41. data/lib/backup/notifier/hipchat.rb +99 -0
  42. data/lib/backup/notifier/mail.rb +100 -61
  43. data/lib/backup/notifier/presently.rb +31 -40
  44. data/lib/backup/notifier/prowl.rb +73 -0
  45. data/lib/backup/notifier/twitter.rb +29 -39
  46. data/lib/backup/packager.rb +25 -0
  47. data/lib/backup/splitter.rb +62 -0
  48. data/lib/backup/storage/base.rb +178 -18
  49. data/lib/backup/storage/cloudfiles.rb +34 -28
  50. data/lib/backup/storage/dropbox.rb +64 -67
  51. data/lib/backup/storage/ftp.rb +48 -40
  52. data/lib/backup/storage/local.rb +33 -28
  53. data/lib/backup/storage/ninefold.rb +40 -26
  54. data/lib/backup/storage/object.rb +8 -6
  55. data/lib/backup/storage/rsync.rb +61 -51
  56. data/lib/backup/storage/s3.rb +29 -27
  57. data/lib/backup/storage/scp.rb +56 -36
  58. data/lib/backup/storage/sftp.rb +49 -33
  59. data/lib/backup/syncer/base.rb +1 -1
  60. data/lib/backup/syncer/rsync.rb +1 -1
  61. data/lib/backup/template.rb +46 -0
  62. data/lib/backup/version.rb +1 -1
  63. data/spec/archive_spec.rb +34 -9
  64. data/spec/backup_spec.rb +1 -1
  65. data/spec/cli/helpers_spec.rb +35 -0
  66. data/spec/cli/utility_spec.rb +38 -0
  67. data/spec/compressor/bzip2_spec.rb +1 -1
  68. data/spec/compressor/gzip_spec.rb +1 -1
  69. data/spec/compressor/lzma_spec.rb +1 -1
  70. data/spec/compressor/pbzip2_spec.rb +63 -0
  71. data/spec/configuration/base_spec.rb +1 -1
  72. data/spec/configuration/compressor/bzip2_spec.rb +1 -1
  73. data/spec/configuration/compressor/gzip_spec.rb +1 -1
  74. data/spec/configuration/compressor/lzma_spec.rb +1 -1
  75. data/spec/configuration/database/base_spec.rb +1 -1
  76. data/spec/configuration/database/mongodb_spec.rb +1 -1
  77. data/spec/configuration/database/mysql_spec.rb +1 -1
  78. data/spec/configuration/database/postgresql_spec.rb +1 -1
  79. data/spec/configuration/database/redis_spec.rb +1 -1
  80. data/spec/configuration/database/riak_spec.rb +31 -0
  81. data/spec/configuration/encryptor/gpg_spec.rb +1 -1
  82. data/spec/configuration/encryptor/open_ssl_spec.rb +4 -1
  83. data/spec/configuration/notifier/campfire_spec.rb +1 -1
  84. data/spec/configuration/notifier/hipchat_spec.rb +43 -0
  85. data/spec/configuration/notifier/mail_spec.rb +34 -22
  86. data/spec/configuration/notifier/presently_spec.rb +1 -1
  87. data/spec/configuration/notifier/prowl_spec.rb +28 -0
  88. data/spec/configuration/notifier/twitter_spec.rb +1 -1
  89. data/spec/configuration/storage/cloudfiles_spec.rb +19 -16
  90. data/spec/configuration/storage/dropbox_spec.rb +1 -1
  91. data/spec/configuration/storage/ftp_spec.rb +1 -1
  92. data/spec/configuration/storage/local_spec.rb +1 -1
  93. data/spec/configuration/storage/ninefold_spec.rb +1 -1
  94. data/spec/configuration/storage/rsync_spec.rb +1 -1
  95. data/spec/configuration/storage/s3_spec.rb +1 -1
  96. data/spec/configuration/storage/scp_spec.rb +1 -1
  97. data/spec/configuration/storage/sftp_spec.rb +1 -1
  98. data/spec/configuration/syncer/rsync_spec.rb +1 -1
  99. data/spec/configuration/syncer/s3_spec.rb +1 -1
  100. data/spec/database/base_spec.rb +10 -1
  101. data/spec/database/mongodb_spec.rb +34 -7
  102. data/spec/database/mysql_spec.rb +8 -7
  103. data/spec/database/postgresql_spec.rb +8 -7
  104. data/spec/database/redis_spec.rb +39 -9
  105. data/spec/database/riak_spec.rb +50 -0
  106. data/spec/encryptor/gpg_spec.rb +1 -1
  107. data/spec/encryptor/open_ssl_spec.rb +77 -20
  108. data/spec/errors_spec.rb +306 -0
  109. data/spec/finder_spec.rb +91 -0
  110. data/spec/logger_spec.rb +254 -33
  111. data/spec/model_spec.rb +120 -15
  112. data/spec/notifier/campfire_spec.rb +127 -52
  113. data/spec/notifier/hipchat_spec.rb +193 -0
  114. data/spec/notifier/mail_spec.rb +290 -74
  115. data/spec/notifier/presently_spec.rb +290 -73
  116. data/spec/notifier/prowl_spec.rb +149 -0
  117. data/spec/notifier/twitter_spec.rb +106 -41
  118. data/spec/spec_helper.rb +8 -2
  119. data/spec/splitter_spec.rb +71 -0
  120. data/spec/storage/base_spec.rb +280 -19
  121. data/spec/storage/cloudfiles_spec.rb +38 -22
  122. data/spec/storage/dropbox_spec.rb +17 -13
  123. data/spec/storage/ftp_spec.rb +145 -55
  124. data/spec/storage/local_spec.rb +6 -6
  125. data/spec/storage/ninefold_spec.rb +70 -29
  126. data/spec/storage/object_spec.rb +44 -44
  127. data/spec/storage/rsync_spec.rb +186 -63
  128. data/spec/storage/s3_spec.rb +23 -24
  129. data/spec/storage/scp_spec.rb +116 -41
  130. data/spec/storage/sftp_spec.rb +124 -46
  131. data/spec/syncer/rsync_spec.rb +3 -3
  132. data/spec/syncer/s3_spec.rb +1 -1
  133. data/spec/version_spec.rb +1 -1
  134. data/templates/cli/utility/archive +13 -0
  135. data/{lib/templates → templates/cli/utility}/compressor/bzip2 +1 -1
  136. data/{lib/templates → templates/cli/utility}/compressor/gzip +1 -1
  137. data/{lib/templates → templates/cli/utility}/compressor/lzma +0 -0
  138. data/templates/cli/utility/compressor/pbzip2 +7 -0
  139. data/templates/cli/utility/config +31 -0
  140. data/{lib/templates → templates/cli/utility}/database/mongodb +1 -1
  141. data/{lib/templates → templates/cli/utility}/database/mysql +1 -1
  142. data/{lib/templates → templates/cli/utility}/database/postgresql +1 -1
  143. data/{lib/templates → templates/cli/utility}/database/redis +1 -1
  144. data/templates/cli/utility/database/riak +8 -0
  145. data/{lib/templates → templates/cli/utility}/encryptor/gpg +1 -1
  146. data/templates/cli/utility/encryptor/openssl +9 -0
  147. data/templates/cli/utility/model.erb +23 -0
  148. data/{lib/templates → templates/cli/utility}/notifier/campfire +2 -1
  149. data/templates/cli/utility/notifier/hipchat +15 -0
  150. data/{lib/templates → templates/cli/utility}/notifier/mail +6 -1
  151. data/{lib/templates → templates/cli/utility}/notifier/presently +1 -0
  152. data/templates/cli/utility/notifier/prowl +11 -0
  153. data/{lib/templates → templates/cli/utility}/notifier/twitter +2 -1
  154. data/templates/cli/utility/splitter +7 -0
  155. data/templates/cli/utility/storage/cloudfiles +12 -0
  156. data/{lib/templates → templates/cli/utility}/storage/dropbox +1 -1
  157. data/{lib/templates → templates/cli/utility}/storage/ftp +0 -0
  158. data/templates/cli/utility/storage/local +7 -0
  159. data/{lib/templates → templates/cli/utility}/storage/ninefold +1 -1
  160. data/templates/cli/utility/storage/rsync +11 -0
  161. data/{lib/templates → templates/cli/utility}/storage/s3 +0 -2
  162. data/templates/cli/utility/storage/scp +11 -0
  163. data/templates/cli/utility/storage/sftp +11 -0
  164. data/{lib/templates → templates/cli/utility}/syncer/rsync +1 -1
  165. data/{lib/templates → templates/cli/utility}/syncer/s3 +1 -1
  166. data/templates/general/links +11 -0
  167. data/templates/general/version.erb +2 -0
  168. data/templates/notifier/mail/failure.erb +9 -0
  169. data/templates/notifier/mail/success.erb +7 -0
  170. data/templates/notifier/mail/warning.erb +9 -0
  171. data/templates/storage/dropbox/authorization_url.erb +6 -0
  172. data/templates/storage/dropbox/authorized.erb +4 -0
  173. data/templates/storage/dropbox/cache_file_written.erb +10 -0
  174. metadata +81 -45
  175. data/lib/backup/cli.rb +0 -110
  176. data/lib/backup/exception/command_failed.rb +0 -8
  177. data/lib/backup/exception/command_not_found.rb +0 -8
  178. data/lib/backup/notifier/binder.rb +0 -32
  179. data/lib/backup/notifier/templates/notify_failure.erb +0 -33
  180. data/lib/backup/notifier/templates/notify_success.erb +0 -16
  181. data/lib/templates/archive +0 -7
  182. data/lib/templates/encryptor/openssl +0 -8
  183. data/lib/templates/readme +0 -15
  184. data/lib/templates/storage/cloudfiles +0 -11
  185. data/lib/templates/storage/local +0 -7
  186. data/lib/templates/storage/rsync +0 -11
  187. data/lib/templates/storage/scp +0 -11
  188. data/lib/templates/storage/sftp +0 -11
@@ -3,14 +3,14 @@
3
3
  module Backup
4
4
  module Compressor
5
5
  class Base
6
- include Backup::CLI
6
+ include Backup::CLI::Helpers
7
7
  include Backup::Configuration::Helpers
8
8
 
9
9
  ##
10
10
  # Logs a message to the console and log file to inform
11
11
  # the client that Backup is compressing the archive
12
12
  def log!
13
- Backup::Logger.message "#{ self.class } started compressing the archive."
13
+ Logger.message "#{ self.class } started compressing the archive."
14
14
  end
15
15
  end
16
16
  end
@@ -0,0 +1,76 @@
1
+ # encoding: utf-8
2
+
3
+ module Backup
4
+ module Compressor
5
+ class Pbzip2 < Base
6
+
7
+ ##
8
+ # Tells Backup::Compressor::Pbzip2 to compress
9
+ # better (-9) rather than faster when set to true
10
+ attr_writer :best
11
+
12
+ ##
13
+ # Tells Backup::Compressor::Pbzip2 to compress
14
+ # faster (-1) rather than better when set to true
15
+ attr_writer :fast
16
+
17
+ ##
18
+ # Tells Backup::Compressor::Pbzip2 how many processors
19
+ # use, by default autodetect is used
20
+ attr_writer :processors
21
+
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)
28
+ def initialize(&block)
29
+ load_defaults!
30
+
31
+ @best ||= false
32
+ @fast ||= false
33
+ @processors ||= nil
34
+
35
+ instance_eval(&block) if block_given?
36
+ end
37
+
38
+ ##
39
+ # Performs the compression of the packages backup file
40
+ def perform!
41
+ log!
42
+ run("#{ utility(:pbzip2) } #{ options } '#{ Backup::Model.file }'")
43
+ Backup::Model.extension += '.bz2'
44
+ end
45
+
46
+ private
47
+
48
+ ##
49
+ # Combines the provided options and returns a pbzip2 options string
50
+ def options
51
+ (best + fast + processors).join("\s")
52
+ end
53
+
54
+ ##
55
+ # Returns the pbzip2 option syntax for compressing
56
+ # setting @best to true is redundant, as pbzip2 compresses best by default
57
+ def best
58
+ return ['--best'] if @best; []
59
+ end
60
+
61
+ ##
62
+ # Returns the pbzip2 option syntax for compressing
63
+ # (not significantly) faster when @fast is set to true
64
+ def fast
65
+ return ['--fast'] if @fast; []
66
+ end
67
+
68
+ ##
69
+ # Returns the pbzip2 option syntax for compressing
70
+ # using given count of cpus
71
+ def processors
72
+ return ['-p' + @processors.to_s] if @processors; []
73
+ end
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,28 @@
1
+ # encoding: utf-8
2
+
3
+ module Backup
4
+ module Configuration
5
+ module Compressor
6
+ class Pbzip2 < Base
7
+ class << self
8
+
9
+ ##
10
+ # Tells Backup::Compressor::Pbzip2 to compress
11
+ # better (-9) which is bzip2 default anyway
12
+ attr_accessor :best
13
+
14
+ ##
15
+ # Tells Backup::Compressor::Pbzip2 to compress
16
+ # faster (-1) (but not significantly faster)
17
+ attr_accessor :fast
18
+
19
+ ##
20
+ # Tells Backup::Compressor::Pbzip2 how many processors
21
+ # use, by default autodetect is used
22
+ attr_writer :processors
23
+
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,25 @@
1
+ # encoding: utf-8
2
+
3
+ module Backup
4
+ module Configuration
5
+ module Database
6
+ class Riak < Base
7
+ class << self
8
+
9
+ ##
10
+ # Name is the name of the backup
11
+ attr_accessor :name
12
+
13
+ ##
14
+ # Node is the node from which to perform the backup.
15
+ attr_accessor :node
16
+
17
+ ##
18
+ # Cookie is the Erlang cookie/shared secret used to connect to the node.
19
+ attr_accessor :cookie
20
+
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -10,6 +10,12 @@ module Backup
10
10
  # The password that'll be used to encrypt the backup. This
11
11
  # password will be required to decrypt the backup later on.
12
12
  attr_accessor :password
13
+
14
+ ##
15
+ # The password file used for encrypting the backup. This
16
+ # password file will be required to decrypt the backup later
17
+ # on.
18
+ attr_accessor :password_file
13
19
 
14
20
  ##
15
21
  # Determines whether the 'base64' should be used or not
@@ -8,21 +8,13 @@ module Backup
8
8
  # Finds all the object's getter methods and checks the global
9
9
  # configuration for these methods, if they respond then they will
10
10
  # assign the object's attribute(s) to that particular global configuration's attribute
11
- def load_defaults!(options = {})
11
+ def load_defaults!
12
12
  c = self.class.name.split('::')
13
13
  configuration = Backup::Configuration.const_get(c[1]).const_get(c[2])
14
- options[:except] ||= []
15
- options[:only] ||= []
16
14
 
17
15
  getter_methods.each do |attribute|
18
16
  if configuration.respond_to?(attribute)
19
- if options[:only].any? and options[:only].include?(attribute)
20
- self.send("#{attribute}=", configuration.send(attribute))
21
- elsif options[:except].any? and !options[:except].include?(attribute)
22
- self.send("#{attribute}=", configuration.send(attribute))
23
- elsif options[:only].empty? and options[:except].empty?
24
- self.send("#{attribute}=", configuration.send(attribute))
25
- end
17
+ self.send("#{attribute}=", configuration.send(attribute))
26
18
  end
27
19
  end
28
20
  end
@@ -36,7 +28,7 @@ module Backup
36
28
  end
37
29
 
38
30
  ##
39
- # Returns an array of the setter methods (as String)
31
+ # Returns an Array of the setter methods (as String)
40
32
  def setter_methods
41
33
  methods.map do |method|
42
34
  method = method.to_s
@@ -45,14 +37,9 @@ module Backup
45
37
  end
46
38
 
47
39
  ##
48
- # Returns an array of getter methods (as Array)
40
+ # Returns an Array of getter methods (as String)
49
41
  def getter_methods
50
- methods.map do |method|
51
- method = method.to_s
52
- if method =~ /^\w(\w|\d|\_)+\=$/ and method != 'taguri='
53
- method.sub('=','')
54
- end
55
- end.compact
42
+ setter_methods.map {|method| method.sub('=','') }
56
43
  end
57
44
 
58
45
  end
@@ -11,6 +11,11 @@ module Backup
11
11
  # when a backup process ends without raising any exceptions
12
12
  attr_writer :on_success
13
13
 
14
+ ##
15
+ # When set to true, the user will be notified by email
16
+ # when a backup process ends successfully, but logged warnings
17
+ attr_writer :on_warning
18
+
14
19
  ##
15
20
  # When set to true, the user will be notified by email
16
21
  # when a backup process raises an exception before finishing
@@ -26,6 +31,14 @@ module Backup
26
31
  @on_success
27
32
  end
28
33
 
34
+ ##
35
+ # When @on_success is nil it means it hasn't been defined
36
+ # and will then default to true
37
+ def self.on_warning
38
+ return true if @on_warning.nil?
39
+ @on_warning
40
+ end
41
+
29
42
  ##
30
43
  # When @on_failure is nil it means it hasn't been defined
31
44
  # and will then default to true
@@ -0,0 +1,41 @@
1
+ # encoding: utf-8
2
+
3
+ module Backup
4
+ module Configuration
5
+ module Notifier
6
+ class Hipchat < Base
7
+ class << self
8
+
9
+ # From
10
+ # Name that appears in Hipchat
11
+ attr_accessor :from
12
+
13
+ # Hipchat API Token
14
+ # The token to interact with Hipchat
15
+ attr_accessor :token
16
+
17
+ # Rooms
18
+ # Rooms that you want to post notifications to
19
+ attr_accessor :rooms_notified
20
+
21
+ # Success Color
22
+ # The background color of a success message. One of :yellow, :red, :green, :purple, or :random. (default: yellow)
23
+ attr_accessor :success_color
24
+
25
+ # Warning Color
26
+ # The background color of a success message. One of :yellow, :red, :green, :purple, or :random. (default: yellow)
27
+ attr_accessor :warning_color
28
+
29
+ # Failure Color
30
+ # The background color of an error message. One of :yellow, :red, :green, :purple, or :random. (default: yellow)
31
+ attr_accessor :failure_color
32
+
33
+ # Notify Users
34
+ # (bool) Notify users in the room
35
+ attr_accessor :notify_users
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+
@@ -6,6 +6,25 @@ module Backup
6
6
  class Mail < Base
7
7
  class << self
8
8
 
9
+ ##
10
+ # Mail delivery method to be used by the Mail gem.
11
+ # Supported methods:
12
+ #
13
+ # `:smtp` [::Mail::SMTP] (default)
14
+ # : Settings used only by this method:
15
+ # : `address`, `port`, `domain`, `user_name`, `password`
16
+ # : `authentication`, `enable_starttls_auto`, `openssl_verify_mode`
17
+ #
18
+ # `:sendmail` [::Mail::Sendmail]
19
+ # : Settings used only by this method:
20
+ # : `sendmail`, `sendmail_args`
21
+ #
22
+ # `:file` [::Mail::FileDelivery]
23
+ # : Settings used only by this method:
24
+ # : `mail_folder`
25
+ #
26
+ attr_accessor :delivery_method
27
+
9
28
  ##
10
29
  # Sender and Receiver email addresses
11
30
  # Examples:
@@ -50,6 +69,25 @@ module Backup
50
69
  # Example: none - Only use this option for a self-signed and/or wildcard certificate
51
70
  attr_accessor :openssl_verify_mode
52
71
 
72
+ ##
73
+ # When using the `:sendmail` `delivery_method` option,
74
+ # this may be used to specify the absolute path to `sendmail` (if needed)
75
+ # Example: '/usr/sbin/sendmail'
76
+ attr_accessor :sendmail
77
+
78
+ ##
79
+ # Optional arguments to pass to `sendmail`
80
+ # Note that this will override the defaults set by the Mail gem (currently: '-i -t')
81
+ # So, if set here, be sure to set all the arguments you require.
82
+ # Example: '-i -t -X/tmp/traffic.log'
83
+ attr_accessor :sendmail_args
84
+
85
+ ##
86
+ # Folder where mail will be kept when using the `:file` `delivery_method` option.
87
+ # Default location is '$HOME/backup-mails'
88
+ # Example: '/tmp/test-mails'
89
+ attr_accessor :mail_folder
90
+
53
91
  end
54
92
  end
55
93
  end
@@ -0,0 +1,23 @@
1
+ # encoding: utf-8
2
+
3
+ module Backup
4
+ module Configuration
5
+ module Notifier
6
+ class Prowl < Base
7
+ class << self
8
+
9
+ ##
10
+ # Application name
11
+ # Tell something like your server name. Example: "Server1 Backup"
12
+ attr_accessor :application
13
+
14
+ ##
15
+ # API-Key
16
+ # Create a Prowl account and request an API key on prowlapp.com.
17
+ attr_accessor :api_key
18
+
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -10,6 +10,10 @@ module Backup
10
10
  # Rackspace Cloud Files Credentials
11
11
  attr_accessor :api_key, :username, :auth_url
12
12
 
13
+ ##
14
+ # Rackspace Service Net (Allows for LAN-based transfers to avoid charges and improve performance)
15
+ attr_accessor :servicenet
16
+
13
17
  ##
14
18
  # Rackspace Cloud Files container name and path
15
19
  attr_accessor :container, :path
@@ -22,19 +22,23 @@ module Backup
22
22
  # DEPRECATED METHODS #############################################
23
23
 
24
24
  def email
25
- Logger.warn "[DEPRECATED] Backup::Configuration::Storage::Dropbox.email is deprecated and will be removed at some point."
25
+ Logger.warn "[DEPRECATED] Backup::Configuration::Storage::Dropbox.email\n" +
26
+ " is deprecated and will be removed at some point."
26
27
  end
27
28
 
28
29
  def email=(value)
29
- Logger.warn "[DEPRECATED] Backup::Configuration::Storage::Dropbox.email= is deprecated and will be removed at some point."
30
+ Logger.warn "[DEPRECATED] Backup::Configuration::Storage::Dropbox.email=\n" +
31
+ " is deprecated and will be removed at some point."
30
32
  end
31
33
 
32
34
  def password
33
- Logger.warn "[DEPRECATED] Backup::Configuration::Storage::Dropbox.password is deprecated and will be removed at some point."
35
+ Logger.warn "[DEPRECATED] Backup::Configuration::Storage::Dropbox.password\n" +
36
+ " is deprecated and will be removed at some point."
34
37
  end
35
38
 
36
39
  def password=(value)
37
- Logger.warn "[DEPRECATED] Backup::Configuration::Storage::Dropbox.password= is deprecated and will be removed at some point."
40
+ Logger.warn "[DEPRECATED] Backup::Configuration::Storage::Dropbox.password=\n" +
41
+ " is deprecated and will be removed at some point."
38
42
  end
39
43
 
40
44
  end
@@ -3,7 +3,7 @@
3
3
  module Backup
4
4
  module Database
5
5
  class Base
6
- include Backup::CLI
6
+ include Backup::CLI::Helpers
7
7
  include Backup::Configuration::Helpers
8
8
 
9
9
  ##
@@ -15,6 +15,14 @@ module Backup
15
15
  # in case it cannot be auto-detected by Backup
16
16
  attr_accessor :utility_path
17
17
 
18
+ ##
19
+ # Super method for all child (database) objects. Every database object's #perform!
20
+ # method should call #super before anything else to prepare
21
+ def perform!
22
+ prepare!
23
+ log!
24
+ end
25
+
18
26
  ##
19
27
  # Defines the @dump_path and ensures it exists by creating it
20
28
  def prepare!
@@ -26,7 +34,7 @@ module Backup
26
34
  # Logs a message to the console and log file to inform
27
35
  # the client that Backup is dumping the database
28
36
  def log!
29
- Logger.message("#{ self.class } started dumping and archiving \"#{ name }\".")
37
+ Logger.message "#{self.class} started dumping and archiving '#{ name }'."
30
38
  end
31
39
  end
32
40
  end
@@ -43,7 +43,6 @@ module Backup
43
43
  @lock ||= false
44
44
 
45
45
  instance_eval(&block)
46
- prepare!
47
46
  end
48
47
 
49
48
  ##
@@ -112,20 +111,18 @@ module Backup
112
111
  # collections to dump, it'll loop through the array of collections and invoke the
113
112
  # 'mongodump' command once per collection
114
113
  def perform!
115
- log!
116
-
117
- begin
118
- lock_database if @lock.eql?(true)
119
- if collections_to_dump.is_a?(Array) and not collections_to_dump.empty?
120
- specific_collection_dump!
121
- else
122
- dump!
123
- end
124
- unlock_database if @lock.eql?(true)
125
- rescue => exception
126
- unlock_database if @lock.eql?(true)
127
- raise exception
114
+ super
115
+
116
+ lock_database if @lock.eql?(true)
117
+ if collections_to_dump.is_a?(Array) and not collections_to_dump.empty?
118
+ specific_collection_dump!
119
+ else
120
+ dump!
128
121
  end
122
+ unlock_database if @lock.eql?(true)
123
+ rescue => exception
124
+ unlock_database if @lock.eql?(true)
125
+ raise exception
129
126
  end
130
127
 
131
128
  ##
@@ -145,9 +142,9 @@ module Backup
145
142
  end
146
143
 
147
144
  ##
148
- # Builds the full mongo string based on all attributes
149
- def mongo_shell
150
- [utility(:mongo), database, credential_options, connectivity_options, ipv6].join(' ')
145
+ # Builds a Mongo URI based on the provided attributes
146
+ def mongo_uri
147
+ ["#{ host }:#{ port }#{ name.is_a?(String) && !name.empty? ? "/#{ name }" : "" }", credential_options, ipv6].join(' ').strip
151
148
  end
152
149
 
153
150
  ##
@@ -157,7 +154,7 @@ module Backup
157
154
  def lock_database
158
155
  lock_command = <<-EOS
159
156
  echo 'use admin
160
- db.runCommand({"fsync" : 1, "lock" : 1})' | #{mongo_shell}
157
+ db.runCommand({"fsync" : 1, "lock" : 1})' | #{ "#{ utility(:mongo) } #{ mongo_uri }" }
161
158
  EOS
162
159
 
163
160
  run(lock_command)
@@ -168,7 +165,7 @@ module Backup
168
165
  def unlock_database
169
166
  unlock_command = <<-EOS
170
167
  echo 'use admin
171
- db.$cmd.sys.unlock.findOne()' | #{mongo_shell}
168
+ db.$cmd.sys.unlock.findOne()' | #{ "#{ utility(:mongo) } #{ mongo_uri }" }
172
169
  EOS
173
170
 
174
171
  run(unlock_command)