backup 3.0.19 → 3.0.20
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +9 -8
- data/Gemfile.lock +19 -1
- data/Guardfile +13 -9
- data/README.md +93 -31
- data/backup.gemspec +3 -3
- data/bin/backup +6 -283
- data/lib/backup.rb +101 -72
- data/lib/backup/archive.rb +21 -9
- data/lib/backup/binder.rb +22 -0
- data/lib/backup/cleaner.rb +36 -0
- data/lib/backup/cli/helpers.rb +103 -0
- data/lib/backup/cli/utility.rb +308 -0
- data/lib/backup/compressor/base.rb +2 -2
- data/lib/backup/compressor/pbzip2.rb +76 -0
- data/lib/backup/configuration/compressor/pbzip2.rb +28 -0
- data/lib/backup/configuration/database/riak.rb +25 -0
- data/lib/backup/configuration/encryptor/open_ssl.rb +6 -0
- data/lib/backup/configuration/helpers.rb +5 -18
- data/lib/backup/configuration/notifier/base.rb +13 -0
- data/lib/backup/configuration/notifier/hipchat.rb +41 -0
- data/lib/backup/configuration/notifier/mail.rb +38 -0
- data/lib/backup/configuration/notifier/prowl.rb +23 -0
- data/lib/backup/configuration/storage/cloudfiles.rb +4 -0
- data/lib/backup/configuration/storage/dropbox.rb +8 -4
- data/lib/backup/database/base.rb +10 -2
- data/lib/backup/database/mongodb.rb +16 -19
- data/lib/backup/database/mysql.rb +2 -2
- data/lib/backup/database/postgresql.rb +2 -2
- data/lib/backup/database/redis.rb +15 -7
- data/lib/backup/database/riak.rb +45 -0
- data/lib/backup/dependency.rb +21 -7
- data/lib/backup/encryptor/base.rb +1 -1
- data/lib/backup/encryptor/open_ssl.rb +20 -5
- data/lib/backup/errors.rb +124 -0
- data/lib/backup/finder.rb +11 -3
- data/lib/backup/logger.rb +121 -82
- data/lib/backup/model.rb +103 -44
- data/lib/backup/notifier/base.rb +50 -0
- data/lib/backup/notifier/campfire.rb +32 -52
- data/lib/backup/notifier/hipchat.rb +99 -0
- data/lib/backup/notifier/mail.rb +100 -61
- data/lib/backup/notifier/presently.rb +31 -40
- data/lib/backup/notifier/prowl.rb +73 -0
- data/lib/backup/notifier/twitter.rb +29 -39
- data/lib/backup/packager.rb +25 -0
- data/lib/backup/splitter.rb +62 -0
- data/lib/backup/storage/base.rb +178 -18
- data/lib/backup/storage/cloudfiles.rb +34 -28
- data/lib/backup/storage/dropbox.rb +64 -67
- data/lib/backup/storage/ftp.rb +48 -40
- data/lib/backup/storage/local.rb +33 -28
- data/lib/backup/storage/ninefold.rb +40 -26
- data/lib/backup/storage/object.rb +8 -6
- data/lib/backup/storage/rsync.rb +61 -51
- data/lib/backup/storage/s3.rb +29 -27
- data/lib/backup/storage/scp.rb +56 -36
- data/lib/backup/storage/sftp.rb +49 -33
- data/lib/backup/syncer/base.rb +1 -1
- data/lib/backup/syncer/rsync.rb +1 -1
- data/lib/backup/template.rb +46 -0
- data/lib/backup/version.rb +1 -1
- data/spec/archive_spec.rb +34 -9
- data/spec/backup_spec.rb +1 -1
- data/spec/cli/helpers_spec.rb +35 -0
- data/spec/cli/utility_spec.rb +38 -0
- data/spec/compressor/bzip2_spec.rb +1 -1
- data/spec/compressor/gzip_spec.rb +1 -1
- data/spec/compressor/lzma_spec.rb +1 -1
- data/spec/compressor/pbzip2_spec.rb +63 -0
- data/spec/configuration/base_spec.rb +1 -1
- data/spec/configuration/compressor/bzip2_spec.rb +1 -1
- data/spec/configuration/compressor/gzip_spec.rb +1 -1
- data/spec/configuration/compressor/lzma_spec.rb +1 -1
- data/spec/configuration/database/base_spec.rb +1 -1
- data/spec/configuration/database/mongodb_spec.rb +1 -1
- data/spec/configuration/database/mysql_spec.rb +1 -1
- data/spec/configuration/database/postgresql_spec.rb +1 -1
- data/spec/configuration/database/redis_spec.rb +1 -1
- data/spec/configuration/database/riak_spec.rb +31 -0
- data/spec/configuration/encryptor/gpg_spec.rb +1 -1
- data/spec/configuration/encryptor/open_ssl_spec.rb +4 -1
- data/spec/configuration/notifier/campfire_spec.rb +1 -1
- data/spec/configuration/notifier/hipchat_spec.rb +43 -0
- data/spec/configuration/notifier/mail_spec.rb +34 -22
- data/spec/configuration/notifier/presently_spec.rb +1 -1
- data/spec/configuration/notifier/prowl_spec.rb +28 -0
- data/spec/configuration/notifier/twitter_spec.rb +1 -1
- data/spec/configuration/storage/cloudfiles_spec.rb +19 -16
- data/spec/configuration/storage/dropbox_spec.rb +1 -1
- data/spec/configuration/storage/ftp_spec.rb +1 -1
- data/spec/configuration/storage/local_spec.rb +1 -1
- data/spec/configuration/storage/ninefold_spec.rb +1 -1
- data/spec/configuration/storage/rsync_spec.rb +1 -1
- data/spec/configuration/storage/s3_spec.rb +1 -1
- data/spec/configuration/storage/scp_spec.rb +1 -1
- data/spec/configuration/storage/sftp_spec.rb +1 -1
- data/spec/configuration/syncer/rsync_spec.rb +1 -1
- data/spec/configuration/syncer/s3_spec.rb +1 -1
- data/spec/database/base_spec.rb +10 -1
- data/spec/database/mongodb_spec.rb +34 -7
- data/spec/database/mysql_spec.rb +8 -7
- data/spec/database/postgresql_spec.rb +8 -7
- data/spec/database/redis_spec.rb +39 -9
- data/spec/database/riak_spec.rb +50 -0
- data/spec/encryptor/gpg_spec.rb +1 -1
- data/spec/encryptor/open_ssl_spec.rb +77 -20
- data/spec/errors_spec.rb +306 -0
- data/spec/finder_spec.rb +91 -0
- data/spec/logger_spec.rb +254 -33
- data/spec/model_spec.rb +120 -15
- data/spec/notifier/campfire_spec.rb +127 -52
- data/spec/notifier/hipchat_spec.rb +193 -0
- data/spec/notifier/mail_spec.rb +290 -74
- data/spec/notifier/presently_spec.rb +290 -73
- data/spec/notifier/prowl_spec.rb +149 -0
- data/spec/notifier/twitter_spec.rb +106 -41
- data/spec/spec_helper.rb +8 -2
- data/spec/splitter_spec.rb +71 -0
- data/spec/storage/base_spec.rb +280 -19
- data/spec/storage/cloudfiles_spec.rb +38 -22
- data/spec/storage/dropbox_spec.rb +17 -13
- data/spec/storage/ftp_spec.rb +145 -55
- data/spec/storage/local_spec.rb +6 -6
- data/spec/storage/ninefold_spec.rb +70 -29
- data/spec/storage/object_spec.rb +44 -44
- data/spec/storage/rsync_spec.rb +186 -63
- data/spec/storage/s3_spec.rb +23 -24
- data/spec/storage/scp_spec.rb +116 -41
- data/spec/storage/sftp_spec.rb +124 -46
- data/spec/syncer/rsync_spec.rb +3 -3
- data/spec/syncer/s3_spec.rb +1 -1
- data/spec/version_spec.rb +1 -1
- data/templates/cli/utility/archive +13 -0
- data/{lib/templates → templates/cli/utility}/compressor/bzip2 +1 -1
- data/{lib/templates → templates/cli/utility}/compressor/gzip +1 -1
- data/{lib/templates → templates/cli/utility}/compressor/lzma +0 -0
- data/templates/cli/utility/compressor/pbzip2 +7 -0
- data/templates/cli/utility/config +31 -0
- data/{lib/templates → templates/cli/utility}/database/mongodb +1 -1
- data/{lib/templates → templates/cli/utility}/database/mysql +1 -1
- data/{lib/templates → templates/cli/utility}/database/postgresql +1 -1
- data/{lib/templates → templates/cli/utility}/database/redis +1 -1
- data/templates/cli/utility/database/riak +8 -0
- data/{lib/templates → templates/cli/utility}/encryptor/gpg +1 -1
- data/templates/cli/utility/encryptor/openssl +9 -0
- data/templates/cli/utility/model.erb +23 -0
- data/{lib/templates → templates/cli/utility}/notifier/campfire +2 -1
- data/templates/cli/utility/notifier/hipchat +15 -0
- data/{lib/templates → templates/cli/utility}/notifier/mail +6 -1
- data/{lib/templates → templates/cli/utility}/notifier/presently +1 -0
- data/templates/cli/utility/notifier/prowl +11 -0
- data/{lib/templates → templates/cli/utility}/notifier/twitter +2 -1
- data/templates/cli/utility/splitter +7 -0
- data/templates/cli/utility/storage/cloudfiles +12 -0
- data/{lib/templates → templates/cli/utility}/storage/dropbox +1 -1
- data/{lib/templates → templates/cli/utility}/storage/ftp +0 -0
- data/templates/cli/utility/storage/local +7 -0
- data/{lib/templates → templates/cli/utility}/storage/ninefold +1 -1
- data/templates/cli/utility/storage/rsync +11 -0
- data/{lib/templates → templates/cli/utility}/storage/s3 +0 -2
- data/templates/cli/utility/storage/scp +11 -0
- data/templates/cli/utility/storage/sftp +11 -0
- data/{lib/templates → templates/cli/utility}/syncer/rsync +1 -1
- data/{lib/templates → templates/cli/utility}/syncer/s3 +1 -1
- data/templates/general/links +11 -0
- data/templates/general/version.erb +2 -0
- data/templates/notifier/mail/failure.erb +9 -0
- data/templates/notifier/mail/success.erb +7 -0
- data/templates/notifier/mail/warning.erb +9 -0
- data/templates/storage/dropbox/authorization_url.erb +6 -0
- data/templates/storage/dropbox/authorized.erb +4 -0
- data/templates/storage/dropbox/cache_file_written.erb +10 -0
- metadata +81 -45
- data/lib/backup/cli.rb +0 -110
- data/lib/backup/exception/command_failed.rb +0 -8
- data/lib/backup/exception/command_not_found.rb +0 -8
- data/lib/backup/notifier/binder.rb +0 -32
- data/lib/backup/notifier/templates/notify_failure.erb +0 -33
- data/lib/backup/notifier/templates/notify_success.erb +0 -16
- data/lib/templates/archive +0 -7
- data/lib/templates/encryptor/openssl +0 -8
- data/lib/templates/readme +0 -15
- data/lib/templates/storage/cloudfiles +0 -11
- data/lib/templates/storage/local +0 -7
- data/lib/templates/storage/rsync +0 -11
- data/lib/templates/storage/scp +0 -11
- data/lib/templates/storage/sftp +0 -11
data/lib/backup/notifier/mail.rb
CHANGED
@@ -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
|
-
|
13
|
+
attr_reader :mail
|
15
14
|
|
16
15
|
##
|
17
|
-
#
|
18
|
-
|
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
|
-
#
|
66
|
-
|
67
|
-
|
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
|
-
|
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
|
-
|
72
|
-
|
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
|
-
#
|
77
|
-
# If
|
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
|
-
|
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
|
-
#
|
97
|
-
#
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
#
|
106
|
-
#
|
107
|
-
|
108
|
-
|
109
|
-
|
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
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
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
|
176
|
+
delivery_method method, options
|
130
177
|
end
|
131
178
|
|
132
|
-
@mail
|
133
|
-
@mail
|
134
|
-
@mail
|
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
|
-
#
|
42
|
-
# If
|
43
|
-
#
|
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
|
-
|
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
|
-
#
|
62
|
-
#
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
#
|
69
|
-
#
|
70
|
-
|
71
|
-
|
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
|
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
|
-
#
|
40
|
-
# If
|
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
|
-
|
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
|
-
#
|
60
|
-
#
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
#
|
67
|
-
#
|
68
|
-
|
69
|
-
|
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
|
##
|