4 Managing Subvolumes and Snapshots

The top level of a Btrfs file system is a subvolume consisting of a named B-tree structure containing directories, files, and possibly further subvolumes that are also named B-trees, each of which also contains directories and files, and so on.

Snapshots are a type of subvolume that record the contents of their parent subvolumes at the time that you took the snapshot. If you take a snapshot of a Btrfs file system and don't write to it, the snapshot records the state of the original file system and forms a stable image from which you can make a backup. If you make a snapshot writable, you can treat it as a alternative version of the original file system. The copy-on-write functionality of a btrfs file system means that snapshots are created quickly and consume little disk space initially.

Taking snapshots of a subvolume isn't a recursive process. If you create a snapshot of a subvolume, every subvolume or snapshot that the subvolume contains is mapped to an empty directory of the same name inside that snapshot.

Attention:

Snapshots record the state of the file system at a moment in time. As such, it's not possible to guarantee file system integrity for transactional processes that might have been in operation at the time when a snapshot was taken. While utilities such as the snapper command might help capture before and after snapshots for particular operations, such as when using the dnf command, these snapshots are still unaware of other processes that might be running on the system at the same time. If you have processes that have intensive I/O or memory usage, such as database or middleware applications, stop these or ensure that all activity is complete before taking a snapshot to reduce the likelihood of data integrity or file system corruption issues within the snapshot.

The snapper command to be used to create and manage Btrfs snapshots and provides automation facilities to ensure that snapshots are taken at key system events such as during software installation or upgrade, see Automating File System Snapshots With the Snapper Utility.

You can mount a Btrfs subvolume as though it were a disk device. If you mount a snapshot instead of its parent subvolume, you effectively roll back the state of the file system to when the snapshot was taken. By default, the operating system mounts the parent Btrfs volume, which has an ID of 5, unless you use the set-default option to change the default subvolume. If you set a new default subvolume, the system mounts that subvolume going forward. Y

After you have rolled back a file system by mounting a snapshot, you can take snapshots of the snapshot to record its state as it changes.

Deleting a subvolume deletes all subvolumes under it in the B-tree hierarchy. For this reason, you can't remove the topmost subvolume of a Btrfs file system, which has an ID of 5.