backup 3.0.19 → 3.0.20

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 (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,7 +3,6 @@
3
3
  ##
4
4
  # Only load the Mail gem and Erb library when using Mail notifications
5
5
  Backup::Dependency.load('mail')
6
- require 'erb'
7
6
 
8
7
  module Backup
9
8
  module Notifier
@@ -11,11 +10,26 @@ module Backup
11
10
 
12
11
  ##
13
12
  # Container for the Mail object
14
- attr_accessor :mail
13
+ attr_reader :mail
15
14
 
16
15
  ##
17
- # Container for the Model object
18
- attr_accessor :model
16
+ # Mail delivery method to be used by the Mail gem.
17
+ # Supported methods:
18
+ #
19
+ # `:smtp` [::Mail::SMTP] (default)
20
+ # : Settings used only by this method:
21
+ # : `address`, `port`, `domain`, `user_name`, `password`
22
+ # : `authentication`, `enable_starttls_auto`, `openssl_verify_mode`
23
+ #
24
+ # `:sendmail` [::Mail::Sendmail]
25
+ # : Settings used only by this method:
26
+ # : `sendmail`, `sendmail_args`
27
+ #
28
+ # `:file` [::Mail::FileDelivery]
29
+ # : Settings used only by this method:
30
+ # : `mail_folder`
31
+ #
32
+ attr_accessor :delivery_method
19
33
 
20
34
  ##
21
35
  # Sender and Receiver email addresses
@@ -62,51 +76,69 @@ module Backup
62
76
  attr_accessor :openssl_verify_mode
63
77
 
64
78
  ##
65
- # Instantiates a new Backup::Notifier::Mail object
66
- def initialize(&block)
67
- load_defaults!
79
+ # When using the `:sendmail` `delivery_method` option,
80
+ # this may be used to specify the absolute path to `sendmail` (if needed)
81
+ # Example: '/usr/sbin/sendmail'
82
+ attr_accessor :sendmail
68
83
 
69
- instance_eval(&block) if block_given?
84
+ ##
85
+ # Optional arguments to pass to `sendmail`
86
+ # Note that this will override the defaults set by the Mail gem (currently: '-i -t')
87
+ # So, if set here, be sure to set all the arguments you require.
88
+ # Example: '-i -t -X/tmp/traffic.log'
89
+ attr_accessor :sendmail_args
70
90
 
71
- set_defaults!
72
- end
91
+ ##
92
+ # Folder where mail will be kept when using the `:file` `delivery_method` option.
93
+ # Default location is '$HOME/Backup/emails'
94
+ # Example: '/tmp/test-mails'
95
+ attr_accessor :mail_folder
73
96
 
74
97
  ##
75
98
  # Performs the notification
76
- # Takes an exception object that might've been created if an exception occurred.
77
- # If this is the case it'll invoke notify_failure!(exception), otherwise, if no
78
- # error was raised, it'll go ahead and notify_success!
79
- #
80
- # If'll only perform these if on_success is true or on_failure is true
99
+ # Extends from super class. Must call super(model, exception).
100
+ # If any pre-configuration needs to be done, put it above the super(model, exception)
81
101
  def perform!(model, exception = false)
82
- @model = model
83
-
84
- if notify_on_success? and exception.eql?(false)
85
- log!
86
- notify_success!
87
- elsif notify_on_failure? and not exception.eql?(false)
88
- log!
89
- notify_failure!(exception)
90
- end
102
+ super(model, exception)
91
103
  end
92
104
 
93
105
  private
94
106
 
95
107
  ##
96
- # Sends an email informing the user that the backup operation
97
- # proceeded without any errors
98
- def notify_success!
99
- mail[:subject] = "[Backup::Succeeded] #{model.label} (#{model.trigger})"
100
- mail[:body] = read_template('notify_success', Binder.bind(:model => @model))
101
- mail.deliver!
102
- end
103
-
104
- ##
105
- # Sends an email informing the user that the backup operation
106
- # raised an exception and will send the user the error details
107
- def notify_failure!(exception)
108
- mail[:subject] = "[Backup::Failed] #{model.label} (#{model.trigger})"
109
- mail[:body] = read_template('notify_failure', Binder.bind(:model => @model, :exception => exception))
108
+ # Notify the user of the backup operation results.
109
+ # `status` indicates one of the following:
110
+ #
111
+ # `:success`
112
+ # : The backup completed successfully.
113
+ # : Notification will be sent if `on_success` was set to `true`
114
+ #
115
+ # `:warning`
116
+ # : The backup completed successfully, but warnings were logged
117
+ # : Notification will be sent, including a copy of the current
118
+ # : backup log, if `on_warning` was set to `true`
119
+ #
120
+ # `:failure`
121
+ # : The backup operation failed.
122
+ # : Notification will be sent, including the Exception which caused
123
+ # : the failure, the Exception's backtrace, a copy of the current
124
+ # : backup log and other information if `on_failure` was set to `true`
125
+ #
126
+ def notify!(status)
127
+ name, send_log =
128
+ case status
129
+ when :success then [ 'Success', false ]
130
+ when :warning then [ 'Warning', true ]
131
+ when :failure then [ 'Failure', true ]
132
+ end
133
+ mail.subject = "[Backup::%s] #{model.label} (#{model.trigger})" % name
134
+ mail.body = template.result('notifier/mail/%s.erb' % status.to_s)
135
+ if send_log
136
+ mail.convert_to_multipart
137
+ mail.attachments["#{model.time}.#{model.trigger}.log"] = {
138
+ :mime_type => 'text/plain;',
139
+ :content => Logger.messages.join("\n")
140
+ }
141
+ end
110
142
  mail.deliver!
111
143
  end
112
144
 
@@ -114,32 +146,39 @@ module Backup
114
146
  # Configures the Mail gem by setting the defaults.
115
147
  # Instantiates the @mail object with the @to and @from attributes
116
148
  def set_defaults!
117
- defaults = {
118
- :address => @address,
119
- :port => @port,
120
- :domain => @domain,
121
- :user_name => @user_name,
122
- :password => @password,
123
- :authentication => @authentication,
124
- :enable_starttls_auto => @enable_starttls_auto,
125
- :openssl_verify_mode => @openssl_verify_mode
126
- }
127
-
149
+ @delivery_method = %w{ smtp sendmail file test }.
150
+ index(@delivery_method.to_s) ? @delivery_method.to_s : 'smtp'
151
+
152
+ options =
153
+ case @delivery_method
154
+ when 'smtp'
155
+ { :address => @address,
156
+ :port => @port,
157
+ :domain => @domain,
158
+ :user_name => @user_name,
159
+ :password => @password,
160
+ :authentication => @authentication,
161
+ :enable_starttls_auto => @enable_starttls_auto,
162
+ :openssl_verify_mode => @openssl_verify_mode }
163
+ when 'sendmail'
164
+ opts = {}
165
+ opts.merge!(:location => File.expand_path(@sendmail)) if @sendmail
166
+ opts.merge!(:arguments => @sendmail_args) if @sendmail_args
167
+ opts
168
+ when 'file'
169
+ @mail_folder ||= "#{ENV['HOME']}/Backup/emails"
170
+ { :location => File.expand_path(@mail_folder) }
171
+ when 'test' then {}
172
+ end
173
+
174
+ method = @delivery_method.to_sym
128
175
  ::Mail.defaults do
129
- delivery_method :smtp, defaults
176
+ delivery_method method, options
130
177
  end
131
178
 
132
- @mail = ::Mail.new
133
- @mail[:from] = @from
134
- @mail[:to] = @to
135
- end
136
-
137
- ##
138
- # Returns the path to the templates, appended by the passed in argument
139
- def read_template(file, binder)
140
- ERB.new(File.read(
141
- File.join( File.dirname(__FILE__), "templates", "#{file}.erb" )
142
- )).result(binder)
179
+ @mail = ::Mail.new
180
+ @mail.from = @from
181
+ @mail.to = @to
143
182
  end
144
183
 
145
184
  end
@@ -10,10 +10,6 @@ module Backup
10
10
  # Container for the Presently Client object
11
11
  attr_accessor :presently_client
12
12
 
13
- ##
14
- # Container for the Model object
15
- attr_accessor :model
16
-
17
13
  ##
18
14
  # Presently subdomain
19
15
  attr_accessor :subdomain
@@ -26,55 +22,50 @@ module Backup
26
22
  # Group id
27
23
  attr_accessor :group_id
28
24
 
29
- ##
30
- # Instantiates a new Backup::Notifier::Presently object
31
- def initialize(&block)
32
- load_defaults!
33
-
34
- instance_eval(&block) if block_given?
35
-
36
- set_defaults!
37
- end
38
-
39
25
  ##
40
26
  # Performs the notification
41
- # Takes an exception object that might've been created if an exception occurred.
42
- # If this is the case it'll invoke notify_failure!(exception), otherwise, if no
43
- # error was raised, it'll go ahead and notify_success!
44
- #
45
- # If'll only perform these if on_success is true or on_failure is true
27
+ # Extends from super class. Must call super(model, exception).
28
+ # If any pre-configuration needs to be done,
29
+ # put it above the super(model, exception)
46
30
  def perform!(model, exception = false)
47
- @model = model
48
-
49
- if notify_on_success? and exception.eql?(false)
50
- log!
51
- notify_success!
52
- elsif notify_on_failure? and not exception.eql?(false)
53
- log!
54
- notify_failure!(exception)
55
- end
31
+ super(model, exception)
56
32
  end
57
33
 
58
34
  private
59
35
 
60
36
  ##
61
- # Sends a tweet informing the user that the backup operation
62
- # proceeded without any errors
63
- def notify_success!
64
- presently_client.update("[Backup::Succeeded] #{model.label} (#{ File.basename(Backup::Model.file) })")
65
- end
66
-
67
- ##
68
- # Sends a tweet informing the user that the backup operation
69
- # raised an exception
70
- def notify_failure!(exception)
71
- presently_client.update("[Backup::Failed] #{model.label} (#{ File.basename(Backup::Model.file) })")
37
+ # Notify the user of the backup operation results.
38
+ # `status` indicates one of the following:
39
+ #
40
+ # `:success`
41
+ # : The backup completed successfully.
42
+ # : Notification will be sent if `on_success` was set to `true`
43
+ #
44
+ # `:warning`
45
+ # : The backup completed successfully, but warnings were logged
46
+ # : Notification will be sent, including a copy of the current
47
+ # : backup log, if `on_warning` was set to `true`
48
+ #
49
+ # `:failure`
50
+ # : The backup operation failed.
51
+ # : Notification will be sent, including the Exception which caused
52
+ # : the failure, the Exception's backtrace, a copy of the current
53
+ # : backup log and other information if `on_failure` was set to `true`
54
+ #
55
+ def notify!(status)
56
+ name = case status
57
+ when :success then 'Success'
58
+ when :warning then 'Warning'
59
+ when :failure then 'Failure'
60
+ end
61
+ message = "[Backup::%s] #{model.label} (#{model.trigger})" % name
62
+ presently_client.update(message)
72
63
  end
73
64
 
74
65
  ##
75
66
  # Create a default Presently::Client object
76
67
  def set_defaults!
77
- @presently_client = Client.new subdomain, user_name, password, group_id
68
+ @presently_client = Client.new(subdomain, user_name, password, group_id)
78
69
  end
79
70
 
80
71
  class Client
@@ -0,0 +1,73 @@
1
+ # encoding: utf-8
2
+
3
+ ##
4
+ # Only load the Prowler gem when using Prowler notifications
5
+ Backup::Dependency.load('prowler')
6
+
7
+ module Backup
8
+ module Notifier
9
+ class Prowl < Base
10
+
11
+ ##
12
+ # Container for the Twitter Client object
13
+ attr_accessor :prowl_client
14
+
15
+ ##
16
+ # Application name
17
+ # Tell something like your server name. Example: "Server1 Backup"
18
+ attr_accessor :application
19
+
20
+ ##
21
+ # API-Key
22
+ # Create a Prowl account and request an API key on prowlapp.com.
23
+ attr_accessor :api_key
24
+
25
+ ##
26
+ # Performs the notification
27
+ # Extends from super class. Must call super(model, exception).
28
+ # If any pre-configuration needs to be done, put it above the super(model, exception)
29
+ def perform!(model, exception = false)
30
+ super(model, exception)
31
+ end
32
+
33
+ private
34
+
35
+ ##
36
+ # Notify the user of the backup operation results.
37
+ # `status` indicates one of the following:
38
+ #
39
+ # `:success`
40
+ # : The backup completed successfully.
41
+ # : Notification will be sent if `on_success` was set to `true`
42
+ #
43
+ # `:warning`
44
+ # : The backup completed successfully, but warnings were logged
45
+ # : Notification will be sent, including a copy of the current
46
+ # : backup log, if `on_warning` was set to `true`
47
+ #
48
+ # `:failure`
49
+ # : The backup operation failed.
50
+ # : Notification will be sent, including the Exception which caused
51
+ # : the failure, the Exception's backtrace, a copy of the current
52
+ # : backup log and other information if `on_failure` was set to `true`
53
+ #
54
+ def notify!(status)
55
+ name = case status
56
+ when :success then 'Success'
57
+ when :warning then 'Warning'
58
+ when :failure then 'Failure'
59
+ end
60
+ message = '[Backup::%s]' % name
61
+ prowl_client.notify(message, "#{model.label} (#{model.trigger})")
62
+ end
63
+
64
+ ##
65
+ # Configures the Prowler object by passing in the @api_key and the
66
+ # @application. Instantiates and sets the @prowl_client object
67
+ def set_defaults!
68
+ @prowl_client = Prowler.new(:application => application, :api_key => api_key)
69
+ end
70
+
71
+ end
72
+ end
73
+ end
@@ -12,10 +12,6 @@ module Backup
12
12
  # Container for the Twitter Client object
13
13
  attr_accessor :twitter_client
14
14
 
15
- ##
16
- # Container for the Model object
17
- attr_accessor :model
18
-
19
15
  ##
20
16
  # Twitter consumer key credentials
21
17
  attr_accessor :consumer_key, :consumer_secret
@@ -24,49 +20,43 @@ module Backup
24
20
  # OAuth credentials
25
21
  attr_accessor :oauth_token, :oauth_token_secret
26
22
 
27
- ##
28
- # Instantiates a new Backup::Notifier::Twitter object
29
- def initialize(&block)
30
- load_defaults!
31
-
32
- instance_eval(&block) if block_given?
33
-
34
- set_defaults!
35
- end
36
-
37
23
  ##
38
24
  # Performs the notification
39
- # Takes an exception object that might've been created if an exception occurred.
40
- # If this is the case it'll invoke notify_failure!(exception), otherwise, if no
41
- # error was raised, it'll go ahead and notify_success!
42
- #
43
- # If'll only perform these if on_success is true or on_failure is true
25
+ # Extends from super class. Must call super(model, exception).
26
+ # If any pre-configuration needs to be done, put it above the super(model, exception)
44
27
  def perform!(model, exception = false)
45
- @model = model
46
-
47
- if notify_on_success? and exception.eql?(false)
48
- log!
49
- notify_success!
50
- elsif notify_on_failure? and not exception.eql?(false)
51
- log!
52
- notify_failure!(exception)
53
- end
28
+ super(model, exception)
54
29
  end
55
30
 
56
31
  private
57
32
 
58
33
  ##
59
- # Sends a tweet informing the user that the backup operation
60
- # proceeded without any errors
61
- def notify_success!
62
- twitter_client.update("[Backup::Succeeded] #{model.label} (#{ File.basename(Backup::Model.file) })")
63
- end
64
-
65
- ##
66
- # Sends a tweet informing the user that the backup operation
67
- # raised an exception
68
- def notify_failure!(exception)
69
- twitter_client.update("[Backup::Failed] #{model.label} (#{ File.basename(Backup::Model.file) })")
34
+ # Notify the user of the backup operation results.
35
+ # `status` indicates one of the following:
36
+ #
37
+ # `:success`
38
+ # : The backup completed successfully.
39
+ # : Notification will be sent if `on_success` was set to `true`
40
+ #
41
+ # `:warning`
42
+ # : The backup completed successfully, but warnings were logged
43
+ # : Notification will be sent, including a copy of the current
44
+ # : backup log, if `on_warning` was set to `true`
45
+ #
46
+ # `:failure`
47
+ # : The backup operation failed.
48
+ # : Notification will be sent, including the Exception which caused
49
+ # : the failure, the Exception's backtrace, a copy of the current
50
+ # : backup log and other information if `on_failure` was set to `true`
51
+ #
52
+ def notify!(status)
53
+ name = case status
54
+ when :success then 'Success'
55
+ when :warning then 'Warning'
56
+ when :failure then 'Failure'
57
+ end
58
+ message = "[Backup::%s] #{model.label} (#{model.trigger})" % name
59
+ twitter_client.update(message)
70
60
  end
71
61
 
72
62
  ##