add rsnapshot timers

Signed-off-by: Frank Villaro-Dixon <frank@villaro-dixon.eu>
This commit is contained in:
Frank Villaro-Dixon 2024-05-02 17:53:38 +02:00
parent 849d7c5fad
commit 7873f0e724
5 changed files with 80 additions and 0 deletions

View file

@ -30,6 +30,7 @@
enabled: yes
when: systemd_mount.changed
- name: Generate ssh key
ansible.builtin.openssh_keypair:
path: /root/.ssh/id_rsa_rsnapshot
@ -56,6 +57,41 @@
register: rsnapshot_conf
tags: rsnapshot
- name: Copy systemd unit files
ansible.builtin.copy:
src: files/{{ item }}
dest: /etc/systemd/system/
owner: root
group: root
mode: 0644
with_items:
- rsnapshot@.service
- rsnapshot-daily.timer
- rsnapshot-weekly.timer
- rsnapshot-monthly.timer
register: rsnapshot_service
- name: Reload systemd
ansible.builtin.systemd:
daemon_reload: yes
when: rsnapshot_service.changed
- name: Enable rsnapshot timers
ansible.builtin.systemd:
name: '{{ item }}'
enabled: yes
with_items:
- rsnapshot-daily.timer
- rsnapshot-weekly.timer
- rsnapshot-monthly.timer
register: rsnapshot_timers
when: rsnapshot_service.changed
- name: Reboot ## IDK how to start a timer
ansible.builtin.reboot:
when: rsnapshot_timers.changed
- hosts: backup_clients
gather_facts: no

View file

@ -0,0 +1,11 @@
[Unit]
Description=rsnapshot daily backup
[Timer]
# Run every day at 3:30 AM local time
OnCalendar=03:30
Persistent=true
Unit=rsnapshot@daily.service
[Install]
WantedBy=timers.target

View file

@ -0,0 +1,11 @@
[Unit]
Description=rsnapshot monthly backup
[Timer]
# Run once per month at 0:30 local time, before daily and weekly runs
OnCalendar=*-*-1 00:30:00
Persistent=true
Unit=rsnapshot@monthly.service
[Install]
WantedBy=timers.target

View file

@ -0,0 +1,11 @@
[Unit]
Description=rsnapshot weekly backup
[Timer]
# Run once per week on Monday at 4:30 local time, before daily
OnCalendar=Monday *-*-* 01:30:00
Persistent=true
Unit=rsnapshot@weekly.service
[Install]
WantedBy=timers.target

View file

@ -0,0 +1,11 @@
[Unit]
Description=rsnapshot (%I) backup
# Like Cron would, send an email if this fails
# XXX TODO
#OnFailure=status-email-admin@%n.service
[Service]
Type=oneshot
Nice=19
IOSchedulingClass=3
ExecStart=/usr/bin/rsnapshot %I