Class: BackupReport

Inherits:
Object
  • Object
show all
Defined in:
lib/backup_report.rb

Instance Method Summary collapse

Constructor Details

#initialize(from = ENV['USER'], to = "root", mail_options = {}) ⇒ BackupReport

Returns a new instance of BackupReport.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/backup_report.rb', line 7

def initialize from = ENV['USER'],to = "root",mail_options = {}
  
  backups = []
  
  Keepitsafe.after_backup do |backup,values|
    backups << backup
  end
  
  start_time = Time.now
  capture = STDCapture.capture do 
    yield
  end
  end_time = Time.now
  
  # Send email report
  mail = MailBuilder.new("#{File.dirname(__FILE__)}/../email/report").build({:backups => backups, :start_time => start_time, :end_time => end_time})
  mail.to to
  mail.from from
  mail.subject "Backup report: #{backups.select {|b| b.error != nil}.count} Error"
  mail.delivery_method.settings = mail.delivery_method.settings.merge(mail_options)
  mail.deliver!
  
  puts "\nSent backup report to: #{to}"
  
end