Pramod Aithal
Pramod Aithal

Reputation: 101

How to take a recursive snapshot of a btrfs subvol?

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 ?

Upvotes: 4

Views: 5008

Answers (3)

Olivetree
Olivetree

Reputation: 444

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.

Upvotes: 0

Pramod Aithal
Pramod Aithal

Reputation: 101

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 >

Upvotes: 0

Peter R
Peter R

Reputation: 414

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.

Upvotes: 0

Related Questions