|
1
|
#!/bin/bash
|
|
2
|
|
|
3
|
## Usage
|
|
4
|
## pour verifier et envoyer les mails
|
|
5
|
## ./XcheckBareos.sh
|
|
6
|
##
|
|
7
|
## pour verifier sans envoyer de mails
|
|
8
|
## ./XcheckBareos.sh no
|
|
9
|
|
|
10
|
########################### VARIABLES !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
11
|
# s=$(basename $0)
|
|
12
|
# dirName=${s%.*}
|
|
13
|
rne=""
|
|
14
|
sendMail=1
|
|
15
|
# dirTmp="/tmp/${dirName}/"
|
|
16
|
# dirBareos="/etc/bareos/"
|
|
17
|
# tabFiles=( "bareos-dir.conf" "bareos-fd.conf" "bareos-sd.conf" "bareos-restore.conf" \
|
|
18
|
# "bareosschedule.conf" "bareosschedulepost.conf" "bareossupport.conf" \
|
|
19
|
# "bat.conf" "bconsole.conf" "include-options.conf" "query.sql" \
|
|
20
|
# "bareosfichiers.d/annuaire.conf" "bareosfichiers.d/bareos.conf" \
|
|
21
|
# "bareosfichiers.d/fichier.conf" "bareosfichiers.d/interbase.conf" \
|
|
22
|
# "bareosfichiers.d/mail.conf" "bareosfichiers.d/mysql.conf" )
|
|
23
|
# md5File="${dirName}_$(date '+%F').md5"
|
|
24
|
# md5FilePath="/var/log/${md5File}"
|
|
25
|
# md5FileLast="${dirName}_$(date --date='yesterday' '+%F').md5"
|
|
26
|
# md5FilePathLast="/var/log/${md5FileLast}"
|
|
27
|
# md5FileLastlast="${dirName}_$(date --date='2 days ago' '+%F').md5"
|
|
28
|
# md5FilePathLastlast="/var/log/${md5FileLastlast}" #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
29
|
# md5Log="/tmp/md5sum.log"
|
|
30
|
|
|
31
|
bareosLog="/var/log/rsyslog/local/bareos-dir/bareos-dir.err.log"
|
|
32
|
bareosconf="/etc/eole/extra/bareos/config.eol"
|
|
33
|
bareosconfJSON='{"bareos.job.job_type.level": {"owner": "bareos", "val": ["Full", "Full", "Incremental"]}, "___version___": "2.5.1", "bareos.support.usb_path": {"owner": "bareos", "val": "/dev/disk/by-label/SAUV_HORUS"}, "bareos.job.job_type.end_day": {"owner": "bareos", "val": [null, null, "6"]}, "bareos.mail.mail_error": {"owner": "bareos", "val": ["sae-reseau@ac-reunion.fr", "ce.974XXXXX@ac-reunion.fr"]}, "bareos.job.job_type.hour": {"owner": "bareos", "val": ["21", "21", "21"]}, "bareos.mail.mail_ok": {"owner": "bareos", "val": ["ce.974XXXXX@ac-reunion.fr"]}, "bareos.monitor.bareos_mon_password": {"owner": "creoled", "val": "bareosMonitorPassword"}, "bareos.job.job_type.job_type": {"owner": "bareos", "val": ["monthly", "weekly", "daily"]}, "bareos.job.job_type.day": {"owner": "bareos", "val": ["1", "7", "2"]}, "bareos.support.support_type": {"owner": "bareos", "val": "usb"}}'
|
|
34
|
|
|
35
|
###################### FONCTIONS #####################################
|
|
36
|
function mailConfBareos()
|
|
37
|
{
|
|
38
|
echo "Erreurs sur la configuration"
|
|
39
|
if [[ ${sendMail} -eq 1 ]]; then
|
|
40
|
echo "Rapport configuration Bareos envoyé à sae-reseau@ac-reunion.fr"
|
|
41
|
# echo -e "Rapport du $(date +%F_%H-%M)\n\nFichiers conf Bareos en erreur ->> Configuration régénérée\n\nVerifiez via l'EAD: https://${ipHorus}:4200/" | mail -s "[LOG][Bareos ${rne}] Erreur configuration" sae-reseau@ac-reunion.fr
|
|
42
|
# read -t1 -p ""
|
|
43
|
else
|
|
44
|
echo "Aucun rapport configuration Bareos envoyé."
|
|
45
|
fi
|
|
46
|
}
|
|
47
|
|
|
48
|
function mailSauvegarde()
|
|
49
|
{
|
|
50
|
local error="$(grep "$(date --date='yesterday' '+%F')" ${bareosLog} | awk '/Termination/ { print $0}' | tail -1)"
|
|
51
|
|
|
52
|
echo "Erreurs sur les sauvegardes"
|
|
53
|
if [[ ${sendMail} -eq 1 ]]; then
|
|
54
|
echo "Rapport des sauvegardes envoyé à sae-reseau@ac-reunion.fr"
|
|
55
|
echo -e "Rapport du $(date +%F_%H-%M)\n\nSauvegarde Bareos en erreur (EAD: https://${ipHorus}:4200/):\n>[si vide, pas de sauvegarde pour le $(date --date='yesterday' '+%F')]\n>>Bareos OK=${isOK}\n>>Bareos Warn=${isWarn}\n>>Details:${error}" | mail -s "[LOG][Bareos ${rne}] Erreur sauvegardes" sae-reseau@ac-reunion.fr
|
|
56
|
read -t1 -p ""
|
|
57
|
else
|
|
58
|
echo "Aucun rapport des sauvegardes envoyé."
|
|
59
|
fi
|
|
60
|
}
|
|
61
|
|
|
62
|
function getRNE()
|
|
63
|
{
|
|
64
|
if [[ "$(which CreoleCat)" != "" ]]; then
|
|
65
|
# eole 2.4+
|
|
66
|
rne=$(CreoleGet numero_etab)
|
|
67
|
else
|
|
68
|
rne=$(grep -A3 numero_etab /etc/eole/config.eol | tail -1 | cut -d"'" -f2)
|
|
69
|
fi
|
|
70
|
rne=$(echo "${rne}" | tr '[:upper:]' '[:lower:]')
|
|
71
|
}
|
|
72
|
|
|
73
|
function getPassword()
|
|
74
|
{
|
|
75
|
bareosPwd=$(egrep '^Console' /etc/bareos/bareos-dir.conf -A3 | awk '/Password/ {print $3}')
|
|
76
|
}
|
|
77
|
|
|
78
|
###################### MAIN ######################################
|
|
79
|
|
|
80
|
# envoyer un mail?
|
|
81
|
[[ -z "$1" ]] && sendMail=1 || sendMail=0
|
|
82
|
|
|
83
|
echo -e "\n********** $0 démarre à $(date) *************"
|
|
84
|
getRNE
|
|
85
|
getPassword
|
|
86
|
ipHorus="$(ip addr show eth0 | awk '/inet/ {print $2}' | cut -d'/' -f1)"
|
|
87
|
|
|
88
|
# Test fichiers configuration Bareos
|
|
89
|
echo "Test la configuration Bareos"
|
|
90
|
grep SAUV_HORUS ${bareosconf} > /dev/null 2>&1
|
|
91
|
if [[ $? -ne 0 || $(grep -c 'Run' /etc/bareos/bareosschedule.conf) -eq 0 ]]; then
|
|
92
|
echo "${bareosconfJSON}" > ${bareosconf}
|
|
93
|
sed -i -e 's/974XXXXX/'${rne}'/g' -e 's/bareosMonitorPassword/'${bareosPwd}'/' ${bareosconf}
|
|
94
|
|
|
95
|
/usr/share/eole/sbin/bareosconfig.py -a
|
|
96
|
mailConfBareos
|
|
97
|
fi
|
|
98
|
|
|
99
|
# Test log sauvegardes Bareos
|
|
100
|
echo "Test des sauvegardes Bareos"
|
|
101
|
isOK=$(grep "$(date --date='yesterday' '+%F')" ${bareosLog} | awk '/Termination/ { print $6}' | tail -1)
|
|
102
|
#isWarn=$(grep "$(date --date='yesterday' '+%F')" ${bareosLog} | awk '/Termination/ { print $9}' | tail -1)
|
|
103
|
#[[ "${isOK}" != "OK" || "${isWarn}" != "" ]] && mailSauvegarde
|
|
104
|
[[ "${isOK}" != "OK" ]] && mailSauvegarde
|
|
105
|
|
|
106
|
# rm -Rf "${dirTmp}"
|