4

I have a question about backuping BTRFS partitions.

Assume I have a BTRFS partition on /dev/sda1 and an external harddrive with BTRFS on /dev/sdb1.

I already found out I can make an initial backup by issuing:

btrfs replace start /dev/sda1 /dev/sdb1

Afterwards I change 2 things:

  • I create a new regular file on SDA1
  • I create a new BTRFS snapshot on SDA1

Now I want to bring my external harddrive SDB1 ('backup') aligned with SDA1. So both the files as the BTRFS specific stuff (snapshots).

How do I do this?

So I am looking for the rsync equivalent which also syncs the BTFS features (snapshots):

rsync -avr --delete <mount point sda1> <mount point sdb1>

Thanks

3

The replace command doesn't make a backup of sda1, it replaces sda1 with sdb1 in the filesystem, but since it's a one device filesystem and btrfs doesn't bother wiping the data from sda1 when it replaces it they end up being indentical copies of the filesystem. However you do NOT want to do this as both will have the same UUID, and currently it's not safe to mount two btrfs filesystems with the same UUID as it can cause MASSIVE DATA CORRUPTION (see btrfswiki's Gotchas page). If you want to use btrfs's incremental backup feature you should format you're backup drive /dev/sdb1 to a new btrfs filesystem. Then you should make a read-only snapshot of watever subvolume(s) you want to backup on your filesystem by using

btrfs su sn -r @subvolume-name @subvolume-name-RO

on each subvolume. Then you should mount the blank btrfs filesystem and run

btrfs send /path/to/@subvolume-name-RO | btrfs rec /path/to/backup-directory/

This will be the first send and btrfs will have to transfer all of the data this time. Next time you want to send a backup to this drive you can use incremental sends to only send what data has changed since the previous backup you sent. It will also use Copy On Write so you'll save a lot of space as well. Just make sure you keep the latest snapshot on both filesystems. When it's done you can rename the sent snapshot to whatever you want.

Now if you want to send another snapshot just rename the orignal one and take a new snapshot with something like

mv @subvolume-name-RO @subvolume-name-RO-old
btrfs su sn -r @subvolume-name @subvolume-name-RO

Then you can use send to send the latest snapshot using

btrfs send -p @subvolume-name-RO-old @subvolume-name-RO | btrfs rec /path/to/backup-directory/

and if the previous snapshot still exists on your backup drive it will send your new snapshot by only having to copy whatever changes you've made since the previous one.

  • I saw the @name syntax in one of your other answers and I was curious. Is prepending names of subvolumes with @ a convention, or a BCP of some kind? I use Btrfs but none of my subvolumes (including snapshots) have names that begin with @. Hmm, maybe I should ask this as a new question... – Celada Jun 26 '15 at 7:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.