A bash script to btrfs snapshot details like disk sizes (requires btrfs quota to be enabled)
Posted by jpluimers on 2016/09/06
One thing I’ve not figured out yet is this: How does enabling btrfs quotas impact the system? – Unix & Linux Stack Exchange
My gut feeling says it’s not much. But if someone knows: please chime in.
Anyway: btrfs quota support helps you to see how big snapshots (and other subvolumes) are.
Enabling and disabling is easy (the slash is the path from where to enable quota):
btrfs quota enable /
btrfs quota disable /
The bad thing is that there is no command that gives just the quota status. You have to revert to btrfs qgroup show /
This will show you quota groups when quota are enabled:
qgroupid rfer excl -------- ---- ---- 0/5 16.00KiB 16.00KiB
or errors when quota are disabled either of these two errors:
# btrfs qgroup show / ERROR: can't perform the search - No such file or directory ERROR: can't list qgroups: No such file or directory # btrfs qgroup show / ERROR: can't list qgroups: quotas not enabled
You might also want to check the syslogs as there was a [PATCH 1/2] btrfs: syslog when quota is enabled.
The btrfs qgroup
output is the base for agronick/btrfs-size: A script that will print out a list of BTRFS subvolumes along with their size in megabytes and their name.
It actually shows it in human readable form (kilo/mega/giga/… bytes) and is documented at Get the size of your BTRFS Snapshots | PoisonPacket. It gives me a nice overview that corresponds to the snapper list
output (see below).
The script has two drawbacks:
- when quota is disabled, you get this error:
./btrfs-size/btrfs-size.sh: line 55: can't + 0: syntax error: invalid arithmetic operator (error token is "'t + 0")
- it can take a while for
btrfs quota enable /
to actually deliver the quota for all the qgroupid values snapper uses. Until that time, the columns ID/Total/Exclusive Data are empty. - it won’t warn you if the quota data is out of data; to check that, run the below script
# btrfs qgroup show / > /dev/null
WARNING: Qgroup data inconsistent, rescan recommended
In that case, run btrfs quota rescan /
and wait for it to complete by running this command until the warning is gone:
# btrfs qgroup show / > /dev/null
WARNING: Rescan is running, qgroup data may be incorrect
If the warning reverts to WARNING: Qgroup data inconsistent, rescan recommended
then you might see the effects from this bug and should not worry about it: Bug 933428 – btrfs qgroup – allways shows WARNING: Qgroup data inconsistent.
For more btrfs quota background information, see: UseCases – btrfs Wiki.
–jeroen
revue:~ # Versioned/btrfs-size/btrfs-size.sh | |
================================================================================================================================================================ | |
Snapshot / Subvolume ID Total Exclusive Data | |
================================================================================================================================================================ | |
257 gen 422054 top level 5 path .snapshots 257 4.42MB 4.42MB | |
258 gen 422246 top level 257 path .snapshots/1/snapshot 258 3.26GB 86.29MB | |
259 gen 421215 top level 5 path boot/grub2/i386-pc 259 2.35MB 2.35MB | |
260 gen 421151 top level 5 path boot/grub2/x86_64-efi 260 16.00KB 16.00KB | |
261 gen 421151 top level 5 path opt 261 16.00KB 16.00KB | |
262 gen 422186 top level 5 path srv 262 860.00KB 860.00KB | |
263 gen 422246 top level 5 path tmp 263 2.30MB 2.30MB | |
264 gen 422049 top level 5 path usr/local 264 260.00KB 260.00KB | |
265 gen 421151 top level 5 path var/crash 265 16.00KB 16.00KB | |
266 gen 421243 top level 5 path var/lib/mailman 266 32.00KB 32.00KB | |
267 gen 422245 top level 5 path var/lib/named 267 16.20MB 16.20MB | |
268 gen 421151 top level 5 path var/lib/pgsql 268 16.00KB 16.00KB | |
269 gen 422235 top level 5 path var/log 269 1.06GB 1.06GB | |
270 gen 421151 top level 5 path var/opt 270 16.00KB 16.00KB | |
271 gen 422242 top level 5 path var/spool 271 72.00KB 72.00KB | |
272 gen 422076 top level 5 path var/tmp 272 80.00KB 80.00KB | |
274 gen 422076 top level 258 path var/lib/machines 274 16.00KB 16.00KB | |
696 gen 376646 top level 257 path .snapshots/381/snapshot 696 3.22GB 200.08MB | |
698 gen 376646 top level 257 path .snapshots/382/snapshot 698 3.23GB 7.66MB | |
701 gen 376646 top level 257 path .snapshots/385/snapshot 701 3.23GB 9.54MB | |
702 gen 376646 top level 257 path .snapshots/386/snapshot 702 3.23GB 6.37MB | |
703 gen 377727 top level 257 path .snapshots/387/snapshot 703 3.23GB 4.45MB | |
704 gen 377734 top level 257 path .snapshots/388/snapshot 704 3.24GB 19.12MB | |
705 gen 395465 top level 257 path .snapshots/389/snapshot 705 3.23GB 16.14MB | |
709 gen 395514 top level 257 path .snapshots/390/snapshot 709 3.39GB 58.66MB | |
710 gen 405061 top level 257 path .snapshots/391/snapshot 710 3.14GB 19.14MB | |
711 gen 405080 top level 257 path .snapshots/392/snapshot 711 3.38GB 52.80MB | |
712 gen 418679 top level 257 path .snapshots/393/snapshot 712 3.14GB 16.99MB | |
713 gen 418720 top level 257 path .snapshots/394/snapshot 713 3.37GB 43.46MB | |
714 gen 421129 top level 257 path .snapshots/395/snapshot 714 3.14GB 34.02MB | |
715 gen 422051 top level 257 path .snapshots/396/snapshot 715 3.31GB 71.84MB | |
================================================================================================================================================================ | |
Exclusive Total: 1.72GB | |
revue:~ # snapper list | |
Type | # | Pre # | Date | User | Cleanup | Description | Userdata | |
——-+—–+——-+————————–+——+———+———————–+————– | |
single | 0 | | | root | | current | | |
single | 1 | | Sat May 16 17:57:31 2015 | root | | first root filesystem | | |
pre | 381 | | Tue May 3 15:11:46 2016 | root | number | zypp(zypper) | important=yes | |
post | 382 | 381 | Tue May 3 15:14:11 2016 | root | number | | important=yes | |
pre | 385 | | Thu May 5 16:06:27 2016 | root | number | zypp(zypper) | important=no | |
post | 386 | 385 | Thu May 5 16:06:49 2016 | root | number | | important=no | |
pre | 387 | | Sun May 8 13:36:17 2016 | root | number | zypp(zypper) | important=no | |
post | 388 | 387 | Sun May 8 13:38:12 2016 | root | number | | important=no | |
pre | 389 | | Fri May 27 18:17:41 2016 | root | number | zypp(zypper) | important=yes | |
post | 390 | 389 | Fri May 27 18:26:09 2016 | root | number | | important=yes | |
pre | 391 | | Mon Jun 6 14:33:43 2016 | root | number | zypp(zypper) | important=yes | |
post | 392 | 391 | Mon Jun 6 14:39:50 2016 | root | number | | important=yes | |
pre | 393 | | Tue Jun 21 21:20:24 2016 | root | number | zypp(zypper) | important=yes | |
post | 394 | 393 | Tue Jun 21 21:27:29 2016 | root | number | | important=yes | |
pre | 395 | | Fri Jun 24 10:14:40 2016 | root | number | zypp(zypper) | important=yes | |
post | 396 | 395 | Fri Jun 24 11:17:32 2016 | root | number | | important=yes |
Nice diskinfo alias showing du, df, btrfs, parted, lsblk « The Wiert Corner – irregular stream of stuff said
[…] can combine this with A bash script to btrfs snapshot details like disk sizes (requires btrfs quota to be enabled) to find out which snapper snapshots take up a truckload of space and might be safely […]