borgmatic.service 2.7 KB

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