automate/zfs-add-mirror.sh

32 lines
861 B
Bash

#!/bin/bash
# first disk reference from zpool status:
DISK_1=ata-HGST_HTS541010A9E680_JA1000102T3MZP
# second disk reference from /dev/disk/by-id
DISK_2=ata-APPLE_HDD_HTS541010A9E632_J88000HWGD8Z1B
# clone the original disk to give a bootable drive in the event of a failure
# and to shorten the resilvering process.
ddrescue \
--force \
--retry-passes=3 \
/dev/disk/by-id/${DISK_1} \
/dev/disk/by-id/${DISK_2} \
./logfile
# when cloning using ddrescue the zfs partitons have the same metadata as the original
# as shown by:
zdb -l /dev/disk/by-id/${DISK_2}-part2
# so we need to use:
zpool labelclear -f /dev/disk/by-id/${DISK_2}-part2
# attach the partitions as mirrors:
zpool attach -f rpool \
${DISK_1}-part2 \
${DISK_2}-part2
echo "the resilvering process will begin now, you can see its progress with zpool status -v"