diff --git a/ansible/roles/restic/files/restic-post.hook b/ansible/roles/restic/files/restic-post.hook deleted file mode 100644 index f605774..0000000 --- a/ansible/roles/restic/files/restic-post.hook +++ /dev/null @@ -1,9 +0,0 @@ -[Trigger] -Operation = Upgrade -Type = Package -Target = restic - -[Action] -Description = Set restic binary permissions -When = PostTransaction -Exec = /usr/share/libalpm/scripts/restic-post.sh diff --git a/ansible/roles/restic/files/restic-post.sh b/ansible/roles/restic/files/restic-post.sh deleted file mode 100644 index 103a052..0000000 --- a/ansible/roles/restic/files/restic-post.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/env bash - -# See https://restic.readthedocs.io/en/stable/080_examples.html#backing-up-your-system-without-running-restic-as-root - -set -e - -RESTIC_BIN=$(which restic) - -# Set owner -chown root:restic $RESTIC_BIN -chmod 750 $RESTIC_BIN - -# Lest restic run root things -setcap cap_dac_read_search=+ep $RESTIC_BIN diff --git a/ansible/roles/restic/files/restic.service b/ansible/roles/restic/files/restic.service new file mode 100644 index 0000000..312dd85 --- /dev/null +++ b/ansible/roles/restic/files/restic.service @@ -0,0 +1,34 @@ +[Unit] +Description=Backup system + +[Service] +Type=oneshot +User=restic +Environment="CHECK_UUID={{ vault_restic_healthchecks_id }}" + +AmbientCapabilities=CAP_DAC_READ_SEARCH +CapabilityBoundingSet=CAP_DAC_READ_SEARCH +DevicePolicy=closed +LockPersonality=yes +MemoryDenyWriteExecute=yes +NoNewPrivileges=yes +PrivateDevices=yes +PrivateTmp=yes +ProtectClock=yes +ProtectControlGroups=yes +ProtectHome=no +ProtectHostname=yes +ProtectKernelLogs=yes +ProtectKernelModules=yes +ProtectKernelTunables=yes +ProtectProc=invisible +ProtectSystem=strict +RemoveIPC=yes +RestrictAddressFamilies=AF_UNIX AF_INET AF_INET6 +RestrictNamespaces=yes +RestrictRealtime=yes +RestrictSUIDSGID=yes +SystemCallFilter=@system-service +UMask=7007 + +ExecStart=/usr/bin/runitor -- /home/restic/restic-backup.sh diff --git a/ansible/roles/restic/files/restic.timer b/ansible/roles/restic/files/restic.timer new file mode 100644 index 0000000..614d89c --- /dev/null +++ b/ansible/roles/restic/files/restic.timer @@ -0,0 +1,10 @@ +[Unit] +Description=Timer for Restic backups + +[Timer] +OnCalendar=*-*-* 00:00:00 +Persistent=true +Unit=restic.service + +[Install] +WantedBy=timers.target diff --git a/ansible/roles/restic/handlers/main.yml b/ansible/roles/restic/handlers/main.yml new file mode 100644 index 0000000..92c01f9 --- /dev/null +++ b/ansible/roles/restic/handlers/main.yml @@ -0,0 +1,3 @@ +- name: reload systemd + systemd_service: + daemon_reload: true diff --git a/ansible/roles/restic/tasks/main.yml b/ansible/roles/restic/tasks/main.yml index 15b49a2..3ecb872 100644 --- a/ansible/roles/restic/tasks/main.yml +++ b/ansible/roles/restic/tasks/main.yml @@ -58,32 +58,22 @@ owner: root group: restic -- name: Set cap_sys_chroot=+ep on restic - community.general.capabilities: - path: /usr/bin/restic - capability: cap_dac_read_search=+ep - -- name: Schedule backup - cron: - name: restic backup - hour: 0 - minute: 0 - job: CHECK_UUID={{ vault_restic_healthchecks_id }} /usr/bin/runitor -- /home/restic/restic-backup.sh - user: restic - -- name: Install pacman post script +- name: Install Systemd service template: - src: files/restic-post.sh - dest: /usr/share/libalpm/scripts/restic-post.sh - mode: "0700" - when: ansible_os_family == 'Archlinux' - -- name: Install pacman post hook - template: - src: files/restic-post.hook - dest: /usr/share/libalpm/hooks/restic-post.hook + src: files/{{ item }} + dest: /etc/systemd/system/{{ item }} mode: "0600" - when: ansible_os_family == 'Archlinux' + loop: + - restic.service + - restic.timer + notify: + - reload systemd + +- name: Enable backups + systemd_service: + name: restic.timer + enabled: true + state: started - name: Install HomeAssistant mounts include_tasks: homeassistant.yml