Ceph inconsistent 错误修复脚本

#!/bin/bash

health_state=$(ceph -s | grep health | awk '{print $2}')
inconsistent_state=$(ceph -s | grep inconsistent)
damaged_pg=$(ceph health detail | grep -A1 PG_DAMAGED | tail -1 | awk '{print $2}')

date >>ceph-pg-repair.log
case $health_state in
"HEALTH_OK")
	echo "Cluster HEALTH_OK!" >>ceph-pg-repair.log
	;;

"HEALTH_WARN")
	echo "Cluster HEALTH_WARN!" >>ceph-pg-repair.log
	;;

"HEALTH_ERR")
	if [ -z "$inconsistent_state" ]; then
		echo "Cluster is not a consistency check problem!" >>ceph-pg-repair.log
	else
		if [ -z "$damaged_pg" ]; then
			echo "No PG with inconsistent found, please check manually!" >>ceph-pg-repair.log
		else
			ceph pg repair $damaged_pg
			if [ $? != 0 ]; then
				echo "Repair error, please check manually!" >>ceph-pg-repair.log
			fi
		fi
	fi
	;;

*)
	echo "Unknown state, please check manually!" >>ceph-pg-repair.log
	;;
esac
echo "------------------------------------------------------------" >>ceph-pg-repair.log
上一篇:Ceph 调整crush map


下一篇:Ceph学习笔记(2)- CRUSH数据分布算法