markusressel / zfs-inplace-rebalancing

Simple bash script to rebalance pool data between all mirrors when adding vdevs to a pool.
Creative Commons Zero v1.0 Universal
340 stars 30 forks source link

Remove dependence on perl #41

Closed KarolKozlowski closed 2 months ago

KarolKozlowski commented 4 months ago

Perl is an unnecessary dependency, the same can be achieved using bash built-in.

markusressel commented 4 months ago

Hey @KarolKozlowski , looks great :+1: Does this also work on FreeBSD and Mac?

KarolKozlowski commented 3 months ago

I don't have easy access to neither of those, but I've got myself a OSX Ventura in kvm and prepared the following script to test this line in isolation:

#!/usr/bin/env bash

current_index=28203
file_count=44558

echo "uname:"
uname -a
echo "bash version:"
bash --version
echo "test: current_index=${current_index} file_count=${file_count}"
progress_percent=$(printf '%0.2f' "$(($current_index*10000/$file_count))e-2")
echo "Should be '63.29': ${progress_percent}" 

Te result from osx looks good:

uname:
Darwin Karols-iMac-Pro.local 22.6.0 Darwin Kernel Version 22.6.0: Mon Apr 22 20:54:28 PDT 2024; root:xnu-8796.141.3.705.2~1/RELEASE_X86_64 x86_64
bash version:
GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin22)
Copyright (C) 2007 Free Software Foundation, Inc.
test: current_index=28203 file_count=44558
Should be '63.29': 63.29

I'll get myself a freebsd in a similar fashion and get back to you with the results.

KarolKozlowski commented 2 months ago

Sorry it took so long, got myself a FreeBSD on an old laptop, here are the results:

karol@freebsd:~/tmp $ ./zfs-test.sh
uname:
FreeBSD freebsd 14.0-RELEASE-p9 FreeBSD 14.0-RELEASE-p9 #0: Tue Aug  6 19:52:06 UTC 2024     root@amd64-builder.daemonology.net:/usr/obj/usr/src/amd64.amd64/sys/GENERIC amd64
bash version:
GNU bash, version 5.2.26(1)-release (amd64-portbld-freebsd14.0)
Copyright (C) 2022 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
test: current_index=28203 file_count=44558
Should be '63.29': 63.29

So it looks good, moreover it works with the default interpreter as well (before installing bash):

karol@freebsd:~/tmp $ ./zfs-test.sh
uname:
FreeBSD freebsd 14.0-RELEASE-p9 FreeBSD 14.0-RELEASE-p9 #0: Tue Aug  6 19:52:06 UTC 2024     root@amd64-builder.daemonology.net:/usr/obj/usr/src/amd64.amd64/sys/GENERIC amd64
bash version:
./zfs-test.sh: bash: not found
test: current_index=28203 file_count=44558
Should be '63.29': 63.29
markusressel commented 2 months ago

@KarolKozlowski No worries, looks good! :+1: Shellcheck is still complaining about SC2004 though, is this a valid complain?

KarolKozlowski commented 2 months ago

@markusressel It was, just pushed the fix, and since the code changed I tested it again and it still looks good.

markusressel commented 2 months ago

Perfect! Merging now, thx for the efforts!