backup 3.0.20 → 3.0.21
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -5
- data/Gemfile.lock +46 -50
- data/README.md +54 -27
- data/lib/backup.rb +16 -39
- data/lib/backup/archive.rb +42 -18
- data/lib/backup/cleaner.rb +110 -25
- data/lib/backup/cli/helpers.rb +17 -32
- data/lib/backup/cli/utility.rb +46 -107
- data/lib/backup/compressor/base.rb +14 -2
- data/lib/backup/compressor/bzip2.rb +10 -24
- data/lib/backup/compressor/gzip.rb +10 -24
- data/lib/backup/compressor/lzma.rb +10 -23
- data/lib/backup/compressor/pbzip2.rb +12 -32
- data/lib/backup/config.rb +171 -0
- data/lib/backup/configuration/compressor/base.rb +1 -2
- data/lib/backup/configuration/compressor/pbzip2.rb +4 -4
- data/lib/backup/configuration/database/base.rb +2 -1
- data/lib/backup/configuration/database/mongodb.rb +8 -0
- data/lib/backup/configuration/database/mysql.rb +4 -0
- data/lib/backup/configuration/database/postgresql.rb +4 -0
- data/lib/backup/configuration/database/redis.rb +4 -0
- data/lib/backup/configuration/database/riak.rb +5 -1
- data/lib/backup/configuration/encryptor/base.rb +1 -2
- data/lib/backup/configuration/encryptor/open_ssl.rb +1 -1
- data/lib/backup/configuration/helpers.rb +7 -2
- data/lib/backup/configuration/notifier/base.rb +4 -28
- data/lib/backup/configuration/storage/base.rb +1 -1
- data/lib/backup/configuration/storage/dropbox.rb +14 -4
- data/lib/backup/configuration/syncer/base.rb +10 -0
- data/lib/backup/configuration/syncer/rsync/base.rb +28 -0
- data/lib/backup/configuration/syncer/rsync/local.rb +11 -0
- data/lib/backup/configuration/syncer/rsync/pull.rb +11 -0
- data/lib/backup/configuration/syncer/rsync/push.rb +31 -0
- data/lib/backup/configuration/syncer/s3.rb +0 -4
- data/lib/backup/database/base.rb +25 -7
- data/lib/backup/database/mongodb.rb +112 -75
- data/lib/backup/database/mysql.rb +54 -29
- data/lib/backup/database/postgresql.rb +60 -42
- data/lib/backup/database/redis.rb +61 -39
- data/lib/backup/database/riak.rb +35 -11
- data/lib/backup/dependency.rb +4 -5
- data/lib/backup/encryptor/base.rb +13 -1
- data/lib/backup/encryptor/gpg.rb +39 -39
- data/lib/backup/encryptor/open_ssl.rb +28 -38
- data/lib/backup/logger.rb +20 -11
- data/lib/backup/model.rb +206 -163
- data/lib/backup/notifier/base.rb +27 -25
- data/lib/backup/notifier/campfire.rb +7 -13
- data/lib/backup/notifier/hipchat.rb +28 -28
- data/lib/backup/notifier/mail.rb +24 -26
- data/lib/backup/notifier/presently.rb +10 -18
- data/lib/backup/notifier/prowl.rb +9 -17
- data/lib/backup/notifier/twitter.rb +11 -18
- data/lib/backup/package.rb +47 -0
- data/lib/backup/packager.rb +81 -16
- data/lib/backup/splitter.rb +48 -35
- data/lib/backup/storage/base.rb +44 -172
- data/lib/backup/storage/cloudfiles.rb +31 -46
- data/lib/backup/storage/cycler.rb +117 -0
- data/lib/backup/storage/dropbox.rb +92 -76
- data/lib/backup/storage/ftp.rb +30 -40
- data/lib/backup/storage/local.rb +44 -45
- data/lib/backup/storage/ninefold.rb +55 -49
- data/lib/backup/storage/rsync.rb +49 -56
- data/lib/backup/storage/s3.rb +33 -44
- data/lib/backup/storage/scp.rb +21 -48
- data/lib/backup/storage/sftp.rb +26 -40
- data/lib/backup/syncer/base.rb +7 -0
- data/lib/backup/syncer/rsync/base.rb +78 -0
- data/lib/backup/syncer/rsync/local.rb +53 -0
- data/lib/backup/syncer/rsync/pull.rb +38 -0
- data/lib/backup/syncer/rsync/push.rb +113 -0
- data/lib/backup/syncer/s3.rb +42 -32
- data/lib/backup/version.rb +1 -1
- data/spec/archive_spec.rb +235 -69
- data/spec/cleaner_spec.rb +304 -0
- data/spec/cli/helpers_spec.rb +142 -1
- data/spec/cli/utility_spec.rb +338 -13
- data/spec/compressor/base_spec.rb +31 -0
- data/spec/compressor/bzip2_spec.rb +60 -35
- data/spec/compressor/gzip_spec.rb +60 -35
- data/spec/compressor/lzma_spec.rb +60 -35
- data/spec/compressor/pbzip2_spec.rb +98 -37
- data/spec/config_spec.rb +321 -0
- data/spec/configuration/base_spec.rb +4 -4
- data/spec/configuration/compressor/bzip2_spec.rb +1 -0
- data/spec/configuration/compressor/gzip_spec.rb +1 -0
- data/spec/configuration/compressor/lzma_spec.rb +1 -0
- data/spec/configuration/compressor/pbzip2_spec.rb +32 -0
- data/spec/configuration/database/base_spec.rb +2 -1
- data/spec/configuration/database/mongodb_spec.rb +26 -16
- data/spec/configuration/database/mysql_spec.rb +4 -0
- data/spec/configuration/database/postgresql_spec.rb +4 -0
- data/spec/configuration/database/redis_spec.rb +4 -0
- data/spec/configuration/database/riak_spec.rb +4 -0
- data/spec/configuration/encryptor/gpg_spec.rb +1 -0
- data/spec/configuration/encryptor/open_ssl_spec.rb +1 -0
- data/spec/configuration/notifier/base_spec.rb +32 -0
- data/spec/configuration/notifier/campfire_spec.rb +1 -0
- data/spec/configuration/notifier/hipchat_spec.rb +1 -0
- data/spec/configuration/notifier/mail_spec.rb +1 -0
- data/spec/configuration/notifier/presently_spec.rb +1 -0
- data/spec/configuration/notifier/prowl_spec.rb +1 -0
- data/spec/configuration/notifier/twitter_spec.rb +1 -0
- data/spec/configuration/storage/cloudfiles_spec.rb +1 -0
- data/spec/configuration/storage/dropbox_spec.rb +4 -3
- data/spec/configuration/storage/ftp_spec.rb +1 -0
- data/spec/configuration/storage/local_spec.rb +1 -0
- data/spec/configuration/storage/ninefold_spec.rb +1 -0
- data/spec/configuration/storage/rsync_spec.rb +3 -1
- data/spec/configuration/storage/s3_spec.rb +1 -0
- data/spec/configuration/storage/scp_spec.rb +1 -0
- data/spec/configuration/storage/sftp_spec.rb +1 -0
- data/spec/configuration/syncer/rsync/base_spec.rb +33 -0
- data/spec/configuration/syncer/rsync/local_spec.rb +10 -0
- data/spec/configuration/syncer/rsync/pull_spec.rb +10 -0
- data/spec/configuration/syncer/{rsync_spec.rb → rsync/push_spec.rb} +12 -15
- data/spec/configuration/syncer/s3_spec.rb +2 -3
- data/spec/database/base_spec.rb +35 -20
- data/spec/database/mongodb_spec.rb +298 -119
- data/spec/database/mysql_spec.rb +147 -72
- data/spec/database/postgresql_spec.rb +155 -100
- data/spec/database/redis_spec.rb +200 -97
- data/spec/database/riak_spec.rb +82 -24
- data/spec/dependency_spec.rb +49 -0
- data/spec/encryptor/base_spec.rb +30 -0
- data/spec/encryptor/gpg_spec.rb +105 -28
- data/spec/encryptor/open_ssl_spec.rb +85 -114
- data/spec/logger_spec.rb +74 -8
- data/spec/model_spec.rb +528 -220
- data/spec/notifier/base_spec.rb +89 -0
- data/spec/notifier/campfire_spec.rb +147 -119
- data/spec/notifier/hipchat_spec.rb +140 -145
- data/spec/notifier/mail_spec.rb +190 -248
- data/spec/notifier/presently_spec.rb +147 -282
- data/spec/notifier/prowl_spec.rb +79 -111
- data/spec/notifier/twitter_spec.rb +87 -106
- data/spec/package_spec.rb +61 -0
- data/spec/packager_spec.rb +154 -0
- data/spec/spec_helper.rb +36 -13
- data/spec/splitter_spec.rb +90 -41
- data/spec/storage/base_spec.rb +95 -239
- data/spec/storage/cloudfiles_spec.rb +185 -75
- data/spec/storage/cycler_spec.rb +239 -0
- data/spec/storage/dropbox_spec.rb +318 -87
- data/spec/storage/ftp_spec.rb +165 -152
- data/spec/storage/local_spec.rb +206 -54
- data/spec/storage/ninefold_spec.rb +264 -128
- data/spec/storage/rsync_spec.rb +244 -163
- data/spec/storage/s3_spec.rb +175 -64
- data/spec/storage/scp_spec.rb +156 -150
- data/spec/storage/sftp_spec.rb +153 -135
- data/spec/syncer/base_spec.rb +22 -0
- data/spec/syncer/rsync/base_spec.rb +118 -0
- data/spec/syncer/rsync/local_spec.rb +121 -0
- data/spec/syncer/rsync/pull_spec.rb +90 -0
- data/spec/syncer/rsync/push_spec.rb +327 -0
- data/spec/syncer/s3_spec.rb +180 -91
- data/templates/cli/utility/config +1 -1
- data/templates/cli/utility/database/mongodb +4 -0
- data/templates/cli/utility/database/mysql +3 -0
- data/templates/cli/utility/database/postgresql +3 -0
- data/templates/cli/utility/database/redis +3 -0
- data/templates/cli/utility/database/riak +3 -0
- data/templates/cli/utility/storage/dropbox +4 -1
- data/templates/cli/utility/syncer/rsync_local +12 -0
- data/templates/cli/utility/syncer/{rsync → rsync_pull} +2 -2
- data/templates/cli/utility/syncer/rsync_push +17 -0
- data/templates/storage/dropbox/authorization_url.erb +1 -1
- metadata +42 -17
- data/lib/backup/configuration/syncer/rsync.rb +0 -45
- data/lib/backup/finder.rb +0 -87
- data/lib/backup/storage/object.rb +0 -47
- data/lib/backup/syncer/rsync.rb +0 -152
- data/spec/backup_spec.rb +0 -11
- data/spec/finder_spec.rb +0 -91
- data/spec/storage/object_spec.rb +0 -74
- data/spec/syncer/rsync_spec.rb +0 -195
data/lib/backup/notifier/base.rb
CHANGED
@@ -5,14 +5,6 @@ module Backup
|
|
5
5
|
class Base
|
6
6
|
include Backup::Configuration::Helpers
|
7
7
|
|
8
|
-
##
|
9
|
-
# Container for the Model object
|
10
|
-
attr_accessor :model
|
11
|
-
|
12
|
-
##
|
13
|
-
# Contains the Backup::Template object
|
14
|
-
attr_accessor :template
|
15
|
-
|
16
8
|
##
|
17
9
|
# When set to true, the user will be notified by email
|
18
10
|
# when a backup process ends without raising any exceptions
|
@@ -32,33 +24,35 @@ module Backup
|
|
32
24
|
alias :notify_on_failure? :on_failure
|
33
25
|
|
34
26
|
##
|
35
|
-
#
|
36
|
-
def initialize(
|
27
|
+
# Called with super(model) from subclasses
|
28
|
+
def initialize(model)
|
29
|
+
@model = model
|
37
30
|
load_defaults!
|
38
31
|
|
39
|
-
|
40
|
-
|
41
|
-
|
32
|
+
@on_success = true if on_success.nil?
|
33
|
+
@on_warning = true if on_warning.nil?
|
34
|
+
@on_failure = true if on_failure.nil?
|
42
35
|
end
|
43
36
|
|
44
37
|
##
|
45
38
|
# Performs the notification
|
46
|
-
# Takes
|
47
|
-
#
|
48
|
-
#
|
49
|
-
#
|
50
|
-
#
|
51
|
-
|
52
|
-
|
53
|
-
|
39
|
+
# Takes a flag to indicate that a failure has occured.
|
40
|
+
# (this is only set from Model#perform! in the event of an error)
|
41
|
+
# If this is the case it will set the 'action' to :failure.
|
42
|
+
# Otherwise, it will set the 'action' to either :success or :warning,
|
43
|
+
# depending on whether or not any warnings were sent to the Logger.
|
44
|
+
# It will then invoke the notify! method with the 'action',
|
45
|
+
# but only if the proper on_success, on_warning or on_failure flag is true.
|
46
|
+
def perform!(failure = false)
|
47
|
+
@template = Backup::Template.new({:model => @model})
|
54
48
|
|
55
49
|
action = false
|
56
|
-
if
|
50
|
+
if failure
|
51
|
+
action = :failure if notify_on_failure?
|
52
|
+
else
|
57
53
|
if notify_on_success? || (notify_on_warning? && Logger.has_warnings?)
|
58
54
|
action = Logger.has_warnings? ? :warning : :success
|
59
55
|
end
|
60
|
-
else
|
61
|
-
action = :failure if notify_on_failure?
|
62
56
|
end
|
63
57
|
|
64
58
|
if action
|
@@ -67,11 +61,19 @@ module Backup
|
|
67
61
|
end
|
68
62
|
end
|
69
63
|
|
64
|
+
private
|
65
|
+
|
66
|
+
##
|
67
|
+
# Return the notifier name, with Backup namespace removed
|
68
|
+
def notifier_name
|
69
|
+
self.class.to_s.sub('Backup::', '')
|
70
|
+
end
|
71
|
+
|
70
72
|
##
|
71
73
|
# Logs a message to the console and log file to inform
|
72
74
|
# the client that Backup is notifying about the process
|
73
75
|
def log!
|
74
|
-
Logger.message "#{
|
76
|
+
Logger.message "#{ notifier_name } started notifying about the process."
|
75
77
|
end
|
76
78
|
|
77
79
|
end
|
@@ -30,15 +30,13 @@ module Backup
|
|
30
30
|
# Campfire account's room id
|
31
31
|
attr_accessor :room_id
|
32
32
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
def perform!(model, exception = false)
|
38
|
-
super(model, exception)
|
33
|
+
def initialize(model, &block)
|
34
|
+
super(model)
|
35
|
+
|
36
|
+
instance_eval(&block) if block_given?
|
39
37
|
end
|
40
38
|
|
41
|
-
|
39
|
+
private
|
42
40
|
|
43
41
|
##
|
44
42
|
# Notify the user of the backup operation results.
|
@@ -65,14 +63,10 @@ module Backup
|
|
65
63
|
when :warning then 'Warning'
|
66
64
|
when :failure then 'Failure'
|
67
65
|
end
|
68
|
-
message = "[Backup::%s] #{model.label} (#{model.trigger})" % name
|
66
|
+
message = "[Backup::%s] #{@model.label} (#{@model.trigger})" % name
|
69
67
|
send_message(message)
|
70
68
|
end
|
71
69
|
|
72
|
-
##
|
73
|
-
# nothing to do
|
74
|
-
def set_defaults!; end
|
75
|
-
|
76
70
|
##
|
77
71
|
# Creates a new Campfire::Interface object and passes in the
|
78
72
|
# campfire clients "room_id", "subdomain" and "api_token". Using this object
|
@@ -138,7 +132,7 @@ module Backup
|
|
138
132
|
send_message(message)
|
139
133
|
end
|
140
134
|
|
141
|
-
|
135
|
+
private
|
142
136
|
|
143
137
|
##
|
144
138
|
# Takes a "message" as argument, the "type" defaults to "Textmessage".
|
@@ -26,39 +26,38 @@ module Backup
|
|
26
26
|
attr_accessor :rooms_notified
|
27
27
|
|
28
28
|
##
|
29
|
-
#
|
29
|
+
# Notify users in the room
|
30
|
+
attr_accessor :notify_users
|
31
|
+
|
32
|
+
##
|
33
|
+
# The background color of a success message.
|
34
|
+
# One of :yellow, :red, :green, :purple, or :random. (default: yellow)
|
30
35
|
attr_accessor :success_color
|
31
36
|
|
32
37
|
##
|
33
|
-
# The background color of a warning message.
|
38
|
+
# The background color of a warning message.
|
39
|
+
# One of :yellow, :red, :green, :purple, or :random. (default: yellow)
|
34
40
|
attr_accessor :warning_color
|
35
41
|
|
36
42
|
##
|
37
|
-
# The background color of an error message.
|
43
|
+
# The background color of an error message.
|
44
|
+
# One of :yellow, :red, :green, :purple, or :random. (default: yellow)
|
38
45
|
attr_accessor :failure_color
|
39
46
|
|
40
|
-
|
41
|
-
|
42
|
-
attr_accessor :notify_users
|
43
|
-
|
44
|
-
##
|
45
|
-
# Performs the notification
|
46
|
-
# Extends from super class. Must call super(model, exception).
|
47
|
-
# If any pre-configuration needs to be done, put it above the super(model, exception)
|
48
|
-
def perform!(model, exception = false)
|
49
|
-
@rooms_notified = [rooms_notified].flatten
|
50
|
-
super(model, exception)
|
51
|
-
end
|
47
|
+
def initialize(model, &block)
|
48
|
+
super(model)
|
52
49
|
|
53
|
-
|
50
|
+
@notify_users ||= false
|
51
|
+
@rooms_notified ||= []
|
52
|
+
@success_color ||= 'yellow'
|
53
|
+
@warning_color ||= 'yellow'
|
54
|
+
@failure_color ||= 'yellow'
|
54
55
|
|
55
|
-
|
56
|
-
client = HipChat::Client.new(token)
|
57
|
-
rooms_notified.each do |room|
|
58
|
-
client[room].send(from, msg, :color => color, :notify => notify)
|
59
|
-
end
|
56
|
+
instance_eval(&block) if block_given?
|
60
57
|
end
|
61
58
|
|
59
|
+
private
|
60
|
+
|
62
61
|
##
|
63
62
|
# Notify the user of the backup operation results.
|
64
63
|
# `status` indicates one of the following:
|
@@ -84,16 +83,17 @@ module Backup
|
|
84
83
|
when :warning then ['Warning', warning_color]
|
85
84
|
when :failure then ['Failure', failure_color]
|
86
85
|
end
|
87
|
-
message = "[Backup::%s] #{model.label} (#{model.trigger})" % name
|
88
|
-
send_message(message, color
|
86
|
+
message = "[Backup::%s] #{@model.label} (#{@model.trigger})" % name
|
87
|
+
send_message(message, color)
|
89
88
|
end
|
90
89
|
|
91
|
-
def
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
90
|
+
def send_message(msg, color)
|
91
|
+
client = HipChat::Client.new(token)
|
92
|
+
[rooms_notified].flatten.each do |room|
|
93
|
+
client[room].send(from, msg, :color => color, :notify => notify_users)
|
94
|
+
end
|
96
95
|
end
|
96
|
+
|
97
97
|
end
|
98
98
|
end
|
99
99
|
end
|
data/lib/backup/notifier/mail.rb
CHANGED
@@ -8,10 +8,6 @@ module Backup
|
|
8
8
|
module Notifier
|
9
9
|
class Mail < Base
|
10
10
|
|
11
|
-
##
|
12
|
-
# Container for the Mail object
|
13
|
-
attr_reader :mail
|
14
|
-
|
15
11
|
##
|
16
12
|
# Mail delivery method to be used by the Mail gem.
|
17
13
|
# Supported methods:
|
@@ -94,15 +90,13 @@ module Backup
|
|
94
90
|
# Example: '/tmp/test-mails'
|
95
91
|
attr_accessor :mail_folder
|
96
92
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
def perform!(model, exception = false)
|
102
|
-
super(model, exception)
|
93
|
+
def initialize(model, &block)
|
94
|
+
super(model)
|
95
|
+
|
96
|
+
instance_eval(&block) if block_given?
|
103
97
|
end
|
104
98
|
|
105
|
-
|
99
|
+
private
|
106
100
|
|
107
101
|
##
|
108
102
|
# Notify the user of the backup operation results.
|
@@ -130,27 +124,31 @@ module Backup
|
|
130
124
|
when :warning then [ 'Warning', true ]
|
131
125
|
when :failure then [ 'Failure', true ]
|
132
126
|
end
|
133
|
-
|
134
|
-
|
127
|
+
|
128
|
+
email = new_email
|
129
|
+
email.subject = "[Backup::%s] #{@model.label} (#{@model.trigger})" % name
|
130
|
+
email.body = @template.result('notifier/mail/%s.erb' % status.to_s)
|
131
|
+
|
135
132
|
if send_log
|
136
|
-
|
137
|
-
|
133
|
+
email.convert_to_multipart
|
134
|
+
email.attachments["#{@model.time}.#{@model.trigger}.log"] = {
|
138
135
|
:mime_type => 'text/plain;',
|
139
136
|
:content => Logger.messages.join("\n")
|
140
137
|
}
|
141
138
|
end
|
142
|
-
|
139
|
+
|
140
|
+
email.deliver!
|
143
141
|
end
|
144
142
|
|
145
143
|
##
|
146
144
|
# Configures the Mail gem by setting the defaults.
|
147
|
-
#
|
148
|
-
def
|
149
|
-
|
145
|
+
# Creates and returns a new email, based on the @delivery_method used.
|
146
|
+
def new_email
|
147
|
+
method = %w{ smtp sendmail file test }.
|
150
148
|
index(@delivery_method.to_s) ? @delivery_method.to_s : 'smtp'
|
151
149
|
|
152
150
|
options =
|
153
|
-
case
|
151
|
+
case method
|
154
152
|
when 'smtp'
|
155
153
|
{ :address => @address,
|
156
154
|
:port => @port,
|
@@ -166,19 +164,19 @@ module Backup
|
|
166
164
|
opts.merge!(:arguments => @sendmail_args) if @sendmail_args
|
167
165
|
opts
|
168
166
|
when 'file'
|
169
|
-
@mail_folder ||=
|
167
|
+
@mail_folder ||= File.join(Config.root_path, 'emails')
|
170
168
|
{ :location => File.expand_path(@mail_folder) }
|
171
169
|
when 'test' then {}
|
172
170
|
end
|
173
171
|
|
174
|
-
method = @delivery_method.to_sym
|
175
172
|
::Mail.defaults do
|
176
|
-
delivery_method method, options
|
173
|
+
delivery_method method.to_sym, options
|
177
174
|
end
|
178
175
|
|
179
|
-
|
180
|
-
|
181
|
-
|
176
|
+
email = ::Mail.new
|
177
|
+
email.to = @to
|
178
|
+
email.from = @from
|
179
|
+
email
|
182
180
|
end
|
183
181
|
|
184
182
|
end
|
@@ -6,10 +6,6 @@ module Backup
|
|
6
6
|
module Notifier
|
7
7
|
class Presently < Base
|
8
8
|
|
9
|
-
##
|
10
|
-
# Container for the Presently Client object
|
11
|
-
attr_accessor :presently_client
|
12
|
-
|
13
9
|
##
|
14
10
|
# Presently subdomain
|
15
11
|
attr_accessor :subdomain
|
@@ -22,16 +18,13 @@ module Backup
|
|
22
18
|
# Group id
|
23
19
|
attr_accessor :group_id
|
24
20
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
# put it above the super(model, exception)
|
30
|
-
def perform!(model, exception = false)
|
31
|
-
super(model, exception)
|
21
|
+
def initialize(model, &block)
|
22
|
+
super(model)
|
23
|
+
|
24
|
+
instance_eval(&block) if block_given?
|
32
25
|
end
|
33
26
|
|
34
|
-
|
27
|
+
private
|
35
28
|
|
36
29
|
##
|
37
30
|
# Notify the user of the backup operation results.
|
@@ -58,14 +51,13 @@ module Backup
|
|
58
51
|
when :warning then 'Warning'
|
59
52
|
when :failure then 'Failure'
|
60
53
|
end
|
61
|
-
message = "[Backup::%s] #{model.label} (#{model.trigger})" % name
|
62
|
-
|
54
|
+
message = "[Backup::%s] #{@model.label} (#{@model.trigger})" % name
|
55
|
+
send_message(message)
|
63
56
|
end
|
64
57
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
@presently_client = Client.new(subdomain, user_name, password, group_id)
|
58
|
+
def send_message(message)
|
59
|
+
client = Client.new(subdomain, user_name, password, group_id)
|
60
|
+
client.update(message)
|
69
61
|
end
|
70
62
|
|
71
63
|
class Client
|
@@ -8,10 +8,6 @@ module Backup
|
|
8
8
|
module Notifier
|
9
9
|
class Prowl < Base
|
10
10
|
|
11
|
-
##
|
12
|
-
# Container for the Twitter Client object
|
13
|
-
attr_accessor :prowl_client
|
14
|
-
|
15
11
|
##
|
16
12
|
# Application name
|
17
13
|
# Tell something like your server name. Example: "Server1 Backup"
|
@@ -22,15 +18,13 @@ module Backup
|
|
22
18
|
# Create a Prowl account and request an API key on prowlapp.com.
|
23
19
|
attr_accessor :api_key
|
24
20
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
def perform!(model, exception = false)
|
30
|
-
super(model, exception)
|
21
|
+
def initialize(model, &block)
|
22
|
+
super(model)
|
23
|
+
|
24
|
+
instance_eval(&block) if block_given?
|
31
25
|
end
|
32
26
|
|
33
|
-
|
27
|
+
private
|
34
28
|
|
35
29
|
##
|
36
30
|
# Notify the user of the backup operation results.
|
@@ -58,14 +52,12 @@ module Backup
|
|
58
52
|
when :failure then 'Failure'
|
59
53
|
end
|
60
54
|
message = '[Backup::%s]' % name
|
61
|
-
|
55
|
+
send_message(message)
|
62
56
|
end
|
63
57
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
def set_defaults!
|
68
|
-
@prowl_client = Prowler.new(:application => application, :api_key => api_key)
|
58
|
+
def send_message(message)
|
59
|
+
client = Prowler.new(:application => application, :api_key => api_key)
|
60
|
+
client.notify(message, "#{@model.label} (#{@model.trigger})")
|
69
61
|
end
|
70
62
|
|
71
63
|
end
|
@@ -8,10 +8,6 @@ module Backup
|
|
8
8
|
module Notifier
|
9
9
|
class Twitter < Base
|
10
10
|
|
11
|
-
##
|
12
|
-
# Container for the Twitter Client object
|
13
|
-
attr_accessor :twitter_client
|
14
|
-
|
15
11
|
##
|
16
12
|
# Twitter consumer key credentials
|
17
13
|
attr_accessor :consumer_key, :consumer_secret
|
@@ -20,15 +16,13 @@ module Backup
|
|
20
16
|
# OAuth credentials
|
21
17
|
attr_accessor :oauth_token, :oauth_token_secret
|
22
18
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
def perform!(model, exception = false)
|
28
|
-
super(model, exception)
|
19
|
+
def initialize(model, &block)
|
20
|
+
super(model)
|
21
|
+
|
22
|
+
instance_eval(&block) if block_given?
|
29
23
|
end
|
30
24
|
|
31
|
-
|
25
|
+
private
|
32
26
|
|
33
27
|
##
|
34
28
|
# Notify the user of the backup operation results.
|
@@ -55,21 +49,20 @@ module Backup
|
|
55
49
|
when :warning then 'Warning'
|
56
50
|
when :failure then 'Failure'
|
57
51
|
end
|
58
|
-
message = "[Backup::%s] #{model.label} (#{model.trigger})" % name
|
59
|
-
|
52
|
+
message = "[Backup::%s] #{@model.label} (#{@model.trigger})" % name
|
53
|
+
send_message(message)
|
60
54
|
end
|
61
55
|
|
62
|
-
|
63
|
-
# Configures the Twitter object by passing in the @consumer_key, @consumer_secret
|
64
|
-
# @oauth_token and @oauth_token_secret. Instantiates and sets the @twitter_client object
|
65
|
-
def set_defaults!
|
56
|
+
def send_message(message)
|
66
57
|
::Twitter.configure do |config|
|
67
58
|
config.consumer_key = @consumer_key
|
68
59
|
config.consumer_secret = @consumer_secret
|
69
60
|
config.oauth_token = @oauth_token
|
70
61
|
config.oauth_token_secret = @oauth_token_secret
|
71
62
|
end
|
72
|
-
|
63
|
+
|
64
|
+
client = ::Twitter::Client.new
|
65
|
+
client.update(message)
|
73
66
|
end
|
74
67
|
|
75
68
|
end
|