diff --git a/usr/local/bin/btrfs-maintenance b/usr/local/bin/btrfs-maintenance index 2067927..8f96954 100755 --- a/usr/local/bin/btrfs-maintenance +++ b/usr/local/bin/btrfs-maintenance @@ -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"