hnuzhoulin
1/14/2016 - 3:23 PM

修复ceph pg repair都无法修复的pg不连续

修复ceph pg repair都无法修复的pg不连续

#!/bin/bash
log=/root/ceph_yunwei/repair_pg_mismatch.log

pg=$1
filename=$2
disk_size=$3
meta_size=$4
size_hex_revert()
{
    size_hex=`printf '%x\n' $1`
    len=`echo ${#size_hex}`
    add_zero=`expr 6 - $len`
    for((i=1;i<=$add_zero;i++))
    do
        size_hex=0"$size_hex"
    done
    size_hex_revert=`echo ${size_hex:4:2}``echo ${size_hex:2:2}``echo ${size_hex:0:2}`
    echo $size_hex_revert
}

osds=`ceph pg map $1|awk '{print $10}'|sed 's/\[//g'|sed 's/\]//g'`
osd1=`echo ${osds}|awk -F\, '{print $1}'`
osd2=`echo ${osds}|awk -F\, '{print $2}'`
osd3=`echo ${osds}|awk -F\, '{print $3}'`

disk_size_hex_revert=`size_hex_revert $disk_size`
meta_size_hex_revert=`size_hex_revert $meta_size`
# disk_size_hex=`printf '%x\n' $disk_size`
# len1=`echo ${#disk_size_hex}`
# if [ '$len1' ]
# disk_size_hex_revert=`echo ${disk_size_hex:2:2}``echo ${disk_size_hex:0:2}`
# meta_size_hex=`printf '%x\n' $meta_size`
# meta_size_hex_revert=`echo ${meta_size_hex:2:2}``echo ${meta_size_hex:0:2}`

node1=`ceph osd find $osd1|grep '"host":'|awk -F\" '{print $6}'`
node2=`ceph osd find $osd2|grep '"host":'|awk -F\" '{print $6}'`
node3=`ceph osd find $osd3|grep '"host":'|awk -F\" '{print $6}'`

dirname="$pg"_head
file_path=`ssh $node1 'find /var/lib/ceph/osd/ceph-'$osd1'/current/'$dirname' -name "*'$filename'*"'`
ssh $node1 "attr -q -g ceph._ '$file_path' > /tmp/attr.1."$filename
ssh $node1 "hexdump -ve '1/1 \"%.2x\"' /tmp/attr.1."$filename" | sed 's/"$meta_size_hex_revert"/"$disk_size_hex_revert"/' | xxd -r -p > /tmp/attr.2"
ssh $node1 "attr -s ceph._ '$file_path' < /tmp/attr.2"
ssh $node1 "scp /tmp/attr.2 $node2:/tmp"
ssh $node1 "scp /tmp/attr.2 $node3:/tmp"
file_path2=`echo $file_path|sed 's/ceph-'$osd1'/ceph-'$osd2'/g'`
ssh $node2 "attr -s ceph._ '$file_path2' < /tmp/attr.2"
file_path3=`echo $file_path|sed 's/ceph-'$osd1'/ceph-'$osd3'/g'`
ssh $node3 "attr -s ceph._ '$file_path3' < /tmp/attr.2"

ceph pg repair $1