有时候在ceph测试过程中需要手动对pg进行深度scrub,甚至对全部osd来做扫描,此种情况写了个脚本以供参考
#!/bin/sh
osd=$1
#扫描指定osd
do_one()
{
num=`ceph pg ls-by-primary osd.$1 | grep -i active | awk '{print $1}'|wc -l`
cat ${num}
for((i=1;i<=${num};i++))
do
sub=`ceph pg ls-by-primary osd.$1 | grep -i active | awk '{print $1}'|sed -n ${i}p`
ceph pg deep-scrub ${sub} >> scrub.log 2>&1
#ceph pg scrub ${sub}
done
}
#扫描全部osd
do_all()
{
osd_num=`ceph osd tree |grep osd |wc -l`
for i in `seq $osd_num`
do
do_one `expr $i - 1`
done
}
main()
{
echo "===Start as `date`===" > scrub.log
if [ $osd == "all" ];then
do_all
else
do_one $osd
fi
}
main $osd