borgmatic.service 2.8 KB

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