Linux Mastering Development

create recursive snapshots with BTRFS

I’m working on a shell script (just with btrfs default tools), which should do recursive snapshots of all subvolumes. My BTRFS looks like that and each directory is a subvolume. In the .snapshots directory are the snaps stored from the parent directory.

── .snapshots
├── sub1
│   ├── .snapshot
│   └── subsub1
│       └── .snapshot
├── sub2
│   ├── .snapshot
│   └── subsub2
│       └── .snapshot
└── sub3
    ├── .snapshot
    └── subsub3
        └── .snapshot

My problem

Imagine, there was a file added in subsub3 and you want to create a new snapshot from the whole BTRFS root and save it in .snapshots, then I see empty files and only from the direct childs. That means there is no directory sub3/subsub3 in the .snapshots directory.

With sudo -n btrfs subvolume list /path I can see all subvolumes and it’s possible to filter with awk '{print $2}' all IDs, but what’s the best way for recursion?

Can you give me a hint?

The result should be similar like zfs -r, but without using ZFS.

Leave a Reply

Your email address will not be published. Required fields are marked *