1

I rotate physical disks in and out of my mirrored ZFS zpool (using ZoL) to use for offsite backups; to help streamline the process I've been using udev rules to respond to the drives being swapped.

Currently when a drive is inserted I use a zfs attach, which requires the name of an existing drive from within the pool. For now it's hardcoded to one of the disks that never goes offsite.

So, rather than hardcoding an id, how could I get the ID of an online disk for the target pool? Currently I'm toying with grepping it from zpool status but was hoping there might be a better option.

  • Wouldn't it be safer to use incremental snapshots with zfs send and zfs recv to achieve off-site backups? – Darth Android Apr 1 '15 at 17:01
  • @DarthAndroid sure, but that's a different topic altogether. – STW Apr 1 '15 at 18:06
  • Why not use zpool online and zpool offline? That will require the pool and device names; the device name should be handed to you on a silver platter (no pun intended) by udev, and the pool name can easily be extracted from the device by zdb <device> -l or perhaps hardcoded if there's only one pool involved. ZFS will automatically resilver an out-of-date device in a pool when it is brought online. – a CVn Oct 20 '15 at 18:08
0

For now I put together a little script, zfs-online-disks.sh that pulls the online disks out of zpool status:

#!/bin/bash

# Return a list of online disks for a storage pool

ONLINE=$(zpool status $1 | grep -Po "\S*(?=\s*ONLINE)")

while read -r line; do
  if ! [ -b "/dev/disk/by-id/$line" ]; then
    continue
  fi
  echo $line
done <<< "$ONLINE"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.