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