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

来源:互联网 发布:淘宝购物高峰期 编辑:程序博客网 时间:2024/06/08 15:33

每天定时迁移热盘数据到慢盘,过一段时间发现快盘越来越容易满,每天数据量没有太大变化。查看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.txtcp -f /dev/null ${tempfile}for port in 8351 8352 8353do# ls /data1/es/es_8353/data/loganalysis/nodes    esIndexNodePath="/data1/es/es_${port}/data/loganalysis/nodes"for item in `ls $esIndexNodePath`doesIndexStorePath="${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 linedo# ${"2G /data1/es/es_8353/data/loganalysis/nodes/0/indices/2017-06-05_ins-crawlerdata4cv-internal"##*/}currentIndex=${line##*/}#echo currentIndexif [ "$currentIndex" != "" ]then#echo $lineecho "----------"$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 10fidonecp -f /dev/null ${tempfile}sleep 20donedonerm -f ${tempfile}echo "end"
原创粉丝点击