borgmatic.service 2.7 KB

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