post-backup email script - detect errors #5

Closed
opened 2020-01-26 20:30:50 +00:00 by palto42 · 1 comment
Owner

The post-backup script should add the backup result (e.g. ERROR) in the mail subject.

Current script:

#!/bin/bash

# get borgmatic log of last 1h and apply filter
log=$(journalctl -t borgmatic -S "$(date -d '1 hour ago' +'%Y-%m-%d %H:%M:%S')" -e | grep "/etc/borg\|WARNING\|ERROR")

echo -e "To: $HOSTNAME-admin<user@mailserver.com>\r\nSubject: $HOSTNAME borgmatic completed\r\n$log" | /usr/bin/msmtp  user@someserver.org

Example of failed backup:

CRITICAL Command 'borg create --patterns-from /tmp/tmpxz85wbqo --info user@server:/mnt/my-pc/main::{hostname}-{now:%Y-%m-%dT%H:%M:%S.%f} /home/user /root /etc' returned non-zero exit status 2.

Example of success:

INFO /etc/borgmatic/config.yaml: Successfully ran configuration file
The post-backup script should add the backup result (e.g. ERROR) in the mail subject. Current script: ``` #!/bin/bash # get borgmatic log of last 1h and apply filter log=$(journalctl -t borgmatic -S "$(date -d '1 hour ago' +'%Y-%m-%d %H:%M:%S')" -e | grep "/etc/borg\|WARNING\|ERROR") echo -e "To: $HOSTNAME-admin<user@mailserver.com>\r\nSubject: $HOSTNAME borgmatic completed\r\n$log" | /usr/bin/msmtp user@someserver.org ``` Example of failed backup: CRITICAL Command 'borg create --patterns-from /tmp/tmpxz85wbqo --info user@server:/mnt/my-pc/main::{hostname}-{now:%Y-%m-%dT%H:%M:%S.%f} /home/user /root /etc' returned non-zero exit status 2. Example of success: INFO /etc/borgmatic/config.yaml: Successfully ran configuration file
palto42 added the
enhancement
label 2020-01-26 20:33:21 +00:00
Author
Owner

Implemented using

success="Successful\\|exit code (75)\\|"
log_level="WARNING\\|ERROR\\|CRITICAL"

log=$(journalctl -t borgmatic -S "$(date -d "$time minutes ago" +'%Y-%m-%d %H:%M:%S')" -r --no-pager | grep "${success}${log_level}")

if [ "$log" ]
then
  message="TO: $HOSTNAME-admin<$TO>\\r\\nSubject: $HOSTNAME: borgmatic backup completed\\r\\n$log"
fi
Implemented using ```sh success="Successful\\|exit code (75)\\|" log_level="WARNING\\|ERROR\\|CRITICAL" log=$(journalctl -t borgmatic -S "$(date -d "$time minutes ago" +'%Y-%m-%d %H:%M:%S')" -r --no-pager | grep "${success}${log_level}") if [ "$log" ] then message="TO: $HOSTNAME-admin<$TO>\\r\\nSubject: $HOSTNAME: borgmatic backup completed\\r\\n$log" fi ```
Sign in to join this conversation.
No Milestone
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: palto42/borgmatic#5
No description provided.