Setup
Provided that /media/myuser/btrbaks is the mount point of btrfs partition that is on external drive (see the end for details on partitions and mounts), here the commands that have to be launched only the first time.
Make a directory for the backups:
sudo mkdir /media/myuser/btrbaks/BACKUPS
Create a @ subvolume that will be the destinations of rsync command
sudo btrfs subvolume create /media/myuser/btrbaks/BACKUPS/@
Routine backup commands
Here the commands that have to be launched for every backup
Rsync:
sudo rsync -aAXv --delete --exclude=/dev/* --exclude=/proc/* --exclude=/sys/* --exclude=/tmp/* --exclude=/run/* --exclude=/mnt/* --exclude=/media/* --exclude="swapfile" --exclude="lost+found" --exclude=/home/* --exclude=/root/* / /media/myuser/btrbaks/BACKUPS/@/
Btrfs snapshot:
sudo btrfs subvolume snapshot /media/myuser/btrbaks/BACKUPS/@ /media/myuser/btrbaks/BACKUPS/@_bak_`date +%Y.%m.%d_%H.%M.%S`
Then you can check:
sudo btrfs subvolume list /media/attilio/btrbaks/ ID 279 gen 109 top level 5 path BACKUPS/@ ID 280 gen 109 top level 5 path BACKUPS/@_bak_2020.09.14_08.12.2
Restoring
If your system boots, you can restore with:
sudo rsync -aAXv --dry-run --delete --exclude=/dev/* --exclude=/proc/* --exclude=/sys/* --exclude=/tmp/* --exclude=/run/* --exclude=/mnt/* --exclude=/media/* --exclude="swapfile" --exclude="lost+found" --exclude=/home/* --exclude=/root/* /media/attilio/btrbaks/BACKUPS/@/ /
Remember to delete the --dry-run option to perform a real restore.
Since @ points to your last backup, you can change it with @_bak_2020.09.14_08.12.22 or whichever snapshot.
If your system doesn't boot, you might boot from a live USB and perform the same command, changing the rsync <source> and <destination>
Note on partitions and mounts
This is my hardware configuration:
/dev/sda5 ext4 / # system installation /dev/sdb3 btrfs /media/myuser/btrbaks # external drive has several partitions, one is btrfs and here is the mount point that is automatically assigned by linux mint