How to take a recursive snapshot of a btrfs subvol?

本小妞迷上赌 提交于 2021-02-09 07:16:03

问题


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 ?


回答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 >




回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/24625712/how-to-take-a-recursive-snapshot-of-a-btrfs-subvol

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!