backup-agoddard 3.0.27

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 (190) hide show
  1. data/.gitignore +8 -0
  2. data/.travis.yml +10 -0
  3. data/Gemfile +28 -0
  4. data/Guardfile +23 -0
  5. data/LICENSE.md +24 -0
  6. data/README.md +478 -0
  7. data/backup.gemspec +32 -0
  8. data/bin/backup +11 -0
  9. data/lib/backup.rb +133 -0
  10. data/lib/backup/archive.rb +117 -0
  11. data/lib/backup/binder.rb +22 -0
  12. data/lib/backup/cleaner.rb +121 -0
  13. data/lib/backup/cli/helpers.rb +93 -0
  14. data/lib/backup/cli/utility.rb +255 -0
  15. data/lib/backup/compressor/base.rb +35 -0
  16. data/lib/backup/compressor/bzip2.rb +50 -0
  17. data/lib/backup/compressor/custom.rb +53 -0
  18. data/lib/backup/compressor/gzip.rb +50 -0
  19. data/lib/backup/compressor/lzma.rb +52 -0
  20. data/lib/backup/compressor/pbzip2.rb +59 -0
  21. data/lib/backup/config.rb +174 -0
  22. data/lib/backup/configuration.rb +33 -0
  23. data/lib/backup/configuration/helpers.rb +130 -0
  24. data/lib/backup/configuration/store.rb +24 -0
  25. data/lib/backup/database/base.rb +53 -0
  26. data/lib/backup/database/mongodb.rb +230 -0
  27. data/lib/backup/database/mysql.rb +160 -0
  28. data/lib/backup/database/postgresql.rb +144 -0
  29. data/lib/backup/database/redis.rb +136 -0
  30. data/lib/backup/database/riak.rb +67 -0
  31. data/lib/backup/dependency.rb +108 -0
  32. data/lib/backup/encryptor/base.rb +29 -0
  33. data/lib/backup/encryptor/gpg.rb +760 -0
  34. data/lib/backup/encryptor/open_ssl.rb +72 -0
  35. data/lib/backup/errors.rb +124 -0
  36. data/lib/backup/hooks.rb +68 -0
  37. data/lib/backup/logger.rb +152 -0
  38. data/lib/backup/model.rb +409 -0
  39. data/lib/backup/notifier/base.rb +81 -0
  40. data/lib/backup/notifier/campfire.rb +155 -0
  41. data/lib/backup/notifier/hipchat.rb +93 -0
  42. data/lib/backup/notifier/mail.rb +206 -0
  43. data/lib/backup/notifier/prowl.rb +65 -0
  44. data/lib/backup/notifier/pushover.rb +88 -0
  45. data/lib/backup/notifier/twitter.rb +70 -0
  46. data/lib/backup/package.rb +47 -0
  47. data/lib/backup/packager.rb +100 -0
  48. data/lib/backup/pipeline.rb +110 -0
  49. data/lib/backup/splitter.rb +75 -0
  50. data/lib/backup/storage/base.rb +99 -0
  51. data/lib/backup/storage/cloudfiles.rb +87 -0
  52. data/lib/backup/storage/cycler.rb +117 -0
  53. data/lib/backup/storage/dropbox.rb +178 -0
  54. data/lib/backup/storage/ftp.rb +119 -0
  55. data/lib/backup/storage/local.rb +82 -0
  56. data/lib/backup/storage/ninefold.rb +116 -0
  57. data/lib/backup/storage/rsync.rb +149 -0
  58. data/lib/backup/storage/s3.rb +94 -0
  59. data/lib/backup/storage/scp.rb +99 -0
  60. data/lib/backup/storage/sftp.rb +108 -0
  61. data/lib/backup/syncer/base.rb +46 -0
  62. data/lib/backup/syncer/cloud/base.rb +247 -0
  63. data/lib/backup/syncer/cloud/cloud_files.rb +78 -0
  64. data/lib/backup/syncer/cloud/s3.rb +68 -0
  65. data/lib/backup/syncer/rsync/base.rb +49 -0
  66. data/lib/backup/syncer/rsync/local.rb +55 -0
  67. data/lib/backup/syncer/rsync/pull.rb +36 -0
  68. data/lib/backup/syncer/rsync/push.rb +116 -0
  69. data/lib/backup/template.rb +46 -0
  70. data/lib/backup/version.rb +43 -0
  71. data/spec-live/.gitignore +6 -0
  72. data/spec-live/README +7 -0
  73. data/spec-live/backups/config.rb +83 -0
  74. data/spec-live/backups/config.yml.template +46 -0
  75. data/spec-live/backups/models.rb +184 -0
  76. data/spec-live/compressor/custom_spec.rb +30 -0
  77. data/spec-live/compressor/gzip_spec.rb +30 -0
  78. data/spec-live/encryptor/gpg_keys.rb +239 -0
  79. data/spec-live/encryptor/gpg_spec.rb +287 -0
  80. data/spec-live/notifier/mail_spec.rb +121 -0
  81. data/spec-live/spec_helper.rb +151 -0
  82. data/spec-live/storage/dropbox_spec.rb +151 -0
  83. data/spec-live/storage/local_spec.rb +83 -0
  84. data/spec-live/storage/scp_spec.rb +193 -0
  85. data/spec-live/syncer/cloud/s3_spec.rb +124 -0
  86. data/spec/archive_spec.rb +335 -0
  87. data/spec/cleaner_spec.rb +312 -0
  88. data/spec/cli/helpers_spec.rb +301 -0
  89. data/spec/cli/utility_spec.rb +411 -0
  90. data/spec/compressor/base_spec.rb +52 -0
  91. data/spec/compressor/bzip2_spec.rb +217 -0
  92. data/spec/compressor/custom_spec.rb +106 -0
  93. data/spec/compressor/gzip_spec.rb +217 -0
  94. data/spec/compressor/lzma_spec.rb +123 -0
  95. data/spec/compressor/pbzip2_spec.rb +165 -0
  96. data/spec/config_spec.rb +321 -0
  97. data/spec/configuration/helpers_spec.rb +247 -0
  98. data/spec/configuration/store_spec.rb +39 -0
  99. data/spec/configuration_spec.rb +62 -0
  100. data/spec/database/base_spec.rb +63 -0
  101. data/spec/database/mongodb_spec.rb +510 -0
  102. data/spec/database/mysql_spec.rb +411 -0
  103. data/spec/database/postgresql_spec.rb +353 -0
  104. data/spec/database/redis_spec.rb +334 -0
  105. data/spec/database/riak_spec.rb +176 -0
  106. data/spec/dependency_spec.rb +51 -0
  107. data/spec/encryptor/base_spec.rb +40 -0
  108. data/spec/encryptor/gpg_spec.rb +909 -0
  109. data/spec/encryptor/open_ssl_spec.rb +148 -0
  110. data/spec/errors_spec.rb +306 -0
  111. data/spec/hooks_spec.rb +35 -0
  112. data/spec/logger_spec.rb +367 -0
  113. data/spec/model_spec.rb +694 -0
  114. data/spec/notifier/base_spec.rb +104 -0
  115. data/spec/notifier/campfire_spec.rb +217 -0
  116. data/spec/notifier/hipchat_spec.rb +211 -0
  117. data/spec/notifier/mail_spec.rb +316 -0
  118. data/spec/notifier/prowl_spec.rb +138 -0
  119. data/spec/notifier/pushover_spec.rb +123 -0
  120. data/spec/notifier/twitter_spec.rb +153 -0
  121. data/spec/package_spec.rb +61 -0
  122. data/spec/packager_spec.rb +213 -0
  123. data/spec/pipeline_spec.rb +259 -0
  124. data/spec/spec_helper.rb +60 -0
  125. data/spec/splitter_spec.rb +120 -0
  126. data/spec/storage/base_spec.rb +166 -0
  127. data/spec/storage/cloudfiles_spec.rb +254 -0
  128. data/spec/storage/cycler_spec.rb +247 -0
  129. data/spec/storage/dropbox_spec.rb +480 -0
  130. data/spec/storage/ftp_spec.rb +271 -0
  131. data/spec/storage/local_spec.rb +259 -0
  132. data/spec/storage/ninefold_spec.rb +343 -0
  133. data/spec/storage/rsync_spec.rb +362 -0
  134. data/spec/storage/s3_spec.rb +245 -0
  135. data/spec/storage/scp_spec.rb +233 -0
  136. data/spec/storage/sftp_spec.rb +244 -0
  137. data/spec/syncer/base_spec.rb +109 -0
  138. data/spec/syncer/cloud/base_spec.rb +515 -0
  139. data/spec/syncer/cloud/cloud_files_spec.rb +181 -0
  140. data/spec/syncer/cloud/s3_spec.rb +174 -0
  141. data/spec/syncer/rsync/base_spec.rb +98 -0
  142. data/spec/syncer/rsync/local_spec.rb +149 -0
  143. data/spec/syncer/rsync/pull_spec.rb +98 -0
  144. data/spec/syncer/rsync/push_spec.rb +333 -0
  145. data/spec/version_spec.rb +21 -0
  146. data/templates/cli/utility/archive +25 -0
  147. data/templates/cli/utility/compressor/bzip2 +4 -0
  148. data/templates/cli/utility/compressor/custom +11 -0
  149. data/templates/cli/utility/compressor/gzip +4 -0
  150. data/templates/cli/utility/compressor/lzma +10 -0
  151. data/templates/cli/utility/compressor/pbzip2 +10 -0
  152. data/templates/cli/utility/config +32 -0
  153. data/templates/cli/utility/database/mongodb +18 -0
  154. data/templates/cli/utility/database/mysql +21 -0
  155. data/templates/cli/utility/database/postgresql +17 -0
  156. data/templates/cli/utility/database/redis +16 -0
  157. data/templates/cli/utility/database/riak +11 -0
  158. data/templates/cli/utility/encryptor/gpg +27 -0
  159. data/templates/cli/utility/encryptor/openssl +9 -0
  160. data/templates/cli/utility/model.erb +23 -0
  161. data/templates/cli/utility/notifier/campfire +12 -0
  162. data/templates/cli/utility/notifier/hipchat +15 -0
  163. data/templates/cli/utility/notifier/mail +22 -0
  164. data/templates/cli/utility/notifier/prowl +11 -0
  165. data/templates/cli/utility/notifier/pushover +11 -0
  166. data/templates/cli/utility/notifier/twitter +13 -0
  167. data/templates/cli/utility/splitter +7 -0
  168. data/templates/cli/utility/storage/cloud_files +22 -0
  169. data/templates/cli/utility/storage/dropbox +20 -0
  170. data/templates/cli/utility/storage/ftp +12 -0
  171. data/templates/cli/utility/storage/local +7 -0
  172. data/templates/cli/utility/storage/ninefold +9 -0
  173. data/templates/cli/utility/storage/rsync +11 -0
  174. data/templates/cli/utility/storage/s3 +19 -0
  175. data/templates/cli/utility/storage/scp +11 -0
  176. data/templates/cli/utility/storage/sftp +11 -0
  177. data/templates/cli/utility/syncer/cloud_files +46 -0
  178. data/templates/cli/utility/syncer/rsync_local +12 -0
  179. data/templates/cli/utility/syncer/rsync_pull +17 -0
  180. data/templates/cli/utility/syncer/rsync_push +17 -0
  181. data/templates/cli/utility/syncer/s3 +43 -0
  182. data/templates/general/links +11 -0
  183. data/templates/general/version.erb +2 -0
  184. data/templates/notifier/mail/failure.erb +9 -0
  185. data/templates/notifier/mail/success.erb +7 -0
  186. data/templates/notifier/mail/warning.erb +9 -0
  187. data/templates/storage/dropbox/authorization_url.erb +6 -0
  188. data/templates/storage/dropbox/authorized.erb +4 -0
  189. data/templates/storage/dropbox/cache_file_written.erb +10 -0
  190. metadata +277 -0
@@ -0,0 +1,81 @@
1
+ # encoding: utf-8
2
+
3
+ module Backup
4
+ module Notifier
5
+ class Base
6
+ include Backup::Configuration::Helpers
7
+
8
+ ##
9
+ # When set to true, the user will be notified by email
10
+ # when a backup process ends without raising any exceptions
11
+ attr_accessor :on_success
12
+ alias :notify_on_success? :on_success
13
+
14
+ ##
15
+ # When set to true, the user will be notified by email
16
+ # when a backup process is successful, but has warnings
17
+ attr_accessor :on_warning
18
+ alias :notify_on_warning? :on_warning
19
+
20
+ ##
21
+ # When set to true, the user will be notified by email
22
+ # when a backup process raises an exception before finishing
23
+ attr_accessor :on_failure
24
+ alias :notify_on_failure? :on_failure
25
+
26
+ ##
27
+ # Called with super(model) from subclasses
28
+ def initialize(model)
29
+ @model = model
30
+ load_defaults!
31
+
32
+ @on_success = true if on_success.nil?
33
+ @on_warning = true if on_warning.nil?
34
+ @on_failure = true if on_failure.nil?
35
+ end
36
+
37
+ ##
38
+ # Performs the notification
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})
48
+
49
+ action = false
50
+ if failure
51
+ action = :failure if notify_on_failure?
52
+ else
53
+ if notify_on_success? || (notify_on_warning? && Logger.has_warnings?)
54
+ action = Logger.has_warnings? ? :warning : :success
55
+ end
56
+ end
57
+
58
+ if action
59
+ log!
60
+ notify!(action)
61
+ end
62
+ end
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
+
72
+ ##
73
+ # Logs a message to the console and log file to inform
74
+ # the client that Backup is notifying about the process
75
+ def log!
76
+ Logger.message "#{ notifier_name } started notifying about the process."
77
+ end
78
+
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,155 @@
1
+ # encoding: utf-8
2
+
3
+ ##
4
+ # Load the HTTParty library from the gem
5
+ Backup::Dependency.load('httparty')
6
+
7
+ module Backup
8
+ module Notifier
9
+ class Campfire < Base
10
+
11
+ ##
12
+ # Campfire api authentication token
13
+ attr_accessor :api_token
14
+
15
+ ##
16
+ # Campfire account's subdomain
17
+ attr_accessor :subdomain
18
+
19
+ ##
20
+ # Campfire account's room id
21
+ attr_accessor :room_id
22
+
23
+ def initialize(model, &block)
24
+ super(model)
25
+
26
+ instance_eval(&block) if block_given?
27
+ end
28
+
29
+ private
30
+
31
+ ##
32
+ # Notify the user of the backup operation results.
33
+ # `status` indicates one of the following:
34
+ #
35
+ # `:success`
36
+ # : The backup completed successfully.
37
+ # : Notification will be sent if `on_success` was set to `true`
38
+ #
39
+ # `:warning`
40
+ # : The backup completed successfully, but warnings were logged
41
+ # : Notification will be sent, including a copy of the current
42
+ # : backup log, if `on_warning` was set to `true`
43
+ #
44
+ # `:failure`
45
+ # : The backup operation failed.
46
+ # : Notification will be sent, including the Exception which caused
47
+ # : the failure, the Exception's backtrace, a copy of the current
48
+ # : backup log and other information if `on_failure` was set to `true`
49
+ #
50
+ def notify!(status)
51
+ name = case status
52
+ when :success then 'Success'
53
+ when :warning then 'Warning'
54
+ when :failure then 'Failure'
55
+ end
56
+ message = "[Backup::%s] #{@model.label} (#{@model.trigger})" % name
57
+ send_message(message)
58
+ end
59
+
60
+ ##
61
+ # Creates a new Campfire::Interface object and passes in the
62
+ # campfire clients "room_id", "subdomain" and "api_token". Using this object
63
+ # the provided "message" will be sent to the desired Campfire chat room
64
+ def send_message(message)
65
+ room = Interface.room(room_id, subdomain, api_token)
66
+ room.message(message)
67
+ end
68
+
69
+ ##
70
+ # The Campfire::Interface acts as the Interface for the Campfire class.
71
+ # It uses the HTTParty library and the Campfire::Room class to communicate
72
+ # with the Campfire rooms. HTTParty provides the Campfire::Interface with the methods
73
+ # necessary to communicate (inside the HTTParty module) such as the class methods:
74
+ # * post
75
+ # * base_uri
76
+ # * basic_auth
77
+ class Interface
78
+ include HTTParty
79
+
80
+ ##
81
+ # We communicate using the JSON data format
82
+ headers 'Content-Type' => 'application/json'
83
+
84
+ ##
85
+ # Instantiates a new Campfire::Room object with
86
+ # the provided arguments and returns this object
87
+ def self.room(room_id, subdomain, api_token)
88
+ Room.new(room_id, subdomain, api_token)
89
+ end
90
+ end
91
+
92
+ ##
93
+ # The Campfire::Room acts as a model for an actual room on the Campfire service.
94
+ # And it uses the Campfire::Interface's (HTTParty) class methods to communicate based
95
+ # on the provided parameters (room_id, subdomain and api_token)
96
+ class Room
97
+
98
+ ##
99
+ # Campfire api authentication api_token
100
+ attr_accessor :api_token
101
+
102
+ ##
103
+ # Campfire account's subdomain
104
+ attr_accessor :subdomain
105
+
106
+ ##
107
+ # Campfire account's room id
108
+ attr_accessor :room_id
109
+
110
+ ##
111
+ # Instantiates a new Campfire::Room object and sets all the
112
+ # necessary arguments (@room_id, @subdomain, @api_token)
113
+ def initialize(room_id, subdomain, api_token)
114
+ @room_id = room_id
115
+ @subdomain = subdomain
116
+ @api_token = api_token
117
+ end
118
+
119
+ ##
120
+ # Wrapper method for the #send_message (private) method
121
+ def message(message)
122
+ send_message(message)
123
+ end
124
+
125
+ private
126
+
127
+ ##
128
+ # Takes a "message" as argument, the "type" defaults to "Textmessage".
129
+ # This method builds up a POST request with the necessary params (serialized to JSON format)
130
+ # and sends it to the Campfire service in order to submit the message
131
+ def send_message(message, type = 'Textmessage')
132
+ post 'speak', :body => MultiJson.encode(
133
+ { :message => { :body => message, :type => type } }
134
+ )
135
+ end
136
+
137
+ ##
138
+ # Builds/sets up the Campfire::Interface attributes and submits
139
+ # the POST request that was built in the #send_message (private) method
140
+ def post(action, options = {})
141
+ Interface.base_uri("https://#{subdomain}.campfirenow.com")
142
+ Interface.basic_auth(api_token, 'x')
143
+ Interface.post(room_url_for(action), options)
144
+ end
145
+
146
+ ##
147
+ # Returns the url for the specified room (in JSON format)
148
+ def room_url_for(action)
149
+ "/room/#{room_id}/#{action}.json"
150
+ end
151
+ end
152
+
153
+ end
154
+ end
155
+ end
@@ -0,0 +1,93 @@
1
+ # encoding: utf-8
2
+
3
+ # Load the HipChat library from the gem
4
+ Backup::Dependency.load('hipchat')
5
+
6
+ module Backup
7
+ module Notifier
8
+ class Hipchat < Base
9
+
10
+ ##
11
+ # The Hipchat API token
12
+ attr_accessor :token
13
+
14
+ ##
15
+ # Who the notification should appear from
16
+ attr_accessor :from
17
+
18
+ ##
19
+ # The rooms that should be notified
20
+ attr_accessor :rooms_notified
21
+
22
+ ##
23
+ # Notify users in the room
24
+ attr_accessor :notify_users
25
+
26
+ ##
27
+ # The background color of a success message.
28
+ # One of :yellow, :red, :green, :purple, or :random. (default: yellow)
29
+ attr_accessor :success_color
30
+
31
+ ##
32
+ # The background color of a warning message.
33
+ # One of :yellow, :red, :green, :purple, or :random. (default: yellow)
34
+ attr_accessor :warning_color
35
+
36
+ ##
37
+ # The background color of an error message.
38
+ # One of :yellow, :red, :green, :purple, or :random. (default: yellow)
39
+ attr_accessor :failure_color
40
+
41
+ def initialize(model, &block)
42
+ super(model)
43
+
44
+ @notify_users ||= false
45
+ @rooms_notified ||= []
46
+ @success_color ||= 'yellow'
47
+ @warning_color ||= 'yellow'
48
+ @failure_color ||= 'yellow'
49
+
50
+ instance_eval(&block) if block_given?
51
+ end
52
+
53
+ private
54
+
55
+ ##
56
+ # Notify the user of the backup operation results.
57
+ # `status` indicates one of the following:
58
+ #
59
+ # `:success`
60
+ # : The backup completed successfully.
61
+ # : Notification will be sent if `on_success` was set to `true`
62
+ #
63
+ # `:warning`
64
+ # : The backup completed successfully, but warnings were logged
65
+ # : Notification will be sent, including a copy of the current
66
+ # : backup log, if `on_warning` was set to `true`
67
+ #
68
+ # `:failure`
69
+ # : The backup operation failed.
70
+ # : Notification will be sent, including the Exception which caused
71
+ # : the failure, the Exception's backtrace, a copy of the current
72
+ # : backup log and other information if `on_failure` was set to `true`
73
+ #
74
+ def notify!(status)
75
+ name, color = case status
76
+ when :success then ['Success', success_color]
77
+ when :warning then ['Warning', warning_color]
78
+ when :failure then ['Failure', failure_color]
79
+ end
80
+ message = "[Backup::%s] #{@model.label} (#{@model.trigger})" % name
81
+ send_message(message, color)
82
+ end
83
+
84
+ def send_message(msg, color)
85
+ client = HipChat::Client.new(token)
86
+ [rooms_notified].flatten.each do |room|
87
+ client[room].send(from, msg, :color => color, :notify => notify_users)
88
+ end
89
+ end
90
+
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,206 @@
1
+ # encoding: utf-8
2
+
3
+ ##
4
+ # Only load the Mail gem when using Mail notifications
5
+ Backup::Dependency.load('mail')
6
+
7
+ module Backup
8
+ module Notifier
9
+ class Mail < Base
10
+
11
+ ##
12
+ # Mail delivery method to be used by the Mail gem.
13
+ # Supported methods:
14
+ #
15
+ # `:smtp` [::Mail::SMTP] (default)
16
+ # : Settings used only by this method:
17
+ # : `address`, `port`, `domain`, `user_name`, `password`
18
+ # : `authentication`, `enable_starttls_auto`, `openssl_verify_mode`
19
+ #
20
+ # `:sendmail` [::Mail::Sendmail]
21
+ # : Settings used only by this method:
22
+ # : `sendmail`, `sendmail_args`
23
+ #
24
+ # `:exim` [::Mail::Exim]
25
+ # : Settings used only by this method:
26
+ # : `exim`, `exim_args`
27
+ #
28
+ # `:file` [::Mail::FileDelivery]
29
+ # : Settings used only by this method:
30
+ # : `mail_folder`
31
+ #
32
+ attr_accessor :delivery_method
33
+
34
+ ##
35
+ # Sender and Receiver email addresses
36
+ # Examples:
37
+ # sender - my.email.address@gmail.com
38
+ # receiver - your.email.address@gmail.com
39
+ attr_accessor :from, :to
40
+
41
+ ##
42
+ # The address to use
43
+ # Example: smtp.gmail.com
44
+ attr_accessor :address
45
+
46
+ ##
47
+ # The port to connect to
48
+ # Example: 587
49
+ attr_accessor :port
50
+
51
+ ##
52
+ # Your domain (if applicable)
53
+ # Example: mydomain.com
54
+ attr_accessor :domain
55
+
56
+ ##
57
+ # Username and Password (sender email's credentials)
58
+ # Examples:
59
+ # user_name - meskyanichi
60
+ # password - my_secret_password
61
+ attr_accessor :user_name, :password
62
+
63
+ ##
64
+ # Authentication type
65
+ # Example: plain
66
+ attr_accessor :authentication
67
+
68
+ ##
69
+ # Automatically set TLS
70
+ # Example: true
71
+ attr_accessor :enable_starttls_auto
72
+
73
+ ##
74
+ # OpenSSL Verify Mode
75
+ # Example: none - Only use this option for a self-signed and/or wildcard certificate
76
+ attr_accessor :openssl_verify_mode
77
+
78
+ ##
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
83
+
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
90
+
91
+ ##
92
+ # When using the `:exim` `delivery_method` option,
93
+ # this may be used to specify the absolute path to `exim` (if needed)
94
+ # Example: '/usr/sbin/exim'
95
+ attr_accessor :exim
96
+
97
+ ##
98
+ # Optional arguments to pass to `exim`
99
+ # Note that this will override the defaults set by the Mail gem (currently: '-i -t')
100
+ # So, if set here, be sure to set all the arguments you require.
101
+ # Example: '-i -t -X/tmp/traffic.log'
102
+ attr_accessor :exim_args
103
+
104
+ ##
105
+ # Folder where mail will be kept when using the `:file` `delivery_method` option.
106
+ # Default location is '$HOME/Backup/emails'
107
+ # Example: '/tmp/test-mails'
108
+ attr_accessor :mail_folder
109
+
110
+ def initialize(model, &block)
111
+ super(model)
112
+
113
+ instance_eval(&block) if block_given?
114
+ end
115
+
116
+ private
117
+
118
+ ##
119
+ # Notify the user of the backup operation results.
120
+ # `status` indicates one of the following:
121
+ #
122
+ # `:success`
123
+ # : The backup completed successfully.
124
+ # : Notification will be sent if `on_success` was set to `true`
125
+ #
126
+ # `:warning`
127
+ # : The backup completed successfully, but warnings were logged
128
+ # : Notification will be sent, including a copy of the current
129
+ # : backup log, if `on_warning` was set to `true`
130
+ #
131
+ # `:failure`
132
+ # : The backup operation failed.
133
+ # : Notification will be sent, including the Exception which caused
134
+ # : the failure, the Exception's backtrace, a copy of the current
135
+ # : backup log and other information if `on_failure` was set to `true`
136
+ #
137
+ def notify!(status)
138
+ name, send_log =
139
+ case status
140
+ when :success then [ 'Success', false ]
141
+ when :warning then [ 'Warning', true ]
142
+ when :failure then [ 'Failure', true ]
143
+ end
144
+
145
+ email = new_email
146
+ email.subject = "[Backup::%s] #{@model.label} (#{@model.trigger})" % name
147
+ email.body = @template.result('notifier/mail/%s.erb' % status.to_s)
148
+
149
+ if send_log
150
+ email.convert_to_multipart
151
+ email.attachments["#{@model.time}.#{@model.trigger}.log"] = {
152
+ :mime_type => 'text/plain;',
153
+ :content => Logger.messages.join("\n")
154
+ }
155
+ end
156
+
157
+ email.deliver!
158
+ end
159
+
160
+ ##
161
+ # Configures the Mail gem by setting the defaults.
162
+ # Creates and returns a new email, based on the @delivery_method used.
163
+ def new_email
164
+ method = %w{ smtp sendmail exim file test }.
165
+ index(@delivery_method.to_s) ? @delivery_method.to_s : 'smtp'
166
+
167
+ options =
168
+ case method
169
+ when 'smtp'
170
+ { :address => @address,
171
+ :port => @port,
172
+ :domain => @domain,
173
+ :user_name => @user_name,
174
+ :password => @password,
175
+ :authentication => @authentication,
176
+ :enable_starttls_auto => @enable_starttls_auto,
177
+ :openssl_verify_mode => @openssl_verify_mode }
178
+ when 'sendmail'
179
+ opts = {}
180
+ opts.merge!(:location => File.expand_path(@sendmail)) if @sendmail
181
+ opts.merge!(:arguments => @sendmail_args) if @sendmail_args
182
+ opts
183
+ when 'exim'
184
+ opts = {}
185
+ opts.merge!(:location => File.expand_path(@exim)) if @exim
186
+ opts.merge!(:arguments => @exim_args) if @exim_args
187
+ opts
188
+ when 'file'
189
+ @mail_folder ||= File.join(Config.root_path, 'emails')
190
+ { :location => File.expand_path(@mail_folder) }
191
+ when 'test' then {}
192
+ end
193
+
194
+ ::Mail.defaults do
195
+ delivery_method method.to_sym, options
196
+ end
197
+
198
+ email = ::Mail.new
199
+ email.to = @to
200
+ email.from = @from
201
+ email
202
+ end
203
+
204
+ end
205
+ end
206
+ end