borgmatic.service 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. [Unit]
  2. Description=borgmatic backup
  3. Wants=network-online.target
  4. After=network-online.target
  5. ConditionACPower=true
  6. [Service]
  7. Type=oneshot
  8. # Security settings for systemd running as root, optional but recommended to improve security. You
  9. # can disable individual settings if they cause problems for your use case. For more details, see
  10. # the systemd manual: https://www.freedesktop.org/software/systemd/man/systemd.exec.html
  11. LockPersonality=true
  12. # Certain borgmatic features like Healthchecks integration need MemoryDenyWriteExecute to be off.
  13. # But you can try setting it to "yes" for improved security if you don't use those features.
  14. MemoryDenyWriteExecute=no
  15. NoNewPrivileges=yes
  16. PrivateDevices=yes
  17. PrivateTmp=yes
  18. ProtectClock=yes
  19. ProtectControlGroups=yes
  20. ProtectHostname=yes
  21. ProtectKernelLogs=yes
  22. ProtectKernelModules=yes
  23. ProtectKernelTunables=yes
  24. RestrictAddressFamilies=AF_UNIX AF_INET AF_INET6 AF_NETLINK
  25. RestrictNamespaces=yes
  26. RestrictRealtime=yes
  27. RestrictSUIDSGID=yes
  28. SystemCallArchitectures=native
  29. SystemCallFilter=@system-service
  30. SystemCallErrorNumber=EPERM
  31. # Restrict write access
  32. # Change to 'ProtectSystem=strict' and uncomment 'ProtectHome' to make the whole file
  33. # system read-only be default and uncomment 'ReadWritePaths' for the required write access.
  34. # Add local repositroy paths to the list of 'ReadWritePaths' like '-/mnt/my_backup_drive'.
  35. ProtectSystem=full
  36. # ProtectHome=read-only
  37. # ReadWritePaths=-/root/.config/borg -/root/.cache/borg -/root/.borgmatic
  38. CapabilityBoundingSet=CAP_DAC_READ_SEARCH CAP_NET_RAW
  39. # Lower CPU and I/O priority.
  40. Nice=19
  41. CPUSchedulingPolicy=batch
  42. IOSchedulingClass=best-effort
  43. IOSchedulingPriority=7
  44. IOWeight=100
  45. Restart=no
  46. # Prevent rate limiting of borgmatic log events. If you are using an older version of systemd that
  47. # doesn't support this (pre-240 or so), you may have to remove this option.
  48. LogRateLimitIntervalSec=0
  49. # Delay start to prevent backups running during boot. Note that systemd-inhibit requires dbus and
  50. # dbus-user-session to be installed.
  51. ExecStartPre=sleep 1m
  52. ExecStart=systemd-inhibit --who="borgmatic" --why="Prevent interrupting scheduled backup" /root/.local/bin/borgmatic --syslog-verbosity 1