Use mountpoints instead of block devices so that RAIDs don't get angry

This commit is contained in:
Logan G 2023-02-24 22:57:28 -07:00
parent d4bdedb018
commit 6711efc131
Signed by: logan
GPG key ID: E328528C921E7A7A

View file

@ -1,16 +1,19 @@
#!/bin/bash
set -e
# Find all BTRFS formatted partitions
# Find the mountpoint for all BTRFS formatted partitions
PARTITIONS=()
for i in $(lsblk -nrpo "name" -e 1,7,11); do
if [[ "$(lsblk -no FSTYPE "$i")" == "btrfs" ]]; then
PARTITIONS+=("$i")
PARTITIONS+=("$(findmnt -v -y --real -f -o TARGET -n $i)")
fi
done
# Remove duplicates, semi-jankily
PARTITIONS=($(echo ${PARTITIONS[@]} | tr ' ' '\n' | sort -u | tr '\n' ' '))
# Reallocate blocks that are less than 95% used
for i in ${PARTITIONS[*]}; do
for i in ${PARTITIONS[@]}; do
{
echo "Starting balance on $i"
btrfs balance start -dusage=95 "$i"
@ -22,7 +25,7 @@ done
wait
# Scrub all partitions
for i in ${PARTITIONS[*]}; do
for i in ${PARTITIONS[@]}; do
{
echo "Starting scrub on $i"
btrfs scrub start -B "$i"