Skip to content
View in the app

A better way to browse. Learn more.

Unraid

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

BTRFS - Script for mirror-rebuild status

Featured Replies

I just tried out rebuilding a BTRFS-Mirror with a new SSD. I found out there is no integrated way to monitor the mirror-rebuild status.

So I created a little script which monitors the status of the rebuild every 5 Minutes and notifies to the notification center.

 

The script might be far from perfect, but I thought I would share for anyone desperate for more infos.

 

Any upgrades are welcome!

 

Just create a new script in User-Scripts and enter the name of your cache in the first variable. Mine is "qvoraidone".

 

As soon as you replaced the broken SSD with a new one and started the array, you can let the script run in the background.

#!/bin/bash
#Enter name of cache to rebuild!
cache="qvoraidone"
#Variable for notification-timer in seconds
notificationtime="300"
#Putting the btrfs command into a variable
distribution="btrfs device usage /mnt/$cache/"

#Start a loop to notify the user every $notificationtime seconds about the status
while true
do

    #Make it multiline
    multilinedistribution="$($distribution \
    )"

    #Get the two lines with "Data,RAID1 " and Capture anything until the first "G".
    #Then put "o1"(only Group1), so everything between "Data,RAID1 " and "G" into a variable.
    #Looks like this "105.00 30.00"
    datasize=$(pcregrep -o1 '.*Data,RAID1: ([^G]+)' <<< "${multilinedistribution}")
    
    #Exchange the "." with "," - Not needed anymore
    #datasizecomma="${datasize2//./$','}"
    #echo datasizecomma $datasizecomma
    
    #Put them in an array for calculation
    array=($datasizecomma)
    array=($datasize)

    #Determine which is the larger number
    if [ ${array[0]} \> ${array[1]} ]
    then
        #calculate the percentage of the larger number
        echo ---------------------------
        status=$(awk "BEGIN {print ${array[0]}/${array[1]}*100}")
        echo "BTRFS-Rebuild status: "$status"% completed!"
        /usr/local/emhttp/webGui/scripts/notify -i normal -s "BTRFS-Rebuld still in progress!" -d ${array[0]}"GiB/"$status"% mirrored!"
        sleep $notificationtime
    else
        if [ ${array[1]} \> ${array[0]} ]
        then
            #calculate the percentage of the larger number
            echo ---------------------------
            status=$(awk "BEGIN {print ${array[1]}/${array[0]}*100}")
            echo "BTRFS-Rebuild status: "$status"% completed!"
            /usr/local/emhttp/webGui/scripts/notify -i normal -s "BTRFS-Rebuld still in progress" -d ${array[1]}"GiB/"$status"% mirrored!"
            sleep $notificationtime
        else
            #Determine if the numbers are equal
            if [ ${array[1]} \= ${array[0]} ]
            then 
                echo ---------------------------
                echo "Rebuild finished! "${array[0]}"GiB mirrored!"
                #Info to unRAID
                /usr/local/emhttp/webGui/scripts/notify -i normal -s "BTRFS-Rebuld finished!" -d ${array[0]}"GiB mirrored!"
                break
            else
                echo "ERROR, calculation failed!"
                #Warning to unRAID
                /usr/local/emhttp/webGui/scripts/notify -i alert -s "BTRFS-Rebuild Error!" -d "Could not calculate progress! Is "$cache" mounted?!"
                break
            fi
        fi
    fi
done

#More output
echo ---------------------------
echo "Data, single needs to be 0!"
echo "Data,RAID1 needs to be identical to be finished!"
echo ---------------------------
echo "Distribution"
echo ---------------------------
$distribution

 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.