I have a laptop with an internal drive using Btrfs. There are several subvolumes and snapshots on here. I want a copy of this drive to be made periodically to an external USB disk of approximately the same size. The external drive must be bootable, and near enough identical to the internal one, so that if the main drive fails I can just swap it in.
What is the best way to achieve this?
Below, some methods I have considered:
I considered using Btrfs RAID 1, but this is really designed for a permanently connected drive, so I suspect it would not work well.
When I had the same disk and used Ext4 on both, I managed this setup with Rysnc, which worked well. I expect this would not work though now, because rsync would not understand the snapshots, and would copy everything many times.
Maybe using Btrfs send / receive could be made to work, but it is not so simple, because to send a filesystem, a read only snapshot must first be made, and then the name of this snapshot is used on the external disk. I don't think there is a way to receive the root filesystem, at /
Best Answer
This is the best solution. I use snapshots to make fast incremental backups of my servers. You can back up the root subvolume just like any other, but I don't think you can receive at the root. More to the point, you shouldn't do so, because that prevents you from enjoying one of the benefits of snapshotting: incremental backups. Done properly, it will only send the data that has changed and consume only the disk space for the changed data.
This script runs as a cron job and takes a daily snapshot of my root partition, then uses
btrfs send
to send an incremental copy to my backup partition. The script as written usespv
, but if for some reason you don't want to install it, you can simply removepv
from the middle of the pipes.(Note: I've adapted the script somewhat to make it into a general solution, and haven't tested it as written. Please feel free to submit revisions if necessary.)