Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace MD5 with CRC32 for 2x checksum speed #57

Merged
merged 2 commits into from
Jan 9, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions zfs-inplace-rebalancing.sh
Original file line number Diff line number Diff line change
Expand Up @@ -137,51 +137,51 @@ function rebalance() {
# Linux

# file attributes
original_md5=$(lsattr "${file_path}")
original_checksum=$(lsattr "${file_path}")
# remove anything after the last space
original_md5=${original_md5% *}
original_checksum=${original_checksum% *}
# file permissions, owner, group, size, modification time
original_md5="${original_md5} $(stat -c "%A %U %G %s %Y" "${file_path}")"
original_checksum="${original_checksum} $(stat -c "%A %U %G %s %Y" "${file_path}")"
# file content
original_md5="${original_md5} $(md5sum -b "${file_path}")"
original_checksum="${original_checksum} $(cksum "${file_path}")"


# file attributes
copy_md5=$(lsattr "${tmp_file_path}")
copy_checksum=$(lsattr "${tmp_file_path}")
# remove anything after the last space
copy_md5=${copy_md5% *}
copy_checksum=${copy_checksum% *}
# file permissions, owner, group, size, modification time
copy_md5="${copy_md5} $(stat -c "%A %U %G %s %Y" "${tmp_file_path}")"
copy_checksum="${copy_checksum} $(stat -c "%A %U %G %s %Y" "${tmp_file_path}")"
# file content
copy_md5="${copy_md5} $(md5sum -b "${tmp_file_path}")"
copy_checksum="${copy_checksum} $(cksum "${file_path}")"
# remove the temporary extension
copy_md5=${copy_md5%"${tmp_extension}"}
copy_checksum=${copy_checksum%"${tmp_extension}"}
elif [[ "${OSName}" == "darwin"* ]] || [[ "${OSName}" == "freebsd"* ]]; then
# Mac OS
# FreeBSD

# note: no lsattr on Mac OS or FreeBSD

# file permissions, owner, group size, modification time
original_md5="$(stat -f "%Sp %Su %Sg %z %m" "${file_path}")"
original_checksum="$(stat -f "%Sp %Su %Sg %z %m" "${file_path}")"
# file content
original_md5="${original_md5} $(md5 -q "${file_path}")"
original_checksum="${original_checksum} $(cksum "${file_path}")"

# file permissions, owner, group size, modification time
copy_md5="$(stat -f "%Sp %Su %Sg %z %m" "${tmp_file_path}")"
copy_checksum="$(stat -f "%Sp %Su %Sg %z %m" "${tmp_file_path}")"
# file content
copy_md5="${copy_md5} $(md5 -q "${tmp_file_path}")"
copy_checksum="${copy_checksum} $(cksum "${file_path}")"
# remove the temporary extension
copy_md5=${copy_md5%"${tmp_extension}"}
copy_checksum=${copy_checksum%"${tmp_extension}"}
else
echo "Unsupported OS type: $OSTYPE"
exit 1
fi

if [[ "${original_md5}" == "${copy_md5}"* ]]; then
color_echo "${Green}" "MD5 OK"
if [[ "${original_checksum}" == "${copy_checksum}"* ]]; then
color_echo "${Green}" "Checksum OK"
else
color_echo "${Red}" "MD5 FAILED: ${original_md5} != ${copy_md5}"
color_echo "${Red}" "Checksum FAILED: ${original_checksum} != ${copy_checksum}"
exit 1
fi
fi
Expand Down
Loading