Skip to content

Instantly share code, notes, and snippets.

@tylerflint
Last active August 29, 2015 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tylerflint/601a88756ab468fc5ce7 to your computer and use it in GitHub Desktop.
Save tylerflint/601a88756ab468fc5ce7 to your computer and use it in GitHub Desktop.
SmartOS cleanup crufty zone datasets
#!/usr/bin/env bash
zfs_uuids=$(zfs list | /usr/xpg4/bin/grep -E -e 'zones/[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12}$' | awk '{ print $1 }' | awk -F/ '{ print $2 }')
vmadm_uuids=$(vmadm list | tail -n +2 | awk '{ print $1 }')
imgadm_uuids=$(ls -1 /var/imgadm/images | sed 's/zones-//' | sed 's/\.json//')
symmetric_uuids=$(comm -3 <(echo "$zfs_uuids" | sort -) <(echo "$vmadm_uuids" | sort -))
symmetric_uuids=$(comm -3 <(echo "$symmetric_uuids" | sort -) <(echo "$imgadm_uuids" | sort -))
for uuid in $symmetric_uuids
do
echo "destroying crufty dataset zones/${uuid}"
zfs destroy zones/${uuid}
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment