Email rsnapshot backup reports

This commit is contained in:
Kris Lamoureux 2021-06-08 00:33:55 -04:00
parent e3200f6ad0
commit 6a73e4120e
Signed by: kris
GPG Key ID: 3EDA9C3441EDA925
7 changed files with 74 additions and 1 deletions

View File

@ -2,6 +2,13 @@
allow_reboot: false allow_reboot: false
manage_network: false manage_network: false
#mail:
# host: smtp.gmail.com
# from: automated@example.com
# user: automated
# password: password123
# rootalias: personal@example.com
# rsnapshot # rsnapshot
rsnapshot: rsnapshot:
- name: localhost - name: localhost
@ -18,6 +25,9 @@ rsnapshot:
minute: "1-59/2" # every odd minute minute: "1-59/2" # every odd minute
#minute: 0 #minute: 0
#hour: 0 #hour: 0
#report:
# to: personal@example.com
# subject: Localhost Backup Report
backups: backups:
- name: config - name: config
source: /etc/ source: /etc/

19
roles/base/tasks/mail.yml Normal file
View File

@ -0,0 +1,19 @@
- name: Install msmtp
apt:
name: "{{ item }}"
state: present
loop:
- msmtp
- msmtp-mta
- mailutils
- name: Install msmtp configuration
template:
src: msmtprc.j2
dest: /root/.msmtprc
mode: 0700
- name: Install /etc/aliases
copy:
dest: /etc/aliases
content: "root: {{ mail.rootalias }}"

View File

@ -8,6 +8,10 @@
tags: network tags: network
when: manage_network when: manage_network
- import_tasks: mail.yml
tags: mail
when: mail is defined
- import_tasks: ddclient.yml - import_tasks: ddclient.yml
tags: ddclient tags: ddclient
when: ddclient is defined when: ddclient is defined

View File

@ -0,0 +1,17 @@
# Set default values for all accounts.
defaults
port 587
tls on
tls_trust_file /etc/ssl/certs/ca-certificates.crt
aliases /etc/aliases
logfile ~/.msmtp.log
account main
host {{ mail.host }}
from {{ mail.from }}
auth on
user {{ mail.user }}
password {{ mail.password }}
# Set a default account
account default : main

View File

@ -1,3 +1,4 @@
rsnapshot_confdir: /etc/rsnapshot.d rsnapshot_confdir: /etc/rsnapshot.d
rsnapshot_logdir: /var/log/rsnapshot rsnapshot_logdir: /var/log/rsnapshot
rsnapshot_root: /srv/backups/{{ item.name }} rsnapshot_root: /srv/backups/{{ item.name }}
rsnapshot_reportlog: "{{ rsnapshot_logdir }}/{{ item.name }}.log"

View File

@ -40,7 +40,7 @@
- name: Install rsnapshot crons - name: Install rsnapshot crons
cron: cron:
name: "{{ item.1.interval }} rsnapshot of {{ item.0.name }}" name: "{{ item.1.interval }} rsnapshot of {{ item.0.name }}"
job: "/usr/bin/rsnapshot -c {{ rsnapshot_confdir }}/{{ item.0.name }}.conf {{ item.1.interval }}" job: "/usr/bin/rsnapshot -c {{ rsnapshot_confdir }}/{{ item.0.name }}.conf {{ item.1.interval }} >/dev/null"
user: "root" user: "root"
minute: "{{ item.1.minute | default('*') }}" minute: "{{ item.1.minute | default('*') }}"
hour: "{{ item.1.hour | default('*') }}" hour: "{{ item.1.hour | default('*') }}"
@ -51,3 +51,21 @@
with_subelements: with_subelements:
- "{{ rsnapshot }}" - "{{ rsnapshot }}"
- cron - cron
- name: Install rsnapshot report script
template:
src: rsnapshot-report.sh.j2
dest: /usr/local/bin/rsnapshot-report
mode: '0750'
- name: Install rsnapshot report crons
cron:
name: "{{ item.name }} rsnapshot report email"
job: "/usr/local/bin/rsnapshot-report {{ rsnapshot_reportlog }}
| mail -s '{{ item.report.subject | default('Backup Report') }}' {{ item.report.to }}"
user: "root"
minute: '0'
hour: '0'
cron_file: "rsnapshot-{{ item.name }}"
loop: "{{ rsnapshot }}"
when: item.report is defined

View File

@ -0,0 +1,4 @@
#/bin/bash
LOG_LOCATION={{ rsnapshot_logdir }}/*.log
[ $# -gt 0 ] && LOG_LOCATION=$1
grep -e ^\\[$(date --date="yesterday" '+%F').*\/usr\/bin\/rsnapshot $LOG_LOCATION