From 7873f0e7243327c7e47b199c8deaa213e62692fe Mon Sep 17 00:00:00 2001 From: Frank Villaro-Dixon Date: Thu, 2 May 2024 17:53:38 +0200 Subject: [PATCH] add rsnapshot timers Signed-off-by: Frank Villaro-Dixon --- ansible/configure-server.yml | 36 +++++++++++++++++++++++++++ ansible/files/rsnapshot-daily.timer | 11 ++++++++ ansible/files/rsnapshot-monthly.timer | 11 ++++++++ ansible/files/rsnapshot-weekly.timer | 11 ++++++++ ansible/files/rsnapshot@.service | 11 ++++++++ 5 files changed, 80 insertions(+) create mode 100644 ansible/files/rsnapshot-daily.timer create mode 100644 ansible/files/rsnapshot-monthly.timer create mode 100644 ansible/files/rsnapshot-weekly.timer create mode 100644 ansible/files/rsnapshot@.service diff --git a/ansible/configure-server.yml b/ansible/configure-server.yml index 19647e2..b2863c9 100644 --- a/ansible/configure-server.yml +++ b/ansible/configure-server.yml @@ -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 diff --git a/ansible/files/rsnapshot-daily.timer b/ansible/files/rsnapshot-daily.timer new file mode 100644 index 0000000..6b6c75a --- /dev/null +++ b/ansible/files/rsnapshot-daily.timer @@ -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 \ No newline at end of file diff --git a/ansible/files/rsnapshot-monthly.timer b/ansible/files/rsnapshot-monthly.timer new file mode 100644 index 0000000..dd7dd83 --- /dev/null +++ b/ansible/files/rsnapshot-monthly.timer @@ -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 \ No newline at end of file diff --git a/ansible/files/rsnapshot-weekly.timer b/ansible/files/rsnapshot-weekly.timer new file mode 100644 index 0000000..ab8e5b0 --- /dev/null +++ b/ansible/files/rsnapshot-weekly.timer @@ -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 \ No newline at end of file diff --git a/ansible/files/rsnapshot@.service b/ansible/files/rsnapshot@.service new file mode 100644 index 0000000..39dab10 --- /dev/null +++ b/ansible/files/rsnapshot@.service @@ -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 \ No newline at end of file