3

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.

STW
  • 1,908

1 Answers1

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"
STW
  • 1,908