#!/bin/bash
#
# Fix Split brain with gluster
#
SCRIPTPID=$!
usage()
{
echo "Fix Split-brain with Gluster"
echo "Usage:"
echo "$0 -f <filelist> -b <brick> -m <mountpoint>"
echo ""
echo " -f <filelist>"
echo " Filelist should contain files as"
echo " shown in 'gluster volume heal volumename info'"
echo " -b <brick>"
echo " Brick contains the actual brick folder"
echo " -m <mountpoint>"
echo " Mountpoint as it is locally mounted"
}
checkFiles()
{
CONFIRM=0
while read LINE
do
echo $LINE
[ ! -f $MOUNTPOINT/$LINE ] && CONFIRM=1
done
return $CONFIRM
}
confirm () {
# call with a prompt string or use a default
read -r -p "${1:-Are you sure? [y/N]} " response
case $response in
[yY][eE][sS]|[yY])
return 0
;;
*)
return 1
;;
esac
}
doFixSplitBrain()
{
echo "Mah brain hurts...."
echo " Processing filelist: $1"
echo " GlusterFS brick: $2"
echo " Mountpoint for data: $3"
echo "-------------------------------------------"
while read LINE
do
if [ ! -z $LINE ]
then
find $2 -samefile $2/$LINE -print -delete
stat $3/$LINE 2>&1 > /dev/null
fi
done < $1
}
while getopts "hf:b:m:" OPTION
do
case $OPTION in
h)
usage
exit 1
;;
f)
INPUTFILE=$OPTARG
;;
b)
BRICK=${OPTARG%/}
;;
m)
MOUNTPOINT=${OPTARG%/}
;;
?)
usage
exit
;;
esac
done
if [[ -z $INPUTFILE ]] || [[ -z $BRICK ]] || [[ -z $MOUNTPOINT ]] || [[ ! -f $INPUTFILE ]] || [[ ! -d $BRICK ]] || [[ ! -d $MOUNTPOINT ]]
then
usage
exit 1
fi
grep $MOUNTPOINT /proc/mounts | grep -i ' fuse.glusterfs ' 2>&1 /dev/null
wait $SCRIPTID
MOUNTEXISTS=$?
if [ $MOUNTEXISTS == 0 ]
then
echo "Mountpoint is correct!"
confirm "Are you sure you want to continue? [y/N]"
CONFIRMATION=$?
if [[ $CONFIRMATION -eq 0 ]]
then
doFixSplitBrain $INPUTFILE $BRICK $MOUNTPOINT
else
echo "Wise choice young grashoppah!"
fi
fi