logoalt Hacker News

atmosxtoday at 6:12 AM2 repliesview on HN

Once a month is fine ("/etc/cron.monthly/zfs-scrub"):

    #!/bin/bash
    #
    # ZFS scrub script for monthly maintenance
    # Place in /etc/cron.monthly/zfs-scrub
    
    POOL="storage"
    TAG="zfs-scrub"
    
    # Log start
    logger -t "$TAG" -p user.notice "Starting ZFS scrub on pool: $POOL"
    
    # Run the scrub
    if /sbin/zpool scrub "$POOL"; then
        logger -t "$TAG" -p user.notice "ZFS scrub initiated successfully on pool: $POOL"
    else
        logger -t "$TAG" -p user.err "Failed to start ZFS scrub on pool: $POOL"
        exit 1
    fi
    
    exit 0

Replies

k_bxtoday at 7:34 AM

Didn't know about the logger script, looks nice. Can it wrap the launch of the scrub itself so that it logs like logger too, or do you separately track its stdout/stderr when something happens?

update: figured how you can improve that call to add logs to logger

show 1 reply
chungytoday at 6:59 AM

That script might do with the "-w" parameter passed to scrub. Then "zpool scrub" won't return until the scrub is finished.