Created
September 27, 2018 21:21
-
-
Save raspi/a7ed5e46b3dc2108ec2afa55700a7058 to your computer and use it in GitHub Desktop.
Scrub ZFS every N days
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Wait this many days since last scrub | |
DAYS=30 | |
LANG=C | |
NOW=$(date -j +%s) | |
POOLS=$(zpool list -H -o name) | |
for pool in "$POOLS" | |
do | |
echo "pool: $pool" | |
ZPOOLSTATUS=$(/sbin/zpool status $pool) | |
if [ $(echo "$ZPOOLSTATUS" | egrep -c "none requested") -ge 1 ]; then | |
echo " ERROR: You need to run \"zpool scrub $pool\" before this script can monitor the scrub expiration time." | |
continue | |
fi | |
if [ $(echo "$ZPOOLSTATUS" | egrep -c "scrub in progress|resilver") -ge 1 ]; then | |
echo " already scrubbing" | |
continue | |
fi | |
# Get last time | |
POOLLASTSCRUB=$(echo "$ZPOOLSTATUS" | grep "scan:" | grep "scrub" | rev | cut -f1-4 -d ' ' | rev) | |
# convert scrub date to unix time | |
LASTSCRUB=$(date -j -f "%b %d %H:%M:%S %Y" "$POOLLASTSCRUB" +%s) | |
# Add N days to last time | |
NEXTSCRUB=$(date -j -v +${DAYS}d -r "$LASTSCRUB" +%s) | |
# compare current time | |
if [ "$NOW" -ge "$NEXTSCRUB" ]; then | |
echo " scrubbing" | |
/sbin/zpool scrub $pool | |
else | |
echo " no need for scrubbing" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment