forked from mirror/zfs-inplace-rebalancing
keep track of rebalances in a 'database' file
This commit is contained in:
13
README.md
13
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
|
||||
|
||||
|
||||
20
rebalance_db.txt
Normal file
20
rebalance_db.txt
Normal file
@@ -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
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user