Amélioration des mails envoyés en début et fin d'export
This commit is contained in:
parent
d623bab8eb
commit
2bb96014cf
1 changed files with 31 additions and 7 deletions
38
backup-usb
38
backup-usb
|
@ -64,17 +64,19 @@ function is_mount () {
|
|||
}
|
||||
|
||||
function send_mail () {
|
||||
echo "$2"|mail -s "$1" -r "$MAIL_FROM" "$MAIL_TO"
|
||||
echo -e "$2"|mail -s "$1" -r "$MAIL_FROM" "$MAIL_TO"
|
||||
}
|
||||
|
||||
REPORT=""
|
||||
function debug () {
|
||||
d=`date "+%Y-%m-%d - %Hh%Mm%Ss"`
|
||||
if [ -z "$LOG" ]
|
||||
then
|
||||
echo "$d -- [$1] $2"
|
||||
echo -e "$d -- [$1] $2"
|
||||
else
|
||||
echo "$d -- [$1] $2" >> $LOG 2>&1
|
||||
echo -e "$d -- [$1] $2" >> $LOG 2>&1
|
||||
fi
|
||||
REPORT="${REPORT}$d -- [$1] $2\n"
|
||||
if [ "$1" == "HALT" ]
|
||||
then
|
||||
beep -f 300 -l 2000
|
||||
|
@ -91,8 +93,27 @@ function debug () {
|
|||
fi
|
||||
}
|
||||
|
||||
function send_report () {
|
||||
[ -n "$REPORT_DF_START" ] && REPORT="${REPORT}\n\n${REPORT_DF_START}"
|
||||
[ -n "$REPORT_DF_END" ] && REPORT="${REPORT}\n\n${REPORT_DF_END}"
|
||||
if [ "$1" == "error" ]
|
||||
then
|
||||
send_mail "[ERREUR] Export sauvegardes Backup PC : fin de l'export" "/\!\\ Intervention manuelle requise avant de débrancher le disque /\!\\\n\n$REPORT"
|
||||
else
|
||||
send_mail "[INFO] Export sauvegardes Backup PC : fin de l'export" "$REPORT"
|
||||
fi
|
||||
}
|
||||
|
||||
function disk_info() {
|
||||
VENDOR=$( lsblk -o VENDOR $DEVICE|tail -n1 )
|
||||
SIZE=$( lsblk -o SIZE $DEVICE|tail -n1 )
|
||||
UUID=$( lsblk -o UUID $DEVICE|tail -n1 )
|
||||
|
||||
echo "$VENDOR $SIZE / UUID : $UUID"|sed 's/ \+/ /g'
|
||||
}
|
||||
|
||||
function backup() {
|
||||
debug INFO Start send
|
||||
debug INFO "Début de l'export des sauvegardes Backup PC sur le disque USB $DEVICE ($( disk_info ))" send
|
||||
if [ -f $LOCK_FILE ]
|
||||
then
|
||||
debug ERREUR "Le fichier de lock est toujours présent ($LOCK_FILE)." send
|
||||
|
@ -139,7 +160,7 @@ function backup() {
|
|||
debug HALT
|
||||
exit 1
|
||||
fi
|
||||
debug INFO "Disque monté."
|
||||
debug INFO "Disque monté. Espace sur le disque USB avant l'export :\n\n$( df -hP $MNT_DIR )\n"
|
||||
|
||||
debug INFO "Montage de BackupPC FS..."
|
||||
$BACKUPPCFS_PATH $BACKUPPCFS_MNT
|
||||
|
@ -178,7 +199,7 @@ function backup() {
|
|||
debug INFO "Fait."
|
||||
fi
|
||||
done
|
||||
debug INFO "Export des sauvegardes terminé"
|
||||
debug INFO "Export des sauvegardes terminé. Espace sur le disque USB après l'export :\n\n$( df --sync -hP $MNT_DIR )\n"
|
||||
|
||||
debug INFO "Démontage de BackupPC FS..."
|
||||
umount $BACKUPPCFS_MNT
|
||||
|
@ -197,6 +218,7 @@ function backup() {
|
|||
then
|
||||
debug ERREUR "Problème durant le démontage du disque dur." send
|
||||
debug HALT
|
||||
send_report error
|
||||
exit 1
|
||||
else
|
||||
debug INFO "Fait."
|
||||
|
@ -209,13 +231,15 @@ function backup() {
|
|||
then
|
||||
debug ERREUR "Problème durant la fermeture du disque LUKS" send
|
||||
debug HALT
|
||||
send_report error
|
||||
exit 1
|
||||
fi
|
||||
|
||||
debug INFO "Suppression du fichier de lock"
|
||||
rm -f $LOCK_FILE
|
||||
|
||||
debug INFO "Stop" send
|
||||
debug INFO "Fin de l'export."
|
||||
send_report
|
||||
beep -f 1000 -l 2000
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue