Last active
September 13, 2023 16:02
-
-
Save enkore/0c93ba5c122c18628035ffc89df98c03 to your computer and use it in GitHub Desktop.
Report pool usage on Samba shares using multiple ZFS datasets
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
#!/bin/bash | |
# Suppose you export a dataset via Samba, then Samba will do df(1), which will only | |
# show the space used by the dataset of the shared directory. If you have datasets nestled | |
# within, then the space used by them will not show up in the overall share space usage: | |
# | |
# /mnt/tank/ -- using X TB from the pool | |
# /mnt/tank/dataset1 -- using Y TB from the pool | |
# /mnt/tank/dataset2 -- using Z TB from the pool | |
# | |
# By default you would only see X TB used on the /mnt/tank share. | |
# This small script simply sums the space used by all datasets in a share recursively, | |
# so you end up with X+Y+Z TB reported for the /mnt/tank share when you set this script | |
# as the "dfree command" (https://www.samba.org/samba/docs/current/man-html/smb.conf.5.html#idm2868). | |
# Linuxistic Bashisms. | |
POOL=$(findmnt -no source -T "$PWD") | |
USED=$(zfs list -rHp -o used "$POOL" | awk '{s+=$1} END {printf "%.0f\n", s}') | |
AVAIL=$(zfs list -Hp -o avail "$POOL") | |
TOTAL=$(($USED + $AVAIL)) | |
echo "$TOTAL $AVAIL 1" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment