centos6.8环境下安装elasticdump进行elasticsearch索引结构mapping的备份
1.安装npm,node
wget https://nodejs.org/dist/v10.14.2/node-v10.14.2-linux-x64.tar.xz
tar -xf node-v10.14.2-linux-x64.tar.xz -C /usr/local/
mv /usr/local/node-v10.14.2-linux-x64/ /usr/local/node
echo 'export PATH=/usr/local/node/bin:$PATH' >/etc/profile.d/nodejs.sh
source /etc/profile.d/nodejs.sh
source /etc/profile
[root@oracle bin]# node --version
v10.14.2
[root@oracle bin]# npm --version
6.4.1
2.安装elasticdump :
全局可用:
npm install elasticdump -g
elasticdump --version
6.33.3
3.备份mapping,即索引的结构,非data
# 编写脚本
# vim bakmapping.sh
#!/bin/bash
# 获取所有的索引结构,通过 elasticdump 工具把索引导出到指定位置
# 测试是否可行
#mappinglist=`curl -u elastic:pass -sXGET http://172.16.2.130:9200/_cat/indices?v|awk '{print $3}'|head -5`
mappinglist=`curl -u elastic:pass -sXGET http://172.16.2.130:9200/_cat/indices?v|awk '{print $3}'`
for i in ${mappinglist};do
/usr/local/node/bin/elasticdump --ignore-errors=true --scrollTime=120m --bulk=true --input=http://elastic:pass@172.16.2.130:9200/${i} --output=/opt/elk/mapping_bak/${i}.mapping.json --type=mapping
done
# 导出 ^sp_apps_active 开头的索引mapping(索引结构)
[root@spyzie-DB1:/opt/elk]# cat bakspappsmapping.sh
#!/bin/bash
#
mappinglist=`curl -u elastic:pass -sXGET http://172.16.2.130:9200/_cat/indices?v|awk '{print $3}' |egrep "^sp_apps_active"`
for i in ${mappinglist};do
/usr/local/node/bin/elasticdump --ignore-errors=true --scrollTime=120m --bulk=true --input=http://elastic:pass@172.16.2.130:9200/${i} --output=/opt/elk/sp_apps_active_mapping_bak/${i}.mapping.json --type=mapping
done