I was also wondering when a long lasting delete would finish so I came up with this little piece of shell code:
get_bytes() {
btrfs device usage --raw /mnt/data | egrep -- '-[0-9]+' | sed -E 's/[^0-9]+([0-9]+)/\1/'
}
prev=$(get_bytes)
while [ 1 ]; do
current=$(get_bytes)
diff=$((current-prev))
if [ "$diff" -gt 0 ]; then
dd if=/dev/zero iflag=count_bytes count="$diff" 2>/dev/null
fi
prev="$current"
sleep 1
done | pv -petraW -s $(get_bytes) >/dev/null
This will give you a nice progress bar like this:
0:13:54 [0,00 B/s] [16,0MiB/s] [> ] 1% ETA 19:23:19
The general idea is to use pv
to display progress. Since that command only allows to monitor bytes flowing through a pipe we use dd
to generate an appropriate amount of zeros and pipe them into pv
.
The advantage of this method is that you get a nice progress bar. However, since it seems btrfs
always deletes data one GB at a time it takes some time until a new difference in byte sizes can be observed.
To address this issue the flag -a
is added to the default flags of pv
to make it display an average transmission rate (since the normal current transmission rate will be 0 most of the time).
I realize this is not the best solution but the best I could come up with. If someone has ideas for improvements please let me know! :)
Balance on '/volume1' is running
28 out of about 171 chunks balanced (1156 considered), 84% left
. Unusually, the percentage counts down. – mwfearnley Apr 30 '18 at 09:41