digint / btrbk

Tool for creating snapshots and remote backups of btrfs subvolumes
https://digint.ch/btrbk/
GNU General Public License v3.0
1.72k stars 124 forks source link

How do I backup my root filesystem? - suggested FAQ entry #130

Open HaleTom opened 7 years ago

HaleTom commented 7 years ago

I've read the FAQ, but still am wondering about best practices to backup my root filesystem. The example given there was not sufficient for me to use as a template, so I wrote the following for inclusion / comment:

Backing up the root filesystem For this section, it is assumed that your rootfs is mounted with option subvol=/rootfs (See section titled "How do I convert '/' (subvolid=0) into a subvolume?"). Also, it is assumed that you have created a subvol=/btrbk-snap for storing snapshots generated by btrbk.

You will need to mount the rootfs volume a second time with subvol=/ so that the snapshots can be created in a different namespace (subvol=/btrbk-snap) than the one being backed up (subvol=/rootfs).

The following setup will mount rootfs's subvol=/ volume RO (to prevent mishaps inside /rootfs) at /mnt/btrfs-volume/rootfs. The snapshots directory (subvol=/btrbk-snap) will be RW mounted, overlayed on top of the RO version at /mnt/btrfs-volume/rootfs/btrbk-snap).

btrbk.conf:

snapshot_dir   btrbk-snap
volume /mnt/btrfs-volume/rootfs
  subvolume rootfs

etc/fstab:

# RO mount of rootfs volume, subvol=/
LABEL=rootfs   /mnt/btrfs-volume/rootfs   btrfs   ro,subvol=/
# RW mount of btrbk-snap, overlapping RO version above
LABEL=rootfs   /mnt/btrfs-volume/rootfs/btrbk-snap   btrfs   rw,subvol=/btrbk-snap
digint commented 7 years ago

@HaleTom Given your setup, what's the output of btrfs subvolume show /btrfs-volume/rootfs ?

I'm asking because on my system it does not show any UUID, which btrbk relies on (kernel 4.9.6, btrfs-progs 4.9):

Name:                   <FS_TREE>
UUID:                   -
Parent UUID:            -
Received UUID:          -
Creation time:          -
Subvolume ID:           5

This means it will not work for btrbk.

And what is your output for your snapshots btrfs subvolume show /mnt/btrfs-volume/rootfs/btrbk-snap/<snapshot-name> ?

HaleTom commented 7 years ago
(ins)svelte ~# btrfs subvolume show /mnt/btrfs-vol/rootfs/
/mnt/btrfs-vol/rootfs
        Name:                   <FS_TREE>
        UUID:                   -
        Parent UUID:            -
        Received UUID:          -
        Creation time:          -
        Subvolume ID:           5
        Generation:             4129
        Gen at creation:        0
        Parent ID:              0
        Top level ID:           0
        Flags:                  -
        Snapshot(s):
                                @
                                btrbk-snap

Here's one that I ran manually:

(ins)svelte ~# btrfs subvolume show /mnt/btrfs-vol/rootfs/btrbk-snap/rootfs.20170219T1951/
/mnt/btrfs-vol/rootfs/btrbk-snap/rootfs.20170219T1951
        Name:                   rootfs.20170219T1951
        UUID:                   ca61ddce-3fa1-ae4f-877e-d2f28b5b6ee8
        Parent UUID:            97039ed0-c127-9a45-b8a8-bbff9ea64888
        Received UUID:          -
        Creation time:          2017-02-19 19:51:22 +0700
        Subvolume ID:           269
        Generation:             4210
        Gen at creation:        4209
        Parent ID:              264
        Top level ID:           264
        Flags:                  readonly
        Snapshot(s):
(ins)svelte ~#

Its UUID matches up as parent of the next one (run by systemd.timer):

(ins)svelte ~# btrfs subvolume show /mnt/btrfs-vol/rootfs/btrbk-snap/rootfs.20170219T2000/
/mnt/btrfs-vol/rootfs/btrbk-snap/rootfs.20170219T2000
        Name:                   rootfs.20170219T2000
        UUID:                   d4431089-102c-834f-8f56-c3a353417adf
        Parent UUID:            97039ed0-c127-9a45-b8a8-bbff9ea64888
        Received UUID:          -
        Creation time:          2017-02-19 20:00:00 +0700
        Subvolume ID:           270
        Generation:             4224
        Gen at creation:        4223
        Parent ID:              264
        Top level ID:           264
        Flags:                  readonly
        Snapshot(s):
(ins)svelte ~# 
HaleTom commented 7 years ago

If my output is not what you expect to see, what mount command do you use for the root subvolume, and what is the output?

digint commented 7 years ago

Sorry for the late answer, I kind of forgot about this one...

Now this is strange, I expect the Parent UUID not to be set. Are you sure that rootfs.20170219T1951 is a snapshot of your root subvolume?

Does 97039ed0-c127-9a45-b8a8-bbff9ea64888 show up in:

btrfs subvolume list -a -c -u -q -R /mnt/btrfs-vol/rootfs
HaleTom commented 7 years ago

My turn to apologise: I've note been across my github notifications.

I may have rebuild things since February, so here's the above commands redone.

I currently only have 2 snapshots:

$ ls /mnt/btrfs-vol/rootfs/btrbk-snap/
rootfs.20170908T1211  rootfs.20170908T1247
$ sudo btrfs subvolume show /mnt/btrfs-vol/rootfs/btrbk-snap/rootfs.20170908T1211/
rootfs.20170908T1211
        Name:                   rootfs.20170908T1211
        UUID:                   28cbd79d-7dc4-9443-9be6-24a7d3b30779
        Parent UUID:            fe5a937d-8ef5-1145-b917-0f81419ff0b3
        Received UUID:          -
        Creation time:          2017-09-08 12:11:51 +0700
        Subvolume ID:           1409
        Generation:             106369
        Gen at creation:        106368
        Parent ID:              267
        Top level ID:           267
        Flags:                  readonly
        Snapshot(s):
$ sudo btrfs subvolume show /mnt/btrfs-vol/rootfs/btrbk-snap/rootfs.20170908T1247
rootfs.20170908T1247
        Name:                   rootfs.20170908T1247
        UUID:                   bfb481f5-56e4-ae46-ada0-a81b17de9a61
        Parent UUID:            fe5a937d-8ef5-1145-b917-0f81419ff0b3
        Received UUID:          -
        Creation time:          2017-09-08 12:47:10 +0700
        Subvolume ID:           1410
        Generation:             106436
        Gen at creation:        106435
        Parent ID:              267
        Top level ID:           267
        Flags:                  readonly
        Snapshot(s):
$ sudo btrfs subvolume list -a -c -u -q -R /mnt/btrfs-vol/rootfs
ID 267 gen 106442 cgen 50 top level 5 parent_uuid - received_uuid - uuid 95eb14a4-5104-5649-8a40-8a49624ff8da path btrbk-snap
ID 314 gen 106453 cgen 199 top level 5 parent_uuid 6b9d08af-9d06-9e41-a93a-8e3ece3c096f received_uuid - uuid fe5a937d-8ef5-1145-b917-0f81419ff0b3 path @
ID 1409 gen 106369 cgen 106368 top level 267 parent_uuid fe5a937d-8ef5-1145-b917-0f81419ff0b3 received_uuid - uuid 28cbd79d-7dc4-9443-9be6-24a7d3b30779 path <FS_TREE>/btrbk-snap/rootfs.20170908T1211
ID 1410 gen 106436 cgen 106435 top level 267 parent_uuid fe5a937d-8ef5-1145-b917-0f81419ff0b3 received_uuid - uuid bfb481f5-56e4-ae46-ada0-a81b17de9a61 path <FS_TREE>/btrbk-snap/rootfs.20170908T1247
$