3

Assume that a btrfs subvol named "child-subvol" is within a another subvol say, "root-subvol" and if we take snapshot of "root-subvol" then, the "child-subvol" should also be taken a snapshot.

Since recursive snapshot support is not yet there in btrfs file system, how can this be achieved alternatively ?

Pramod Aithal
  • 93
  • 1
  • 9

3 Answers3

1

Step 1: Get all the residing btrfs sub-volumes. Preferably in the sorted order as achieved by the command below.

$ btrfs subvolume list --sort=-path < top_subvol >

Step 2: In the order of preference as obtained, perform delete/Snapshot operation.

$ btrfs subvolume delete < subvol-name >

Pramod Aithal
  • 93
  • 1
  • 9
  • 1
    This is a wrong answer, because the "snapshot" procedure is not atomic. It should not be called a snapshot. The correct answer is: There is (still) no way to take recursive snapshots on Btrfs. Only ZFS has a feature of that kind (zfs snapshot -r). Unlike Btrfs, ZFS has a subvolume hierarchy organized in a tree structure separated from the mounted directory structure (apart from optional default mount points). The subvolume tree represents recursive snapshot atomicity coverage, regardless mount points. https://openzfs.github.io/openzfs-docs/man/8/zfs-snapshot.8.html – Andrej Podzimek Jul 15 '20 at 01:51
0

I've been wondering this too and haven't been able to find any recommended best practices online. It should be possible to write a script to create a snapshot that handles the recursion.

Peter R
  • 414
  • 2
  • 10
  • There is no way to write such a script without kernel-side support. A series of snapshots (without mutual atomicity) doesn't help. Let's assume that a program first creates a file in subvolume A and then writes a symlink to the new file into subvolume B. The wannabe-snapshotting script running around the same time could, for example, snapshot subvolume A first, _before_ the new file on A was created. Next it could snapshot subvolume B, _after_ the symlink from B to A was created. There. We have a dangling symlink between the two separate snapshots. – Andrej Podzimek Jul 15 '20 at 02:07
  • 1
    I'd say a non-atomic series of snapshots is better than failing to make any recursive snapshots at all though right? – Peter R Oct 15 '20 at 07:44
0

As Peter R suggests, you can write a script. However, if you want to send the subvolume it must be marked as readonly, and you can't snapshot recursively into readonly volumes.

To solve that you can use btrfs-property (found through this answear) in the script that handles recursion, making it (after all snapshots are taken) mark the snapshots readonly, so you can send them.

Alternatively, you can do

cp -a --reflink=always /path/to/root_subvol/ /path/to/child_subvol/

(--reflink=auto never worked for me before, and could also help you catch errors)

It should be fast, and afaik with the same advantages as a snapshot, although you don't keep the old subvolume structure.

Community
  • 1
  • 1
Olivetree
  • 424
  • 3
  • 11
  • 3
    snapshot is atomic per subvolume, reflink is atomic per file. Any program that uses multiple data files and modifies its data between the start and the end of a reflink copy may have its data corrupted (databases are particularly vulnerable to this.) – Perkins Aug 18 '17 at 18:09