From e7626bdedcedc7e0a2dc4b586376077a36425b50 Mon Sep 17 00:00:00 2001 From: = Date: Wed, 2 Nov 2022 13:51:59 +0100 Subject: [PATCH] added restic repository state --- restic/files/restic.automount.jinja | 8 ++++++++ restic/files/restic.mount.jinja | 11 +++++++++++ restic/repository.sls | 27 +++++++++++++++++++++++++++ 3 files changed, 46 insertions(+) create mode 100644 restic/files/restic.automount.jinja create mode 100644 restic/files/restic.mount.jinja create mode 100644 restic/repository.sls diff --git a/restic/files/restic.automount.jinja b/restic/files/restic.automount.jinja new file mode 100644 index 0000000..57609c0 --- /dev/null +++ b/restic/files/restic.automount.jinja @@ -0,0 +1,8 @@ +[Unit] +Description=Automount for restic repository + +[Automount] +Where={{ pillar['restic']['repository']['mount'] }} + +[Install] +WantedBy=multi-user.target diff --git a/restic/files/restic.mount.jinja b/restic/files/restic.mount.jinja new file mode 100644 index 0000000..5945724 --- /dev/null +++ b/restic/files/restic.mount.jinja @@ -0,0 +1,11 @@ +[Unit] +Description=Mount the USB disk used as restic repository + +[Mount] +What=/dev/disk/by-uuid/{{ pillar['restic']['repository']['disk_uuid'] }} +Where={{ pillar['restic']['repository']['mount'] }} +Type=auto +Options=defaults + +[Install] +WantedBy=multi-user.target diff --git a/restic/repository.sls b/restic/repository.sls new file mode 100644 index 0000000..b232134 --- /dev/null +++ b/restic/repository.sls @@ -0,0 +1,27 @@ +{% set escape_command = [ "systemd-escape -p", pillar['restic']['repository']['mount']]|join(" ") %} +{% set unit_name = salt['cmd.shell'](escape_command) %} + +Create restic repository mount unit: + file.managed: + - name: /etc/systemd/system/{{ unit_name }}.mount + - source: salt://restic/files/restic.mount.jinja + - template: jinja + - user: root + - group: root + - mode: "0644" + +Create restic repository automount unit: + file.managed: + - name: /etc/systemd/system/{{ unit_name }}.automount + - source: salt://restic/files/restic.automount.jinja + - template: jinja + - user: root + - group: root + - mode: "0644" + +Run systemd daemon reload for repository: + cmd.run: + - name: systemctl daemon-reload + - onchanges: + - file: Create restic repository mount unit + - file: Create restic repository automount unit