added ability to disable passes tracking

This commit is contained in:
Markus Ressel 2020-07-30 17:45:43 +02:00
parent 3d02d6c274
commit b258b6aa3b
2 changed files with 23 additions and 17 deletions

View File

@ -58,7 +58,7 @@ chmod +x ./zfs-inplace-rebalancing.sh
| Name | Description | Default | | Name | Description | Default |
|-----------|-------------|---------| |-----------|-------------|---------|
| -checksum | Whether to compare the copy using an **MD5** checksum | `true` | | -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 ### Example

View File

@ -60,12 +60,14 @@ function rebalance () {
progress_percent=$(echo "scale=2; ${current_index}*100/${file_count}" | bc) progress_percent=$(echo "scale=2; ${current_index}*100/${file_count}" | bc)
color_echo "${Cyan}" "Progress -- Files: ${current_index}/${file_count} (${progress_percent}%)" color_echo "${Cyan}" "Progress -- Files: ${current_index}/${file_count} (${progress_percent}%)"
if [ "${passes_flag}" -ge 1 ]; then
# check if target rebalance count is reached # check if target rebalance count is reached
rebalance_count=$(get_rebalance_count "${file_path}") rebalance_count=$(get_rebalance_count "${file_path}")
if [ "${rebalance_count}" -ge "${passes_flag}" ]; then if [ "${rebalance_count}" -ge "${passes_flag}" ]; then
color_echo "${Yellow}" "Rebalance count (${passes_flag}) reached, skipping: ${file_path}" color_echo "${Yellow}" "Rebalance count (${passes_flag}) reached, skipping: ${file_path}"
return return
fi fi
fi
tmp_extension=".balance" tmp_extension=".balance"
tmp_file_path="${file_path}${tmp_extension}" tmp_file_path="${file_path}${tmp_extension}"
@ -149,6 +151,7 @@ function rebalance () {
echo "Renaming temporary copy to original '${file_path}'..." echo "Renaming temporary copy to original '${file_path}'..."
mv "${tmp_file_path}" "${file_path}" mv "${tmp_file_path}" "${file_path}"
if [ "${passes_flag}" -ge 1 ]; then
# update rebalance "database" # update rebalance "database"
line_nr=$(grep -n "${file_path}" "./${rebalance_db_file_name}" | head -n 1 | cut -d: -f1) line_nr=$(grep -n "${file_path}" "./${rebalance_db_file_name}" | head -n 1 | cut -d: -f1)
if [ -z "${line_nr}" ]; then if [ -z "${line_nr}" ]; then
@ -160,6 +163,7 @@ function rebalance () {
rebalance_count="$((rebalance_count + 1))" rebalance_count="$((rebalance_count + 1))"
sed -i "${rebalance_count_line_nr}s/.*/${rebalance_count}/" "./${rebalance_db_file_name}" sed -i "${rebalance_count_line_nr}s/.*/${rebalance_count}/" "./${rebalance_db_file_name}"
fi fi
fi
} }
checksum_flag='true' checksum_flag='true'
@ -202,7 +206,9 @@ file_count=$(find "${root_path}" -type f | wc -l)
color_echo "$Cyan" " File count: ${file_count}" color_echo "$Cyan" " File count: ${file_count}"
# create db file # 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 # recursively scan through files and execute "rebalance" procedure
find "$root_path" -type f -print0 | while IFS= read -r -d '' file; do rebalance "$file"; done find "$root_path" -type f -print0 | while IFS= read -r -d '' file; do rebalance "$file"; done