Created
April 27, 2017 17:00
-
-
Save wojas/2bc139f39cde1369196c545f9685a3a5 to your computer and use it in GitHub Desktop.
Get btrfs subvolume disk usage sorted by incremental size
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# NOTE: btrfs quota must be enabled for this to work: | |
# btrfs quota enable /btrfs/ | |
import os | |
import sys | |
usage = {} | |
for line in os.popen('btrfs qgroup show / --raw', 'r'): | |
# 0/10784 15678980096 557056 | |
if not line.startswith('0/'): | |
continue | |
p = line.strip().split() | |
sid = p[0].split('/')[1] | |
usage[sid] = (int(p[1]), int(p[2])) | |
output = [] | |
for line in os.popen('btrfs subvolume list /', 'r'): | |
# ID 10790 gen 301424 top level 264 path .snapshots/2878/snapshot | |
if not line.startswith('ID'): | |
continue | |
p = line.strip().split() | |
sid = p[1] | |
assert p[7] == 'path', p | |
path = p[8] | |
u = usage[sid] | |
output.append((sid, u[0], u[1], path)) | |
output.sort(key=lambda x: x[2]) | |
for o in output: | |
print("{:6} {:14,d} {:14,d} {}".format(*o)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment