ES热盘数据批量迁移到慢盘脚本

每天定时迁移热盘数据到慢盘,过一段时间发现快盘越来越容易满,每天数据量没有太大变化。查看es存储目录的索引文件,发现部分索引迁移失败导致的。
我们的日志索引是按"YYYY-mm-dd_项目名"命名,最近2天的数据存在热盘路径/data1/es/es_8351、es_8352、es_8353下。
写个脚本,遍历下历史索引在快盘存储目录下的文件大小,如果已经迁移到慢盘,快盘下存储的索引信息一般只有几K,到达M和G级别的都是迁移失败的索引,再次往慢盘组stale迁移


#!/bin/bash
# 
echo "开始检查快盘中的历史索引"

yestoday=`date -d '-1 day' "+%Y-%m-%d"`
today=`date +"%Y-%m-%d"`
tomorrow=`date -d '1 day' "+%Y-%m-%d"`
tempfile=tempfile.txt
cp -f /dev/null ${tempfile}

for port in 8351 8352 8353
do
	# ls /data1/es/es_8353/data/loganalysis/nodes
    esIndexNodePath="/data1/es/es_${port}/data/loganalysis/nodes"
	for item in `ls $esIndexNodePath`
	do
		esIndexStorePath="${esIndexNodePath}/${item}/indices/"
		# get all old index in fast disk
		# du -h --max-depth=1 /data1/es/es_8352/data/loganalysis/nodes/0/indices/
		du -h --max-depth=1 ${esIndexStorePath} | grep -v "K" | grep -v $yestoday | grep -v $today  | grep -v $tomorrow >> ${tempfile}

		#for line in `cat ${tempfile}` # | awk  '{print $1}'
		cat cat ${tempfile} |while read line
		do
			# ${"2G /data1/es/es_8353/data/loganalysis/nodes/0/indices/2017-06-05_ins-crawlerdata4cv-internal"##*/}
			currentIndex=${line##*/}
			#echo currentIndex
			if [ "$currentIndex" != "" ]
			then
				#echo $line
				echo "----------"$currentIndex"----------"
				#curlUrl="'192.168.72.21:8350/${currentIndex}/_settings' -d '{\"index.routing.allocation.require.group\": \"stale\"}'"
				curlUrl="http://192.168.72.21:8350/${currentIndex}/_settings"
				curl -XPUT ${curlUrl} -d '{"index.routing.allocation.require.group": "stale"}'
				echo ""
				sleep 10
			fi
		done

		cp -f /dev/null ${tempfile}
		sleep 20
	done
done

rm -f ${tempfile}

echo "end"
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值