Only send log messages on errors.

This commit is contained in:
Christoph 2024-12-17 00:26:57 +01:00
parent 595ce80230
commit c7c028abfc
2 changed files with 72 additions and 82 deletions

View File

@ -732,48 +732,9 @@ durationReadable=$(printf "%02d hours %02d minutes %02d seconds" $durationHour $
echo -e "\n\n###### Server backup finished on ${endDateReadable} (${durationReadable}) ######\n" >> ${BORG_LOG_FILE} echo -e "\n\n###### Server backup finished on ${endDateReadable} (${durationReadable}) ######\n" >> ${BORG_LOG_FILE}
# Send Summery
#
if $terminal ; then
echo -e -n " Send Summary.."
fi
datum="$(date +"%d.%m.%Y %H:%M")"
filesystem_usage="$(df -h)"
msg_head_line="\n\n# ---\n# Server backup finished on ${endDateReadable} (${durationReadable})\n# ---\n\n"
msg="$(cat "${BORG_LOG_FILE}")"
datum="$(date +"%d.%m.%Y")"
content_type='Content-Type: text/plain;\n charset="utf-8"'
subject="Borg Backup - ${COMPANY} - ${datum}"
subject_utf8="$(echo "$subject" | iconv -t UTF8)"
subject_utf8_encoded="=?utf-8?B?$(echo $subject_utf8 | base64 --wrap=0)?="
cat <<EOF >> ${BORG_LOG_FILE}
echo -e "To:${ADMIN_EMAIL}\n${content_type}\nSubject:${subject_utf8_encoded}\n\${filesystem_usage}\n\${msg_head_line}\n\${msg}\n" | /usr/sbin/sendmail -F "Borg BACKUP ${COMPANY}" -f ${FROM_ADDRESS} ${ADMIN_EMAIL}
EOF
echo -e "To:${ADMIN_EMAIL}\n${content_type}\nSubject:${subject_utf8_encoded}\n${filesystem_usage}\n${msg_head_line}\n${msg}\n" | /usr/sbin/sendmail -F "Borg BACKUP ${COMPANY}" -f ${FROM_ADDRESS} ${ADMIN_EMAIL} > ${log_file} 2>&1
if [[ $? -gt 0 ]] ; then
echo_failed
error "$(cat "${log_file}")"
else
echo_ok
fi
blank_line blank_line
# Error Handling # Error Handling
# #
declare -i error=$(grep -i -e"\[\s*ERROR" ${BORG_LOG_FILE} | wc -l) declare -i error=$(grep -i -e"\[\s*ERROR" ${BORG_LOG_FILE} | wc -l)
@ -781,6 +742,41 @@ declare -i warning=$(grep -i -e"\[\s*WARN" ${BORG_LOG_FILE} | wc -l)
if [ $error -gt 0 -o $warning -gt 0 ] ; then if [ $error -gt 0 -o $warning -gt 0 ] ; then
# Send Summery
#
if $terminal ; then
echo -e -n " Send Summary.."
fi
datum="$(date +"%d.%m.%Y %H:%M")"
filesystem_usage="$(df -h)"
msg_head_line="\n\n# ---\n# Server backup finished on ${endDateReadable} (${durationReadable})\n# ---\n\n"
msg="$(cat "${BORG_LOG_FILE}")"
datum="$(date +"%d.%m.%Y")"
content_type='Content-Type: text/plain;\n charset="utf-8"'
subject="Borg Backup - ${COMPANY} - ${datum}"
subject_utf8="$(echo "$subject" | iconv -t UTF8)"
subject_utf8_encoded="=?utf-8?B?$(echo $subject_utf8 | base64 --wrap=0)?="
echo -e "To:${ADMIN_EMAIL}\n${content_type}\nSubject:${subject_utf8_encoded}\n${filesystem_usage}\n${msg_head_line}\n${msg}\n" | /usr/sbin/sendmail -F "Borg BACKUP ${COMPANY}" -f ${FROM_ADDRESS} ${ADMIN_EMAIL} > ${log_file} 2>&1
if [[ $? -gt 0 ]] ; then
echo_failed
error "$(cat "${log_file}")"
else
echo_ok
fi
blank_line
# Send Error Message # Send Error Message
# #
if $terminal ; then if $terminal ; then
@ -836,6 +832,7 @@ fi
blank_line blank_line
echononl "Create temporary logorotate configuration file 'logrotate_borg.conf'.." echononl "Create temporary logorotate configuration file 'logrotate_borg.conf'.."
cat << EOF > ${LOCK_DIR}/logrotate_borg.conf 2> ${log_file} cat << EOF > ${LOCK_DIR}/logrotate_borg.conf 2> ${log_file}

View File

@ -701,51 +701,9 @@ durationReadable=$(printf "%02d hours %02d minutes %02d seconds" $durationHour $
echo -e "\n\n###### Server backup finished on ${endDateReadable} (${durationReadable}) ######\n" >> ${BORG_LOG_FILE} echo -e "\n\n###### Server backup finished on ${endDateReadable} (${durationReadable}) ######\n" >> ${BORG_LOG_FILE}
blank_line blank_line
# Send Summery
#
if $terminal ; then
echo -e -n " Send Summary.."
fi
datum="$(date +"%d.%m.%Y %H:%M")"
filesystem_usage="$(df -h)"
msg_head_line="\n\n# ---\n# Server backup finished on ${endDateReadable} (${durationReadable})\n# ---\n\n"
msg="$(cat "${BORG_LOG_FILE}")"
datum="$(date +"%d.%m.%Y")"
content_type='Content-Type: text/plain;\n charset="utf-8"'
subject="Borg Backup - ${COMPANY} - ${datum}"
subject_utf8="$(echo "$subject" | iconv -t UTF8)"
subject_utf8_encoded="=?utf-8?B?$(echo $subject_utf8 | base64 --wrap=0)?="
cat <<EOF >> ${BORG_LOG_FILE}
echo -e "To:${ADMIN_EMAIL}\n${content_type}\nSubject:${subject_utf8_encoded}\n\${filesystem_usage}\n\${msg_head_line}\n\${msg}\n" | /usr/sbin/sendmail -F "Borg BACKUP ${COMPANY}" -f ${FROM_ADDRESS} ${ADMIN_EMAIL}
EOF
echo -e "To:${ADMIN_EMAIL}\n${content_type}\nSubject:${subject_utf8_encoded}\n${filesystem_usage}\n${msg_head_line}\n${msg}\n" | /usr/sbin/sendmail -F "Borg BACKUP ${COMPANY}" -f ${FROM_ADDRESS} ${ADMIN_EMAIL} > ${log_file} 2>&1
if [[ $? -gt 0 ]] ; then
echo_failed
error "$(cat "${log_file}")"
else
echo_ok
fi
blank_line
# Error Handling # Error Handling
# #
declare -i error=$(grep -i -e"\[\s*ERROR" ${BORG_LOG_FILE} | wc -l) declare -i error=$(grep -i -e"\[\s*ERROR" ${BORG_LOG_FILE} | wc -l)
@ -753,6 +711,41 @@ declare -i warning=$(grep -i -e"\[\s*WARN" ${BORG_LOG_FILE} | wc -l)
if [ $error -gt 0 -o $warning -gt 0 ] ; then if [ $error -gt 0 -o $warning -gt 0 ] ; then
# Send Summery
#
if $terminal ; then
echo -e -n " Send Summary.."
fi
datum="$(date +"%d.%m.%Y %H:%M")"
filesystem_usage="$(df -h)"
msg_head_line="\n\n# ---\n# Server backup finished on ${endDateReadable} (${durationReadable})\n# ---\n\n"
msg="$(cat "${BORG_LOG_FILE}")"
datum="$(date +"%d.%m.%Y")"
content_type='Content-Type: text/plain;\n charset="utf-8"'
subject="Borg Backup - ${COMPANY} - ${datum}"
subject_utf8="$(echo "$subject" | iconv -t UTF8)"
subject_utf8_encoded="=?utf-8?B?$(echo $subject_utf8 | base64 --wrap=0)?="
echo -e "To:${ADMIN_EMAIL}\n${content_type}\nSubject:${subject_utf8_encoded}\n${filesystem_usage}\n${msg_head_line}\n${msg}\n" | /usr/sbin/sendmail -F "Borg BACKUP ${COMPANY}" -f ${FROM_ADDRESS} ${ADMIN_EMAIL} > ${log_file} 2>&1
if [[ $? -gt 0 ]] ; then
echo_failed
error "$(cat "${log_file}")"
else
echo_ok
fi
blank_line
# Send Error Message # Send Error Message
# #
if $terminal ; then if $terminal ; then