From ea7a5501b3156fce8a5b3f567bbf045f30612792 Mon Sep 17 00:00:00 2001 From: Markus Ressel Date: Thu, 30 Jul 2020 16:27:57 +0200 Subject: [PATCH] keep track of rebalances in a 'database' file --- README.md | 13 ++++++++++++- rebalance_db.txt | 20 ++++++++++++++++++++ zfs-inplace-rebalancing.sh | 17 +++++++++++++++++ 3 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 rebalance_db.txt diff --git a/README.md b/README.md index 2908008..3c1fd6e 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,18 @@ Note that this process is not entirely "in-place", since a file has to be fully At no point in time are both versions of the original file deleted. To make sure file attributes, permissions and file content are maintained when copying the original file, all attributes and the file checksum is compared before removing the original file. -Since file attributes are fully retained, it is not possible to verify if an individual file has been rebalanced. + +Since file attributes are fully retained, it is not possible to verify if an individual file has been rebalanced. However, this script keeps track of rebalanced files by maintaining a "database" file called `rebalance_db.txt` in its working directory. This file contains two lines of text for each processed file: + +* One line for the file path +* and the next line for the current count of rebalances + +```text +/my/example/pool/file1.mkv +1 +/my/example/pool/file2.mkv +1 +``` ## Prerequisites diff --git a/rebalance_db.txt b/rebalance_db.txt new file mode 100644 index 0000000..35bb732 --- /dev/null +++ b/rebalance_db.txt @@ -0,0 +1,20 @@ +/home/markus/music/Vorsingen 21.02.2020/080101-000.wav +1 +/home/markus/music/Vorsingen 21.02.2020/Der Vogelfänger - Can.mp3 +1 +/home/markus/music/Vorsingen 21.02.2020/Bona Nox - Chor.mp3 +1 +/home/markus/music/Vorsingen 21.02.2020/Gambenkanon - Chor.mp3 +1 +/home/markus/music/Vorsingen 21.02.2020/Großer Herr - Can.mp3 +1 +/home/markus/music/Vorsingen 21.02.2020/Arie des Harlekin - Bruno.mp3 +1 +/home/markus/music/190904-004.wav +1 +/home/markus/music/190904-002.wav +1 +/home/markus/music/190904-003.wav +1 +/home/markus/music/190904-002_edited.mp3 +1 diff --git a/zfs-inplace-rebalancing.sh b/zfs-inplace-rebalancing.sh index 9a8c079..77e9747 100755 --- a/zfs-inplace-rebalancing.sh +++ b/zfs-inplace-rebalancing.sh @@ -5,6 +5,9 @@ set -e # exit on undeclared variable set -u +# file used to track processed files +rebalance_db_file_name="rebalance_db.txt" + # index used for progress current_index=0 @@ -118,6 +121,20 @@ function rebalance () { echo "Renaming temporary copy to original '${file_path}'..." mv "${tmp_file_path}" "${file_path}" + + # update rebalance "database" + touch "./${rebalance_db_file_name}" + 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=$(awk "NR == ${rebalance_count_line_nr}" "./${rebalance_db_file_name}") + rebalance_count="$((rebalance_count + 1))" + sed -i "${rebalance_count_line_nr}s/.*/${rebalance_count}/" "./${rebalance_db_file_name}" + fi } root_path=$1