Only send log messages on errors.
This commit is contained in:
parent
53ab70325a
commit
2d6485f06c
@ -697,48 +697,105 @@ 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
|
||||||
|
|
||||||
# Send Summery
|
|
||||||
|
# Error Handling
|
||||||
#
|
#
|
||||||
if $terminal ; then
|
declare -i error=$(grep -i -e"\[\s*ERROR" ${BORG_LOG_FILE} | wc -l)
|
||||||
echo -e -n " Send Summary.."
|
declare -i warning=$(grep -i -e"\[\s*WARN" ${BORG_LOG_FILE} | wc -l)
|
||||||
fi
|
|
||||||
|
|
||||||
datum="$(date +"%d.%m.%Y %H:%M")"
|
if [ $error -gt 0 -o $warning -gt 0 ] ; then
|
||||||
|
|
||||||
filesystem_usage="$(df -h)"
|
# Send Summery
|
||||||
|
#
|
||||||
|
if $terminal ; then
|
||||||
|
echo -e -n " Send Summary.."
|
||||||
|
fi
|
||||||
|
|
||||||
msg_head_line="\n\n# ---\n# Server backup finished on ${endDateReadable} (${durationReadable})\n# ---\n\n"
|
datum="$(date +"%d.%m.%Y %H:%M")"
|
||||||
|
|
||||||
msg="$(cat "${BORG_LOG_FILE}")"
|
filesystem_usage="$(df -h)"
|
||||||
|
|
||||||
datum="$(date +"%d.%m.%Y")"
|
msg_head_line="\n\n# ---\n# Server backup finished on ${endDateReadable} (${durationReadable})\n# ---\n\n"
|
||||||
|
|
||||||
content_type='Content-Type: text/plain;\n charset="utf-8"'
|
msg="$(cat "${BORG_LOG_FILE}")"
|
||||||
|
|
||||||
subject="Borg Backup - ${COMPANY} - ${datum}"
|
datum="$(date +"%d.%m.%Y")"
|
||||||
subject_utf8="$(echo "$subject" | iconv -t UTF8)"
|
|
||||||
subject_utf8_encoded="=?utf-8?B?$(echo $subject_utf8 | base64 --wrap=0)?="
|
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 "BACKUP ${COMPANY}" -f ${FROM_ADDRESS} ${ADMIN_EMAIL} > ${log_file} 2>&1
|
||||||
|
|
||||||
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 "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 "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
|
||||||
|
#
|
||||||
|
if $terminal ; then
|
||||||
|
echo -e -n " Send Error Message to ${ADMIN_EMAIL}.."
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
if [[ $? -gt 0 ]] ; then
|
err_msg="$(grep -A 2 -i -e"\[\s*ERROR" ${BORG_LOG_FILE})\n"
|
||||||
echo_failed
|
warn_msg="$(grep -A 2 -i -e"\[\s*WARN" ${BORG_LOG_FILE})\n"
|
||||||
error "$(cat "${log_file}")"
|
|
||||||
else
|
msg_top="Borg Backup Error ${COMPANY} vom ${datum}.\nBorg Backup on '$(hostname -f)' beendet mit:"
|
||||||
echo_ok
|
msg_body_01="\t${error} Error(s)\n\t${warning} Warning(s)\n"
|
||||||
|
msg_body_02="\n\n--- ERROR(S) ---\n${err_msg}\n\n--- WARNING(S) ...\n${warn_msg}"
|
||||||
|
|
||||||
|
msg="${msg_top}\n${msg_body_01}\n${msg_body_02}"
|
||||||
|
|
||||||
|
subject="Borg Backup Errors at ${host_name} -- ${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${msg}\n" | /usr/sbin/sendmail -F "Errors 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
|
||||||
|
|
||||||
|
if [[ -n "${ADMIN_EXTRA_EMAIL}" ]] ; then
|
||||||
|
|
||||||
|
echo -e "To:${ADMIN_EXTRA_EMAIL}\n${content_type}\nSubject:${subject_utf8_encoded}\n${msg}\n" | /usr/sbin/sendmail -F "Errors Borg BACKUP ${COMPANY}" -f ${FROM_ADDRESS} ${ADMIN_EXTRA_EMAIL} > ${log_file} 2>&1
|
||||||
|
|
||||||
|
# Send Error Message
|
||||||
|
#
|
||||||
|
if $terminal ; then
|
||||||
|
echo -e -n " Send Error Message to ${ADMIN_EMAIL}.."
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ $? -gt 0 ]] ; then
|
||||||
|
echo_failed
|
||||||
|
error "$(cat "${log_file}")"
|
||||||
|
else
|
||||||
|
echo_ok
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
blank_line
|
||||||
|
|
||||||
fi
|
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}
|
||||||
|
102
borg-backup.sh
102
borg-backup.sh
@ -666,51 +666,105 @@ 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
|
# Error Handling
|
||||||
#
|
#
|
||||||
if $terminal ; then
|
declare -i error=$(grep -i -e"\[\s*ERROR" ${BORG_LOG_FILE} | wc -l)
|
||||||
echo -e -n " Send Summary.."
|
declare -i warning=$(grep -i -e"\[\s*WARN" ${BORG_LOG_FILE} | wc -l)
|
||||||
fi
|
|
||||||
|
|
||||||
datum="$(date +"%d.%m.%Y %H:%M")"
|
if [ $error -gt 0 -o $warning -gt 0 ] ; then
|
||||||
|
|
||||||
filesystem_usage="$(df -h)"
|
# Send Summery
|
||||||
|
#
|
||||||
|
if $terminal ; then
|
||||||
|
echo -e -n " Send Summary.."
|
||||||
|
fi
|
||||||
|
|
||||||
msg_head_line="\n\n# ---\n# Server backup finished on ${endDateReadable} (${durationReadable})\n# ---\n\n"
|
datum="$(date +"%d.%m.%Y %H:%M")"
|
||||||
|
|
||||||
msg="$(cat "${BORG_LOG_FILE}")"
|
filesystem_usage="$(df -h)"
|
||||||
|
|
||||||
datum="$(date +"%d.%m.%Y")"
|
msg_head_line="\n\n# ---\n# Server backup finished on ${endDateReadable} (${durationReadable})\n# ---\n\n"
|
||||||
|
|
||||||
content_type='Content-Type: text/plain;\n charset="utf-8"'
|
msg="$(cat "${BORG_LOG_FILE}")"
|
||||||
|
|
||||||
subject="Borg Backup - ${COMPANY} - ${datum}"
|
datum="$(date +"%d.%m.%Y")"
|
||||||
subject_utf8="$(echo "$subject" | iconv -t UTF8)"
|
|
||||||
subject_utf8_encoded="=?utf-8?B?$(echo $subject_utf8 | base64 --wrap=0)?="
|
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 "BACKUP ${COMPANY}" -f ${FROM_ADDRESS} ${ADMIN_EMAIL} > ${log_file} 2>&1
|
||||||
|
|
||||||
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 "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 "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
|
||||||
|
#
|
||||||
|
if $terminal ; then
|
||||||
|
echo -e -n " Send Error Message to ${ADMIN_EMAIL}.."
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
if [[ $? -gt 0 ]] ; then
|
err_msg="$(grep -A 2 -i -e"\[\s*ERROR" ${BORG_LOG_FILE})\n"
|
||||||
echo_failed
|
warn_msg="$(grep -A 2 -i -e"\[\s*WARN" ${BORG_LOG_FILE})\n"
|
||||||
error "$(cat "${log_file}")"
|
|
||||||
else
|
msg_top="Borg Backup Error ${COMPANY} vom ${datum}.\nBorg Backup on '$(hostname -f)' beendet mit:"
|
||||||
echo_ok
|
msg_body_01="\t${error} Error(s)\n\t${warning} Warning(s)\n"
|
||||||
|
msg_body_02="\n\n--- ERROR(S) ---\n${err_msg}\n\n--- WARNING(S) ...\n${warn_msg}"
|
||||||
|
|
||||||
|
msg="${msg_top}\n${msg_body_01}\n${msg_body_02}"
|
||||||
|
|
||||||
|
subject="Borg Backup Errors at ${host_name} -- ${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${msg}\n" | /usr/sbin/sendmail -F "Errors 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
|
||||||
|
|
||||||
|
if [[ -n "${ADMIN_EXTRA_EMAIL}" ]] ; then
|
||||||
|
|
||||||
|
echo -e "To:${ADMIN_EXTRA_EMAIL}\n${content_type}\nSubject:${subject_utf8_encoded}\n${msg}\n" | /usr/sbin/sendmail -F "Errors Borg BACKUP ${COMPANY}" -f ${FROM_ADDRESS} ${ADMIN_EXTRA_EMAIL} > ${log_file} 2>&1
|
||||||
|
|
||||||
|
# Send Error Message
|
||||||
|
#
|
||||||
|
if $terminal ; then
|
||||||
|
echo -e -n " Send Error Message to ${ADMIN_EMAIL}.."
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ $? -gt 0 ]] ; then
|
||||||
|
echo_failed
|
||||||
|
error "$(cat "${log_file}")"
|
||||||
|
else
|
||||||
|
echo_ok
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
blank_line
|
||||||
|
|
||||||
fi
|
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}
|
||||||
|
@ -161,6 +161,15 @@
|
|||||||
#ADMIN_EMAIL="root"
|
#ADMIN_EMAIL="root"
|
||||||
|
|
||||||
|
|
||||||
|
# ADMIN_EXTRA_EMAIL
|
||||||
|
#
|
||||||
|
# Send Informations about the backup process also to this e-mail address
|
||||||
|
#
|
||||||
|
# Defaults to empty string (NOT SET)
|
||||||
|
#
|
||||||
|
#ADMIN_EXTRA_EMAIL=""
|
||||||
|
|
||||||
|
|
||||||
# FROM_ADDRESS
|
# FROM_ADDRESS
|
||||||
#
|
#
|
||||||
# Defaults to:
|
# Defaults to:
|
||||||
|
@ -197,6 +197,15 @@
|
|||||||
#ADMIN_EMAIL="root"
|
#ADMIN_EMAIL="root"
|
||||||
|
|
||||||
|
|
||||||
|
# ADMIN_EXTRA_EMAIL
|
||||||
|
#
|
||||||
|
# Send Informations about the backup process also to this e-mail address
|
||||||
|
#
|
||||||
|
# Defaults to empty string (NOT SET)
|
||||||
|
#
|
||||||
|
#ADMIN_EXTRA_EMAIL=""
|
||||||
|
|
||||||
|
|
||||||
# FROM_ADDRESS
|
# FROM_ADDRESS
|
||||||
#
|
#
|
||||||
# Defaults to:
|
# Defaults to:
|
||||||
|
Loading…
Reference in New Issue
Block a user