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