Envio de Email personalizado

156 views
Skip to first unread message

Gabriel Motta

unread,
Jul 24, 2015, 1:09:59 PM7/24/15
to Bacula Backup-Pt-Br
Senhores,


Possuo cerca de 30 Jobs. Minha dúvida é a seguinte: Meu alerta de email é enviado somente se ocorrer erro! Porem, preciso que seja feito ao final de todos os backups, um novo email dizendo ("Os 30 jobs foi feito com sucesso"). Da maneira que esta hoje, se não ocorrer nenhum erro, não tenho nenhuma informação de execução de backup.

Segue abaixo a configuração de messagem do bacula.

########################################################################################################################################################################################
                 # Message delivery for daemon messages (no job).
                    Messages {
                    Name = Daemon
                    mailcommand = "/sbin/bsmtp -h SERVIDOR_EMAIL -f \"\(Bacula\) \<bac...@planejamento.rj.gov.br\>\" -s \"Bacula daemon message\" %r"
                    mail = monit...@gmail.com =  warning, error, fatal, security, notsaved, mount, alert
                    console = all, !skipped, !saved
                    append = "/etc/bacula/log/bacula.log" = all, !skipped
}
########################################################################################################################################################################################



Wanderlei

unread,
Jul 24, 2015, 1:21:39 PM7/24/15
to Bacula Backup-Pt-Br, gbtm...@gmail.com
Boa tarde Gabriel

Para receber os emails você deve configurar o "Messages Standard"

Messages {
  Name = Standard
  mailcommand = "/sbin/bsmtp -h localhost -f \"\(Bacula\) \<%r\>\" -s \"Bacula: %t %e of %c %l\" %r"
  operatorcommand = "/sbin/bsmtp -h localhost -f \"\(Bacula\) \<%r\>\" -s \"Bacula: Intervention needed for %j\" %r"
  mail = no...@dominio.com.br = all, !skipped
  operator = root@localhost = mount
  console = all, !skipped, !saved
  append = "/etc/bacula/log/bacula.log" = all, !skipped
  catalog = all, !skipped, !saved
}


Att Wanderlei

Gabriel Motta

unread,
Jul 24, 2015, 1:38:25 PM7/24/15
to Wanderlei, Bacula Backup-Pt-Br
Wanderlei,

Se eu colocar: all, !skipped para cada JOB executado irei receber um email dizendo:

Bacula: Backup OK of FULL

E o q preciso eh receber um unico email dizend: "Relatorio, 25 jobs Okay 5 Problem" ... <----Exemplo.


 Atenciosamente,


Gabriel Motta
gbtm...@gmail.com





Wanderlei

unread,
Jul 24, 2015, 2:56:56 PM7/24/15
to Bacula Backup-Pt-Br, gbtm...@gmail.com
Olá Gabriel

Desconheço uma maneira de receber um resumo, pois os Jobs são executados individualmente.
O bacula possui uma tabela de Status dos Jobs que pode ser usada para fazer uma query SQL:

Tabela Status
+-----------+---------------------------------+----------+
| JobStatus | JobStatusLong                   | Severity |
+-----------+---------------------------------+----------+
| A         | Canceled by user                |       90 |
| B         | Blocked                         |       15 |
| C         | Created, not yet running        |       15 |
| D         | Verify found differences        |       15 |
| E         | Terminated with errors          |       25 |
| F         | Waiting for Client              |       15 |
| M         | Waiting for media mount         |       15 |
| R         | Running                         |       15 |
| S         | Waiting for Storage daemon      |       15 |
| T         | Completed successfully          |       10 |
| a         | SD despooling attributes        |       15 |
| c         | Waiting for client resource     |       15 |
| d         | Waiting on maximum jobs         |       15 |
| e         | Non-fatal error                 |       20 |
| f         | Fatal error                     |      100 |
| i         | Doing batch insert file records |       15 |
| j         | Waiting for job resource        |       15 |
| m         | Waiting for new media           |       15 |
| p         | Waiting on higher priority jobs |       15 |
| s         | Waiting for storage resource    |       15 |
| t         | Waiting on start time           |       15 |
+-----------+---------------------------------+----------+


Você poderia fazer um script e colocar no crontab para listar os jobs do dia:

#####################################################################################
# Exemplo de Script:
#!/bin/bash
data=$(date  +%Y-%m-%d)

sql_query="select A.JobId, A.Name, A.Type, A.Level, A.JobStatus, B.JobStatusLong,
A.StartTime, A.EndTime,  cast(A.JobBytes/1024/1024 as decimal(10,2)) as JobMegaBytes
from Job A
left join Status B on (A.JobStatus = B.JobStatus)
where A.StartTime >= '$data 00:00:01' and A.EndTime <= '$data 23:59:59';"

echo "$sql_query" | mysql -u root -D bacula -t |  mail -s "Backup Bacula" root

#####################################################################################



+-------+---------------------+------+-------+-----------+------------------------+---------------------+---------------------+---------------+
| JobId | Name                | Type | Level | JobStatus | JobStatusLong          | StartTime           | EndTime             | JobMegaBytes  |
+-------+---------------------+------+-------+-----------+------------------------+---------------------+---------------------+---------------+
| 1,219 | Restore_Files       | R    | F     | T         | Completed successfully | 2015-07-23 07:59:44 | 2015-07-23 07:59:49 | 405.01        |
| 1,220 | Backup_Banco_Dados  | B    | F     | T         | Completed successfully | 2015-07-23 12:16:47 | 2015-07-23 12:19:39 | 402.96        |
| 1,221 | Backup_Maquina_001  | B    | D     | T         | Completed successfully | 2015-07-23 17:30:01 | 2015-07-23 17:32:06 | 0.47          |
| 1,222 | Backup_Maquina_002  | B    | D     | T         | Completed successfully | 2015-07-23 17:30:04 | 2015-07-23 17:31:30 | 4.60          |
| 1,223 | Backup_Banco_Dados  | B    | F     | T         | Completed successfully | 2015-07-23 22:06:37 | 2015-07-23 22:09:24 | 403.18        |
| 1,224 | Backup_Servidor_001 | B    | D     | T         | Completed successfully | 2015-07-23 22:00:00 | 2015-07-23 22:02:17 | 53.48         |
| 1,225 | Backup_Servidor_002 | B    | D     | T         | Completed successfully | 2015-07-23 22:00:06 | 2015-07-23 22:00:17 | 7.14          |
| 1,226 | Backup_Servidor_002 | B    | D     | T         | Completed successfully | 2015-07-23 22:00:09 | 2015-07-23 22:00:21 | 13.25         |
| 1,227 | Backup_Servidor_004 | B    | D     | T         | Completed successfully | 2015-07-23 22:00:01 | 2015-07-23 22:00:13 | 2.89          |
| 1,228 | Backup_Servidor_005 | B    | D     | T         | Completed successfully | 2015-07-23 22:09:25 | 2015-07-23 22:15:10 | 1145.33       |
| 1,229 | Backup_Catalogo     | B    | D     | T         | Completed successfully | 2015-07-23 22:15:21 | 2015-07-23 22:15:44 | 59.55         |
+-------+---------------------+------+-------+-----------+------------------------+---------------------+---------------------+---------------+


Att Wanderlei

Gabriel Motta

unread,
Jul 24, 2015, 3:13:07 PM7/24/15
to Wanderlei, Bacula Backup-Pt-Br

Muito bom...Adorei a sugestão... Acho q podemos melhorar essa ideia de resumo...

Vou tentar fazer algo aqui e atualizo a todos.

Se alguém tiver maiores ideia para dar sugestão. Fiquem a vontade. Abraço.

Reply all
Reply to author
Forward
0 new messages