How to check (simulate), how much space will be freed after I remove a btrfs subvolume

btrfsdisk-usage

The question is not trivial. BTRFS is COW file system and one object stored on hard disk can be referenced by many files.

I use BTRFS snapshots as a part of a backup solution on my production server. This way I have space-efficient, browsable history of a given subvolume (I use a modification of the SnapBtr).

I have several independent btrfs subvolumes for different purposes and a backup scheme for each one. When the free space is running out, I can get the most unneeded backup snapshot from each backup pool based on the smart logarithmic-time-cost algorithm of SnapBtr.

I need a way to weight the amount of data that will be freed after I remove each backup with age of the old snapshot and importance of its backup pool.
I am missing the former information.

I understand that the process of calculation of the free space on the BTRFS is neither trivial nor quick. I need something that would simulate the subvolume's deletion to get the size of the would-be freed space.

Can anyone help me? Should I post this message to the linux-btrfs@vger.kernel.org?

Best Answer

As demonstrated here, this is actually fairly simple to do.

First, enable btrfs quotas:

# btrfs quota enable /btrfs_subvolume

And then run:

# btrfs qgroup show /btrfs_subvolume
OR
# btrfs qgroup show -f /btrfs_subvolume

Which in Btrfs v3.18.2 shows you this:

qgroupid        rfer       excl
--------        ----       ----
0/260        1.09GiB    1.09GiB

The 0/260 is the subvolume ID, and the excl is the exclusive data in the subvolume. If you delete the subvolume, that's how much space you'll free up.

Edit: According to this link, this appears to be the official recommended way to do this.

Related Question