linux, shell

Check disk space of your BTRFS snapshots with btrfs-du

Today I want to share a simple way to check the state of our BTRFS snapshots.

Usage

If path is omitted, it will default to / .

We can list easily our snapshots, plus have a clear view of how much data they have in common and how much total overhead are we holding.

Four months worth of snapshots for only 7.48GB!!

Installation

Get the script and make it executable. You can do this in two lines, but better inspect it first. Don’t trust anyone blindly.

Details

Normally you can only get disk usage information through the quota info in qgroups

 

This is not ideal for a couple reasons:

  • First, we need to have quota enabled, which can have a performance impact with many subvolumes.
  • Second, we still have to list our subvolumes to correlate subvolume IDs to subvolume names. Two steps for a simple operation.

I was inspired by btrfs-size by Kyle Agronick, but not only the output wasn’t very clean to my taste, but also it was terribly slow on my root subvolume where docker uses BTRFS as storage driver and I have very many subvolumes. I am talking close to a minute.

Looking into the code to speed it up I decided that it would be cleaner to rewrite it as it was more complex that it needed to be. Also, quotas don’t need to be enabled for btrfs-du to work.

Code

github

Author: nachoparker

Humbly sharing things that I find useful
[ github dockerhub ]

One Commnet on “Check disk space of your BTRFS snapshots with btrfs-du

Leave a Reply

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