Scheduled scrubs?


Recommended Posts

  • 1 year later...

If you install the Dynamix Trim plugin you can schedule Trim, but I am not aware of anything to schedule scrub. You could schedule a script to do it with the User Scripts plugin.

 

Github is back, I installed trim (which is a gread addon, I missed that one).

 

I also installed user scripts and have created a very crude little script to do a btrfs scrub of the cache drive:

 

btrfs scrub start -rdB /mnt/cache > /boot/logs/scrub_cache.log

 

When this is run in the background it works.. It is kind of crude in the sense that the fact that logfile is written does not mean that I will see it...

 

Anyone any idea what I could look at to make this thing use the web browser notification system to report starting and finishing the scrub ?

Link to comment

btrfs scrub start -rdB /mnt/cache > /boot/logs/scrub_cache.log

If you don't redirect the output, user scripts will be able to display the output from the script (ie: log) with a simple button press

Anyone any idea what I could look at to make this thing use the web browser notification system to report starting and finishing the scrub ?

Search for "scripts/notify" for examples of using the notifications. There are lots.

/usr/local/emhttp/plugins/dynamix/scripts/notify

will bring up all the options available.

 

  • Thanks 1
Link to comment

btrfs scrub start -rdB /mnt/cache > /boot/logs/scrub_cache.log

If you don't redirect the output, user scripts will be able to display the output from the script (ie: log) with a simple button press

Anyone any idea what I could look at to make this thing use the web browser notification system to report starting and finishing the scrub ?

Search for "scripts/notify" for examples of using the notifications. There are lots.

/usr/local/emhttp/plugins/dynamix/scripts/notify

will bring up all the options available.

 

Woo.. that is really nicely done.. I wasn't aware the notification system was so easy to use... I am now testing with the following setup:

 

/usr/local/emhttp/plugins/dynamix/scripts/notify -e "start_scrub_cache" -s "Scrub cache drive" -d "Scrub of cache drive started" -i "normal" -m "Scrubbing message"

btrfs scrub start -rdB /mnt/cache > /boot/logs/scrub_cache.log

/usr/local/emhttp/plugins/dynamix/scripts/notify -e "start_scrub_cache" -s "Scrub cache drive" -d "Scrub of cache drive finished" -i "normal" -m /boot/logs/scrub_cache.log

I am now actually trying to get some finished logfiles so I can see the structure of what is comming back.. With some grep's I think I will be able to assess a possible error condition and change the color of the notification based on that... Should not be very difficult I think..

 

Without actually trying the following should work I guess:

 

/usr/local/emhttp/plugins/dynamix/scripts/notify -e "start_scrub_cache" -s "Scrub cache drive" -d "Scrub of cache drive started" -i "normal" -m "Scrubbing message"
btrfs scrub start -rdB /mnt/cache > /boot/logs/scrub_cache.log
if grep -q error /boot/logs/scrub_cache.log; then
   /usr/local/emhttp/plugins/dynamix/scripts/notify -e "start_scrub_cache" -s "Scrub cache drive" -d "Error in scrub of cache drive !" -i "alert" -m /boot/logs/scrub_cache.log
fi
/usr/local/emhttp/plugins/dynamix/scripts/notify -e "start_scrub_cache" -s "Scrub cache drive" -d "Scrub of cache drive finished" -i "normal" -m /boot/logs/scrub_cache.log

Link to comment

Found a possible solution... Using the exitcodes..

 

I am now testing the following:

 

/usr/local/emhttp/plugins/dynamix/scripts/notify -e "start_scrub_cache" -s "Scrub cache drive" -d "Scrub of cache drive started" -i "normal" -m "Scrubbing message"
btrfs scrub start -rdB /mnt/cache > /boot/logs/scrub_cache.log
if [ $? -eq 0 ]
then
   /usr/local/emhttp/plugins/dynamix/scripts/notify -e "start_scrub_cache" -s "Scrub cache drive" -d "Scrub of cache drive finished" -i "normal" -m /boot/logs/scrub_cache.log
else
   /usr/local/emhttp/plugins/dynamix/scripts/notify -e "start_scrub_cache" -s "Scrub cache drive" -d "Error in scrub of cache drive !" -i "alert" -m /boot/logs/scrub_cache.log
fi

  • Like 1
  • Thanks 1
Link to comment
  • 3 years later...

I stumbled across this thread after running into a btrfs csum issue, and started looking for a way to schedule a scrub of all the btrfs disks in my system.  Big kudos to Constructor for the idea, Helmonder for the script, and Squid for adding the notify part.  You guys got me there!

 

I figured I summarize what I did to save folks from bouncing around.

 

I basically used Helmonder's script as a starting point.

  • I don't have notify set up to email me, I rely only on GUI notifications, so I dropped the -m part of the notifiy
  • I copied the script to have one for each disk  on my system (i.e. cache, disk1, disk2, etc.), making appropriate changes
/usr/local/emhttp/plugins/dynamix/scripts/notify -e "scrub_array" -s "Scrub Cache Drive" -d "Scrub of cache drive started" -i "normal"
btrfs scrub start -Bdr /mnt/cache > /var/log/scrub_array.log
if [ $? -eq 0 ]
then
  /usr/local/emhttp/plugins/dynamix/scripts/notify -e "scrub_array" -s "Scrub Cache Drive" -d "Scrub of cache drive finished" -i "normal"
else
  /usr/local/emhttp/plugins/dynamix/scripts/notify -e "scrub_array" -s "Scrub Cache Drive" -d "Error in scrub of cache drive!" -i "alert"
fi
  • I used crontab -e and added entries at the bottom to run each script at 10 pm starting on the 15th of every month, one disk per day.
#
# Run monthly cron jobs at 20:00 on the 15th day of the month:
00 20 15 * * /usr/local/emhttp/plugins/dynamix/scripts/scrub_cache &>/dev/null
#
# Run monthly cron jobs at 20:00 on the 16th day of the month:
00 20 16 * * /usr/local/emhttp/plugins/dynamix/scripts/scrub_disk1 &>/dev/null
...

Notifications look like:

1097272105_ScreenShot2020-07-28at7_43_00PM.jpg.b4153e75844c8eecfe8831028726c32e.jpg

 

  • Like 2
Link to comment

@CarpNCod thank you so much for posting that.  I can't believe it was just before I started looking for this, and I only just found out you need to regularly balance the btrfs pool...

 

Thanks to @Helmonder for the original as well.

 

I've taken that and used it to schedule a weekly scrub as well as a monthly balance (same script but running a balance).

I do have a question about the log file though, where do you find that?  I haven't run it yet, but wanted to do a test run and then check out the log file to make sure it works.

I'm also curious since you aren't correcting errors, if it does need to be corrected will it throw and error and alert you in the notification?  I'm not sure if that's the point of the error handling or if it's just if the script/command fails.

 

Edit: Oh and now that I know how to create a notification like that, I'm totally going to go back over my scripts and add more!

Edit2: oh I really don't have any scripts that need notifications, oh well.

Edited by lordbob75
Link to comment
49 minutes ago, johnnie.black said:

It shouldn't need regular balancing on current kernel, since kernel 4.15 IIRC

Ok, that's good to know.  I thought mine needed balancing but maybe not now that I look again.  Well for now I won't turn on the balance script and I'll keep a closer eye on it to see if it ever needs it.  Hopefully not, in which case I'll just keep the scrub one.

Link to comment
On 7/28/2020 at 11:46 PM, lordbob75 said:

@CarpNCod

I do have a question about the log file though, where do you find that?  I haven't run it yet, but wanted to do a test run and then check out the log file to make sure it works.

I'm also curious since you aren't correcting errors, if it does need to be corrected will it throw and error and alert you in the notification?  I'm not sure if that's the point of the error handling or if it's just if the script/command fails.

 

Edit: Oh and now that I know how to create a notification like that, I'm totally going to go back over my scripts and add more!

Edit2: oh I really don't have any scripts that need notifications, oh well.

I redirect the output of the scrub command to /var/log/scrub_array.log.  You can call it whatever you want, it will be overwritten each time the script runs.  If you just want to check the status of the last scrub run from the command line use btrfs scrub status /mnt/cache  Substitute for the drive you want the status of.  It will give you pretty much what is in the log file.  

 

You are correct, the point of this is just to let me know there is a problem.  If I get a notification that an error has been found, I check the Unraid syslog in the GUI -- Tools --> System Log.  Look for errors that look like this:  

 

Jul 11 13:10:32 Tower kernel: BTRFS warning (device md3): csum failed root 5 ino 9417 off 0 csum 0xff2f6c6e expected csum 0xfbf6a901 mirror 1

 

This is showing I had a check sum error on my data disk3 inode 9417.  You can then use ls or btrfs to correlate the inode to a file name.  I rename the file, and replace it from backup.  Then I run a scrub on the disk with the repair option.  Finally I go back and remove the renamed file.

Link to comment
  • 4 months later...

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...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.