From b258b6aa3bc763557200b338c1c1a8117d53e26d Mon Sep 17 00:00:00 2001 From: Markus Ressel Date: Thu, 30 Jul 2020 17:45:43 +0200 Subject: [PATCH] added ability to disable passes tracking --- README.md | 2 +- zfs-inplace-rebalancing.sh | 38 ++++++++++++++++++++++---------------- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 3cd671f..55769a1 100644 --- a/README.md +++ b/README.md @@ -58,7 +58,7 @@ chmod +x ./zfs-inplace-rebalancing.sh | Name | Description | Default | |-----------|-------------|---------| | -checksum | Whether to compare the copy using an **MD5** checksum | `true` | -| -passes | The maximum number of rebalance passes per file | `1` | +| -passes | The maximum number of rebalance passes per file. Setting this to infinity by using a value `<= 0` might improve performance when rebalancing a lot of small files. | `1` | ### Example diff --git a/zfs-inplace-rebalancing.sh b/zfs-inplace-rebalancing.sh index 7570319..19f6789 100755 --- a/zfs-inplace-rebalancing.sh +++ b/zfs-inplace-rebalancing.sh @@ -60,11 +60,13 @@ function rebalance () { progress_percent=$(echo "scale=2; ${current_index}*100/${file_count}" | bc) color_echo "${Cyan}" "Progress -- Files: ${current_index}/${file_count} (${progress_percent}%)" - # check if target rebalance count is reached - rebalance_count=$(get_rebalance_count "${file_path}") - if [ "${rebalance_count}" -ge "${passes_flag}" ]; then - color_echo "${Yellow}" "Rebalance count (${passes_flag}) reached, skipping: ${file_path}" - return + if [ "${passes_flag}" -ge 1 ]; then + # check if target rebalance count is reached + rebalance_count=$(get_rebalance_count "${file_path}") + if [ "${rebalance_count}" -ge "${passes_flag}" ]; then + color_echo "${Yellow}" "Rebalance count (${passes_flag}) reached, skipping: ${file_path}" + return + fi fi tmp_extension=".balance" @@ -149,16 +151,18 @@ function rebalance () { echo "Renaming temporary copy to original '${file_path}'..." mv "${tmp_file_path}" "${file_path}" - # update rebalance "database" - line_nr=$(grep -n "${file_path}" "./${rebalance_db_file_name}" | head -n 1 | cut -d: -f1) - if [ -z "${line_nr}" ]; then - rebalance_count=1 - echo "${file_path}" >> "./${rebalance_db_file_name}" - echo "${rebalance_count}" >> "./${rebalance_db_file_name}" - else - rebalance_count_line_nr="$((line_nr + 1))" - rebalance_count="$((rebalance_count + 1))" - sed -i "${rebalance_count_line_nr}s/.*/${rebalance_count}/" "./${rebalance_db_file_name}" + if [ "${passes_flag}" -ge 1 ]; then + # update rebalance "database" + line_nr=$(grep -n "${file_path}" "./${rebalance_db_file_name}" | head -n 1 | cut -d: -f1) + if [ -z "${line_nr}" ]; then + rebalance_count=1 + echo "${file_path}" >> "./${rebalance_db_file_name}" + echo "${rebalance_count}" >> "./${rebalance_db_file_name}" + else + rebalance_count_line_nr="$((line_nr + 1))" + rebalance_count="$((rebalance_count + 1))" + sed -i "${rebalance_count_line_nr}s/.*/${rebalance_count}/" "./${rebalance_db_file_name}" + fi fi } @@ -202,7 +206,9 @@ file_count=$(find "${root_path}" -type f | wc -l) color_echo "$Cyan" " File count: ${file_count}" # create db file -touch "./${rebalance_db_file_name}" +if [ "${passes_flag}" -ge 1 ]; then + touch "./${rebalance_db_file_name}" +fi # recursively scan through files and execute "rebalance" procedure find "$root_path" -type f -print0 | while IFS= read -r -d '' file; do rebalance "$file"; done