Merge pull request 'Fix logging.' (#2) from log_fix into main

Reviewed-on: #2
Reviewed-by: meaz <meaz@no-reply@disroot.org>
This commit is contained in:
muppeth 2024-01-03 05:39:40 +00:00
commit 97cfee4d9c
1 changed files with 6 additions and 3 deletions

View File

@ -7,6 +7,7 @@ BORG_SERVER="{{ item.borgserver }}"
BORG_REPO_PATH="{{ borg_backup_dir }}{{ item.hostname }}/{{ item.repo_name }}"
BORG_SOURCE_PATH="{{ item.backup_path }}"
BORG_LOG="{{ borg_log_dir }}{{ item.hostname }}_{{ item.repo_name }}.log"
TEMPBORG_LOG="/tmp/{{ item.hostname }}_{{ item.repo_name }}.log"
BORG_STATS_FILE="{{ borg_log_dir }}{{ item.hostname }}_{{ item.repo_name }}.stats"
BORG_BACKUP_SERVER="${BORG_USER}@${BORG_SERVER}"
@ -18,8 +19,9 @@ if [ ${?} == 2 ]; then
fi
# Run backup keep the last {{ item.retention }} days
borg create --stats ${BORG_BACKUP_SERVER}:${BORG_REPO_PATH}::$(date +'%Y-%m-%dT%H:%M:%S') ${BORG_SOURCE_PATH} > ${BORG_LOG} 2>&1
borg create --stats ${BORG_BACKUP_SERVER}:${BORG_REPO_PATH}::$(date +'%Y-%m-%dT%H:%M:%S') ${BORG_SOURCE_PATH} > ${TEMPBORG_LOG} 2>&1
borg prune --stats -d {{ item.retention }} ${BORG_BACKUP_SERVER}:${BORG_REPO_PATH}
cat ${TEMPBORG_LOG} >> ${BORG_LOG}
{% if item.report_zabbix is defined and item.report_zabbix == 'true' %}
@ -35,8 +37,8 @@ zabbix_sender --tls-connect=psk --tls-psk-identity="Bog Backup" --tls-psk-file=/
{% if item.report_xmpp is defined and item.report_xmpp == 'true' %}
# Send backup report to XMPP
source {{ borg_xmppshouter_cfg }}
echo "💾️ BorgBackup Stats for {{ item.hostname }} - {{ item.repo_name }} 💾️" > ${BORG_STATS_FILE}
borg info ${BORG_BACKUP_SERVER}:${BORG_REPO_PATH} | sed -n '/----------/,$p' >> ${BORG_STATS_FILE}
echo "💾️ BorgBackup Stats for {{ item.hostname }} - {{ item.repo_name }} 💾️" >> ${BORG_STATS_FILE}
awk '/^-+$/ {count++} count==2, count==3 {if(count==1) next; print}' ${TEMPBORG_LOG} >> ${BORG_STATS_FILE}
echo "------------------------------------------------------------------------------" >> ${BORG_STATS_FILE}
cat ${BORG_STATS_FILE} | $SENDXMPP
rm ${BORG_STATS_FILE}
@ -44,4 +46,5 @@ rm ${BORG_STATS_FILE}
#Remove borg password and exit
unset BORG_PASSPHRASE
rm ${TEMPBORG_LOG}