Skip to content

Instantly share code, notes, and snippets.

@canhnt
Last active August 14, 2018 07:23
Show Gist options
  • Save canhnt/ffdee001b7aca43897ccfd14c3f6a92a to your computer and use it in GitHub Desktop.
Save canhnt/ffdee001b7aca43897ccfd14c3f6a92a to your computer and use it in GitHub Desktop.
Clean invalid LVs that exist in physical (via lvscan) but not managed by gluster
#!/usr/bin/env bash
# Find invalid LVs that exist in physical (via lvscan) but not managed by gluster
vgs=$1
host_address='10.165.210.xxx'
valid_lvs=$(gluster volume info | grep $vgs | grep ${host_address} | sed -e 's/.*brick_\(.[a-z0-9]*\)\/brick/\1/')
all_lvs=$(lvscan | grep $vgs | grep 'brick_' | awk -F'brick_' '{ print substr($2,0,32)}')
for lv in $all_lvs; do
valid=false
for valid_lv in $valid_lvs; do
if [ "$lv" == "$valid_lv" ]; then
valid=true;
break
fi
done
if [ "$valid" = false ]; then
echo "Invalid lv: $lv"
# umount "/dev/$vgs/brick_$lv"
# umount "/dev/$vgs/tp_$lv"
# lvremove -y "/dev/$vgs/brick_$lv"
# lvremove -y "/dev/$vgs/tp_$lv"
fi
done
## Sync Heketi db with Gluster via `heketi-cli device resync <id>`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment