Skip to content

Instantly share code, notes, and snippets.

@binwiederhier
Last active October 4, 2015 21:07
Show Gist options
  • Save binwiederhier/b08df612de3c55d22c28 to your computer and use it in GitHub Desktop.
Save binwiederhier/b08df612de3c55d22c28 to your computer and use it in GitHub Desktop.
# ./resilver
[So 4. Okt 22:02:28 BST 2015] Activating slow mirror ... OK
[So 4. Okt 22:02:39 BST 2015] Waiting 60 seconds for resilvering to start ... OK
[So 4. Okt 22:03:39 BST 2015] Waiting for resilvering to finish ..................................... OK
[So 4. Okt 22:05:22 BST 2015] Activating slow mirror ... OK
#!/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
POOL=tank
SLOWMIRROR=wwn-0x50004cf20c41a05b-part2
WAIT=60
if [ "$(id -u)" != "0" ]; then
echo "[$(date)] Script must be run as root."
exit 1
fi
if [ -n "$(zpool status $POOL | grep $SLOWMIRROR | grep ONLINE)" ]; then
echo "[$(date)] Slow mirror already online. Resilvering canceled."
exit 2
fi
echo -n "[$(date)] Activating slow mirror ..."
zpool online $POOL $SLOWMIRROR
echo " OK"
echo -n "[$(date)] Waiting $WAIT seconds for resilvering to start ..."
sleep $WAIT
echo " OK"
echo -n "[$(date)] Waiting for resilvering to finish ..."
while [ -n "$(zpool status $POOL | grep resilvering)" ]; do
echo -n "."
sleep 3
done
echo " OK"
echo -n "[$(date)] Activating slow mirror ..."
zpool offline $POOL $SLOWMIRROR
echo " OK"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment