add systemd timer for backups
This commit is contained in:
parent
baa9bd7bed
commit
6c214a2330
6 changed files with 59 additions and 0 deletions
|
|
@ -1,4 +1,14 @@
|
|||
backups:
|
||||
jobs:
|
||||
retention:
|
||||
enabled: true
|
||||
OnCalendar: "1:{{ 60|random(seed=(inventory_hostname + 'backups_jobs')) }}"
|
||||
run:
|
||||
enabled: true
|
||||
OnCalendar: "3,11,19:{{ 60|random(seed=(inventory_hostname + 'backups_jobs')) }}"
|
||||
check:
|
||||
enabled: true
|
||||
OnCalendar: "monday 5:{{ 60|random(seed=(inventory_hostname + 'backups_jobs')) }}"
|
||||
backends:
|
||||
restic:
|
||||
url: /var/backup-client/restic
|
||||
|
|
|
|||
|
|
@ -1,3 +1,13 @@
|
|||
- name: reload systemd
|
||||
systemd:
|
||||
daemon_reload: True
|
||||
|
||||
- name: enable timers
|
||||
loop:
|
||||
- check
|
||||
- retention
|
||||
- run
|
||||
systemd:
|
||||
name: "backup-{{ item }}.timer"
|
||||
enabled: "{{ backups.jobs[item].enabled }}"
|
||||
state: "{% if backups.jobs[item].enabled %}started{% else %}stopped{% endif %}"
|
||||
|
|
|
|||
|
|
@ -48,6 +48,7 @@
|
|||
- backup-full
|
||||
- backup-cronjob
|
||||
- backup-check
|
||||
- status-email-root
|
||||
template:
|
||||
src: "{{ item }}.j2"
|
||||
dest: "/usr/local/bin/{{ item }}"
|
||||
|
|
@ -62,12 +63,28 @@
|
|||
- backup-check
|
||||
- backup-retention
|
||||
- backup-run
|
||||
- status-email-root@
|
||||
template:
|
||||
src: "{{ item }}.service.j2"
|
||||
dest: "/etc/systemd/system/{{ item }}.service"
|
||||
owner: root
|
||||
group: root
|
||||
mode: 0644
|
||||
# validate: /usr/bin/systemd-analyze verify %s
|
||||
- name: copy timers
|
||||
notify:
|
||||
- reload systemd
|
||||
- enable timers
|
||||
loop:
|
||||
- check
|
||||
- retention
|
||||
- run
|
||||
template:
|
||||
src: "timer.j2"
|
||||
dest: "/etc/systemd/system/backup-{{ item }}.timer"
|
||||
owner: root
|
||||
group: root
|
||||
mode: 0644
|
||||
# validate: /usr/bin/systemd-analyze verify %s
|
||||
- name: create data folder
|
||||
file:
|
||||
|
|
|
|||
4
templates/status-email-root.j2
Executable file
4
templates/status-email-root.j2
Executable file
|
|
@ -0,0 +1,4 @@
|
|||
#!/bin/bash
|
||||
set -euo pipefail
|
||||
|
||||
systemctl status "$1" | mail -s "service $1 failed on $( hostname )" root || true
|
||||
7
templates/status-email-root@.service.j2
Normal file
7
templates/status-email-root@.service.j2
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
[Unit]
|
||||
Description=Send a mail to root in case of a service failure
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=/usr/local/bin/status-email-root %i
|
||||
|
||||
11
templates/timer.j2
Normal file
11
templates/timer.j2
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
[Unit]
|
||||
Description=Execute backup job
|
||||
|
||||
[Timer]
|
||||
Persistent=true
|
||||
{% if "OnCalendar" in backups.jobs[item] %}
|
||||
OnCalendar={{ backups.jobs[item].OnCalendar }}
|
||||
{% endif %}
|
||||
|
||||
[Install]
|
||||
WantedBy=timers.target
|
||||
Loading…
Add table
Add a link
Reference in a new issue