安装elasticdump
安装npm工具
1 2 |
[root@es01 ~]# yum install -y npm |
下载包
1 |
[root@es01 ~]# wget https://npm.taobao.org/mirrors/node/v14.15.1/node-v14.15.1-linux-x64.tar.xz |
解压包
1 2 |
[root@es01 ~]# tar xf node-v10.16.3-linux-x64.tar.xz -C /opt/ |
移动并改名
1 2 |
[root@es01 ~]# mv node-v10.16.3-linux-x64 /opt/node |
配置环境变量并生效
1 2 3 |
[root@es01 ~]# echo "export PATH=/opt/node/bin:$PATH" >> /etc/profile [root@es01 ~]# source /etc/profile |
指定使用国内淘宝npm源
1 2 |
[root@es01 ~]# npm install -g cnpm --registry=https://registry.npm.taobao.org |
安装es-dump
1 2 |
[root@es01 ~]# cnpm install elasticdump -g |
备份工具
备份参数
1 2 3 4 |
--input:来源文件或地址 --output:目标文件或地址 --type:备份内容类型(settings, analyzer, data, mapping, alias, template) |
备份到另一台ES节点
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
elasticdump \ --input=http://10.0.0.91:9200/test \ --output=http://staging.es.com:9200/test \ --type=analyzer elasticdump \ --input=http://10.0.0.91:9200/test \ --output=http://staging.es.com:9200/test \ --type=mapping elasticdump \ --input=http://10.0.0.91:9200/test \ --output=http://staging.es.com:9200/test \ --type=data |
备份数据成json文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
elasticdump \ --input=http://10.0.0.91:9200/test \ --output=/data/test_mapping.json \ --type=mapping elasticdump \ --input=http://10.0.0.91:9200/test \ --output=/data/test_data.json \ --type=data elasticdump \ --input=http://10.0.0.91:9200/test \ --output=/data/test_alias.json \ --type=alias elasticdump \ --input=http://10.0.0.91:9200/test \ --output=/data/test_template.json \ --type=template elasticdump \ --input=http://10.0.0.91:9200/test \ --output=/data/test_analyzer.json \ --type=analyzer |
备份成压缩文件
1 2 3 4 5 |
#当文件导出不是为了使用,只是为了保存,可以压缩 elasticdump \ --input=http://10.0.0.91:9200/test \ --output=$ | gzip > /data/test_data.json.gz |
备份指定条件的数据
1 2 3 4 5 |
elasticdump \ --input=http://10.0.0.91:9200/test \ --output=/data/test_query.json \ --searchBody='{"query":{"term":{"name": "lhd"}}}' |
导入命令
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
elasticdump \ --input=/data/test_alias.json \ --output=http://10.0.0.91:9200/test \ --type=alias elasticdump \ --input=/data/test_analyzer.json \ --output=http://10.0.0.91:9200/test \ --type=analyzer elasticdump \ --input=/data/test_data.json \ --output=http://10.0.0.91:9200/test \ --type=data elasticdump \ --input=/data/test_template.json \ --output=http://10.0.0.91:9200/test \ --type=template elasticdump \ --input=/data/test_mapping.json \ --output=http://10.0.0.91:9200/test \ --type=mapping #注意:恢复的时候,如果已存在相同的数据,会覆盖原来的数据,如果不存在数据,则无影响 |
备份es脚本
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
#!/bin/bash echo '要备份的机器是:'${1} index_name=' test_2020-11-30 student linux7 ' for index in `echo $index_name` do echo "start input index ${index}" elasticdump --input=http://${1}:9200/${index} --output=/data/${index}_alias.json --type=alias &> /dev/null elasticdump --input=http://${1}:9200/${index} --output=/data/${index}_analyzer.json --type=analyzer &> /dev/null elasticdump --input=http://${1}:9200/${index} --output=/data/${index}_data.json --type=data &> /dev/null elasticdump --input=http://${1}:9200/${index} --output=/data/${index}_alias.json --type=alias &> /dev/null elasticdump --input=http://${1}:9200/${index} --output=/data/${index}_template.json --type=template &> /dev/null done |
导入es脚本
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
#!/bin/bash echo '要导入的机器是:'${1} index_name=' test student linux7 ' for index in `echo $index_name` do echo "start input index ${index}" elasticdump --input=/data/${index}_alias.json --output=http://${1}:9200/${index} --type=alias &> /dev/null elasticdump --input=/data/${index}_analyzer.json --output=http://${1}:9200/${index} --type=analyzer &> /dev/null elasticdump --input=/data/${index}_data.json --output=http://${1}:9200/${index} --type=data &> /dev/null elasticdump --input=/data/${index}_template.json --output=http://${1}:9200/${index} --type=template &> /dev/null done |