borgmatic.service 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. # Restrict write access
  34. # Change to 'ProtectSystem=strict' and uncomment 'ProtectHome' to make the whole file
  35. # system read-only be default and uncomment 'ReadWritePaths' for the required write access.
  36. # Add local repositroy paths to the list of 'ReadWritePaths' like '-/mnt/my_backup_drive'.
  37. ProtectSystem=full
  38. # ProtectHome=read-only
  39. # ReadWritePaths=-/root/.config/borg -/root/.cache/borg -/root/.borgmatic
  40. CapabilityBoundingSet=CAP_DAC_READ_SEARCH CAP_NET_RAW
  41. # Lower CPU and I/O priority.
  42. Nice=19
  43. CPUSchedulingPolicy=batch
  44. IOSchedulingClass=best-effort
  45. IOSchedulingPriority=7
  46. IOWeight=100
  47. Restart=no
  48. # Prevent rate limiting of borgmatic log events. If you are using an older version of systemd that
  49. # doesn't support this (pre-240 or so), you may have to remove this option.
  50. LogRateLimitIntervalSec=0
  51. # Delay start to prevent backups running during boot. Note that systemd-inhibit requires dbus and
  52. # dbus-user-session to be installed.
  53. ExecStartPre=sleep 1m
  54. ExecStart=systemd-inhibit --who="borgmatic" --why="Prevent interrupting scheduled backup" /root/.local/bin/borgmatic --syslog-verbosity 1