borgmatic.service 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. [Unit]
  2. Description=borgmatic backup
  3. Wants=network-online.target
  4. After=network-online.target
  5. # Prevent borgmatic from running unless the machine is plugged into power. Remove this line if you
  6. # want to allow borgmatic to run anytime.
  7. ConditionACPower=true
  8. [Service]
  9. Type=oneshot
  10. # Security settings for systemd running as root, optional but recommended to improve security. You
  11. # can disable individual settings if they cause problems for your use case. For more details, see
  12. # the systemd manual: https://www.freedesktop.org/software/systemd/man/systemd.exec.html
  13. LockPersonality=true
  14. # Certain borgmatic features like Healthchecks integration need MemoryDenyWriteExecute to be off.
  15. # But you can try setting it to "yes" for improved security if you don't use those features.
  16. MemoryDenyWriteExecute=no
  17. NoNewPrivileges=yes
  18. PrivateDevices=yes
  19. PrivateTmp=yes
  20. ProtectClock=yes
  21. ProtectControlGroups=yes
  22. ProtectHostname=yes
  23. ProtectKernelLogs=yes
  24. ProtectKernelModules=yes
  25. ProtectKernelTunables=yes
  26. RestrictAddressFamilies=AF_UNIX AF_INET AF_INET6 AF_NETLINK
  27. RestrictNamespaces=yes
  28. RestrictRealtime=yes
  29. RestrictSUIDSGID=yes
  30. SystemCallArchitectures=native
  31. SystemCallFilter=@system-service
  32. SystemCallErrorNumber=EPERM
  33. # To restrict write access further, change "ProtectSystem" to "strict" and uncomment
  34. # "ReadWritePaths", "ReadOnlyPaths", "ProtectHome", and "BindPaths". Then add any local repository
  35. # paths to the list of "ReadWritePaths" and local backup source paths to "ReadOnlyPaths". This
  36. # leaves most of the filesystem read-only to borgmatic.
  37. ProtectSystem=full
  38. # ReadWritePaths=-/mnt/my_backup_drive
  39. # ReadOnlyPaths=-/var/lib/my_backup_source
  40. # This will mount a tmpfs on top of /root and pass through needed paths
  41. # ProtectHome=tmpfs
  42. # BindPaths=-/root/.cache/borg -/root/.config/borg -/root/.borgmatic
  43. # May interfere with running external programs within borgmatic hooks.
  44. CapabilityBoundingSet=CAP_DAC_READ_SEARCH CAP_NET_RAW
  45. # Lower CPU and I/O priority.
  46. Nice=19
  47. CPUSchedulingPolicy=batch
  48. IOSchedulingClass=best-effort
  49. IOSchedulingPriority=7
  50. IOWeight=100
  51. Restart=no
  52. # Prevent rate limiting of borgmatic log events. If you are using an older version of systemd that
  53. # doesn't support this (pre-240 or so), you may have to remove this option.
  54. LogRateLimitIntervalSec=0
  55. # Delay start to prevent backups running during boot. Note that systemd-inhibit requires dbus and
  56. # dbus-user-session to be installed.
  57. ExecStartPre=sleep 1m
  58. ExecStart=systemd-inhibit --who="borgmatic" --what="sleep:shutdown" --why="Prevent interrupting scheduled backup" /root/.local/bin/borgmatic --verbosity -2 --syslog-verbosity 1