borgmatic.service 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. # Filesystem hooks like ZFS may not work unless PrivateDevices is disabled.
  26. PrivateDevices=yes
  27. PrivateTmp=yes
  28. ProtectClock=yes
  29. ProtectControlGroups=yes
  30. ProtectHostname=yes
  31. ProtectKernelLogs=yes
  32. ProtectKernelModules=yes
  33. ProtectKernelTunables=yes
  34. RestrictAddressFamilies=AF_UNIX AF_INET AF_INET6 AF_NETLINK
  35. RestrictNamespaces=yes
  36. RestrictRealtime=yes
  37. RestrictSUIDSGID=yes
  38. SystemCallArchitectures=native
  39. SystemCallFilter=@system-service @mount
  40. SystemCallErrorNumber=EPERM
  41. # To restrict write access further, change "ProtectSystem" to "strict" and
  42. # uncomment "ReadWritePaths", "TemporaryFileSystem", "BindPaths" and
  43. # "BindReadOnlyPaths". Then add any local repository paths to the list of
  44. # "ReadWritePaths". This leaves most of the filesystem read-only to borgmatic.
  45. ProtectSystem=full
  46. # ReadWritePaths=-/mnt/my_backup_drive
  47. # This will mount a tmpfs on top of /root and pass through needed paths
  48. # TemporaryFileSystem=/root:ro
  49. # BindPaths=-/root/.cache/borg -/root/.config/borg -/root/.borgmatic
  50. # BindReadOnlyPaths=-/root/.ssh
  51. # May interfere with running external programs within borgmatic hooks. This
  52. # includes, for instance, programs to snapshot filesystems (e.g. ZFS).
  53. CapabilityBoundingSet=CAP_DAC_READ_SEARCH CAP_NET_RAW
  54. # Lower CPU and I/O priority.
  55. Nice=19
  56. CPUSchedulingPolicy=batch
  57. IOSchedulingClass=best-effort
  58. IOSchedulingPriority=7
  59. IOWeight=100
  60. Restart=no
  61. # Prevent rate limiting of borgmatic log events. If you are using an older version of systemd that
  62. # doesn't support this (pre-240 or so), you may have to remove this option.
  63. LogRateLimitIntervalSec=0
  64. # Delay start to prevent backups running during boot. Note that systemd-inhibit requires dbus and
  65. # dbus-user-session to be installed.
  66. ExecStartPre=sleep 1m
  67. ExecStart=systemd-inhibit --who="borgmatic" --what="sleep:shutdown" --why="Prevent interrupting scheduled backup" /root/.local/bin/borgmatic --verbosity -2 --syslog-verbosity 1