Btrbk
2024-10-24
On the host machine
Run these commands as root
Add a system user for btrbk:
useradd -c "Btrbk user" -m -r -s /bin/bash -U btrbk
Setup sudo for btrbk:
echo "btrbk ALL=NOPASSWD:/usr/sbin/btrfs,/usr/bin/readlink,/usr/bin/test" | tee -a /etc/sudoers.d/btrbk
Create a subvolume for each client:
mount /dev/sda1 /mnt/storage
btrfs subvolume create client_hostname
On each client machine
Create a dedicated SSH key:
mkdir -p /etc/btrbk/ssh
ssh-keygen -t ed25519 -f /etc/btrbk/ssh/id_ed25519
Add each client’s SSH public key to /home/btrbk/.ssh/authorized_keys
on the NAS machine:
ssh-copy-id -i /etc/btrbk/ssh/id_ed25519 btrbk@nas.local
Create /etc/btrbk/btrbk.conf
on each client:
transaction_log /var/log/btrbk.log
snapshot_preserve_min latest
target_preserve 24h 7d 1m 1y
target_preserve_min 7d
ssh_user btrbk
ssh_identity /etc/btrbk/ssh/id_ed25519
backend btrfs-progs-sudo
snapshot_dir /btrbk_snapshots
target ssh://nas.local/mnt/storage/<client hostname>
subvolume /
subvolume /home
snapshot_create ondemand
Create directory to store btrbk snapshots on each client machine:
mkdir /btrbk_snapshots
Create /etc/systemd/system/btrbk.service
:
[Unit]
Description=Daily btrbk backup
[Service]
Type=simple
ExecStart=/usr/bin/btrbk -q -c /etc/btrbk/btrbk.conf run
Create /etc/systemd/system/btrbk.timer
:
[Unit]
Description=Daily btrbk backup
[Timer]
OnCalendar=*-*-* 23:00:00
Persistent=true
[Install]
WantedBy=timers.target
Alternatively, create a shell script to be placed under /etc/cron.daily
:
#!/usr/bin/env bash
set -e
/usr/bin/btrbk -q -c /etc/btrbk/btrbk.conf run >/dev/null