From 38fbe9613f38b647f7017df0e6817a2c4fab80f2 Mon Sep 17 00:00:00 2001 From: = Date: Thu, 3 Nov 2022 13:27:06 +0100 Subject: [PATCH] added timer, fixed /root typo --- restic/files/backup.sh.jinja | 2 +- restic/files/restic-backup.service.jinja | 10 +++++++ restic/files/restic-backup.timer.jinja | 10 +++++++ restic/init.sls | 34 +++++++++++++++++++++++- 4 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 restic/files/restic-backup.service.jinja create mode 100644 restic/files/restic-backup.timer.jinja diff --git a/restic/files/backup.sh.jinja b/restic/files/backup.sh.jinja index 89389a4..b89d48d 100644 --- a/restic/files/backup.sh.jinja +++ b/restic/files/backup.sh.jinja @@ -42,5 +42,5 @@ restic backup \ --verbose \ {% if pillar.podman is defined %}{{ salt['cmd.run']('podman info -f "{{.Store.VolumePath}}"', runas=pillar.podman.user ) }} \{% endif %} /etc \ - / root \ + /root \ /home diff --git a/restic/files/restic-backup.service.jinja b/restic/files/restic-backup.service.jinja new file mode 100644 index 0000000..d24a8b4 --- /dev/null +++ b/restic/files/restic-backup.service.jinja @@ -0,0 +1,10 @@ +[Unit] +Description=Run restic backup + +[Service] +Type=oneshot +User={{ pillar.restic.user }} +ExecStart={{ salt['user.info'](pillar.restic.user).home }}/bin/backup.sh + +[Install] +WantedBy=default.target diff --git a/restic/files/restic-backup.timer.jinja b/restic/files/restic-backup.timer.jinja new file mode 100644 index 0000000..e6b2d84 --- /dev/null +++ b/restic/files/restic-backup.timer.jinja @@ -0,0 +1,10 @@ +[Unit] +Description=Restic backup timer + +[Timer] +OnCalendar={{ pillar.restic.OnCalendar }} +RandomizedDelaySec=300 +Unit=restic-backup.service + +[Install] +WantedBy=timers.target diff --git a/restic/init.sls b/restic/init.sls index ea7676b..989093b 100644 --- a/restic/init.sls +++ b/restic/init.sls @@ -9,7 +9,7 @@ Install restic packages: - restic - restic-bash-completion -Copy backup script for {{ pillar.restic.user }}: +Create backup script for {{ pillar.restic.user }}: file.managed: - name: {{ salt['user.info'](pillar.restic.user).home }}/bin/backup.sh - source: salt://restic/files/backup.sh.jinja @@ -17,3 +17,35 @@ Copy backup script for {{ pillar.restic.user }}: - user: {{ pillar.restic.user }} - group: root - mode: "0740" + +Create the restic backup service unit: + file.managed: + - name: /etc/systemd/system/restic-backup.service + - source: salt://restic/files/restic-backup.service.jinja + - template: jinja + - user: root + - group: root + - mode: "0644" + +Create the restic backup timer: + file.managed: + - name: /etc/systemd/system/restic-backup.timer + - source: salt://restic/files/restic-backup.timer.jinja + - template: jinja + - user: root + - group: root + - mode: "0644" + +Run systemctl daemon reload for restic: + cmd.run: + - name: systemctl daemon-reload + - onchanges: + - file: Create the restic backup service unit + - file: Create the restic backup timer + +Start the restic backup timer: + service.running: + - name: restic-backup.timer + - enable: True + - onchanges: + - cmd: Run systemctl daemon reload for restic