前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >elasticdump数据导入导出

elasticdump数据导入导出

作者头像
summerking
发布2022-09-19 11:49:48
1.4K0
发布2022-09-19 11:49:48
举报
文章被收录于专栏:summerking的专栏

# 1.需要npm环境

  • 上传node-v8.9.0包并解压
代码语言:javascript
复制
[root@summer ~]# ll
total 17480
-rw-------. 1 root root     1259 Sep 16 02:35 anaconda-ks.cfg
-rw-r--r--. 1 root root 17894489 Oct 27 09:04 node-v8.9.0-linux-x64 (1).tar.gz
[root@summer ~]# tar -zxf node-v8.9.0-linux-x64\ \(1\).tar.gz 
[root@summer ~]# ll
total 17480
-rw-------. 1 root root     1259 Sep 16 02:35 anaconda-ks.cfg
drwxrwxr-x. 6  500  500      108 Nov  1  2017 node-v8.9.0-linux-x64
-rw-r--r--. 1 root root 17894489 Oct 27 09:04 node-v8.9.0-linux-x64 (1).tar.gz
[root@summer ~]# pwd
/root
[root@summer ~]# ln -s /root/node-v8.9.0-linux-x64/bin/node /usr/bin/node
[root@summer ~]# ln -s /root/node-v8.9.0-linux-x64/bin/npm /usr/bin/npm

  • 验证
代码语言:javascript
复制
[root@summer ~]# node -v 
v8.9.0
[root@summer ~]# npm -v
5.5.1

# 2.安装elasticdump

  • 在线安装
代码语言:javascript
复制
[root@summer ~]# npm install elasticdump -g //全局安装
[root@summer ~]# ln -s /root/node-v8.9.0-linux-x64/lib/node_modules/elasticdump/bin/elasticdump /usr/bin/elasticdump
[root@summer ~]# elasticdump //简单验证
Fri, 23 Jan 2020 09:30:51 GMT | Error Emitted => {"errors":["`input` is a required input","`output` is a required input"]}

  • 离线安装 在同样的系统版本有网络的服务器下生成模块elasticdump缓存
代码语言:javascript
复制
# 查看缓存目录位置  npm config get cache
cd /root/.npm/
# 压缩缓存,并拷贝到待安装机器
tar -cf npm-cache.tar .npm

  • 上传npm-cache.tar到需要离线安装机器上
代码语言:javascript
复制
[root@summer ~]# ll
total 30620
-rw-------. 1 root root     1259 Sep 16 02:35 anaconda-ks.cfg
drwxrwxr-x. 6  500  500      108 Nov  1  2017 node-v8.9.0-linux-x64
-rw-r--r--. 1 root root 17894489 Oct 27 09:04 node-v8.9.0-linux-x64 (1).tar.gz
-rw-r--r--. 1 root root 13455360 Oct 27 09:09 npm-cache.tar

  • 解压 注意之前是没有.npm隐藏文件,解压后生成
代码语言:javascript
复制
[root@summer ~]# tar -xvf npm-cache.tar
[root@summer ~]# cd .npm/
[root@summer .npm]# ll
total 16
-rw-r--r--. 1 root root   171 Oct 23 17:17 anonymous-cli-metrics.json
drwxr-xr-x. 5 root root    51 Oct 23 17:16 _cacache
drwxr-xr-x. 2 root root     6 Oct 23 17:17 _locks
-rw-r--r--. 1 root root 10240 Oct 26 18:27 npm-cache.tar
[root@summer ~]# cd node-v8.9.0-linux-x64/lib/
[root@summer lib]# ll
total 0
drwxrwxr-x. 3 500 500 17 Nov  1  2017 node_modules
[root@summer lib]# npm install --cache /root/.npm --optional --cache-min 99999999999 --shrinkwrap false elasticdump
npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
npm WARN deprecated har-validator@5.1.5: this library is no longer supported
npm WARN deprecated s3signed@0.1.0: This module is no longer maintained. It is provided as is.
/root/node-v8.9.0-linux-x64/bin/elasticdump -> /root/node-v8.9.0-linux-x64/lib/node_modules/elasticdump/bin/elasticdump
/root/node-v8.9.0-linux-x64/bin/multielasticdump -> /root/node-v8.9.0-linux-x64/lib/node_modules/elasticdump/bin/multielasticdump
+ elasticdump@6.33.4
added 97 packages in 7.144s
[root@summer lib]# ln -s /root/node-v8.9.0-linux-x64/lib/node_modules/elasticdump/bin/elasticdump /usr/bin/elasticdump
[root@summer lib]# elasticdump
Tue, 27 Oct 2020 01:15:08 GMT | Error Emitted => {"errors":["`input` is a required input","`output` is a required input"]}

# 3.使用方式

  • elasticdump提供了多种导入导出数据的方式,可以 index <-> index 、 index <-> .json 文件,还支持将 index 查询结果导出到 .json 文件。执行的命令也很简单,只需指定数据来源 input 、数据输出 output 、数据类型 type 即可。
  • 支持导入导出的type列表

type

说明

settings

对应 es 中的 settings

analyzer

对应 es 中的 analyzer

data

es 查询出来的数据

mapping

对应 es 中的 mapping

alias

对应 es 中的 alias

template

对应 es 中的 template

# 4.导出示例

  • 导出当前索引的mapping结构
代码语言:javascript
复制
[root@summer ~]# elasticdump --input http://192.168.0.8:29200/x_restree --output ./x_restree_mapping.json --type=mapping

  • 导出当前索引下的所有真实数据
代码语言:javascript
复制
[root@summer ~]# elasticdump --input http://192.168.0.8:29200/x_restree --output ./x_restree_data.json --type=data

# 5.导入示例

  • 创建索引并导入数据
代码语言:javascript
复制
[root@summer ~]# curl -XPUT http://192.168.0.8:29200/x_restree

  • 导入mapping,设置type为mapping
代码语言:javascript
复制
[root@summer ~]# elasticdump --input ./x_restree_mapping.json --output http://192.168.0.8:29200/ --type=mapping

  • 导入data(真实数据)设置type为data
代码语言:javascript
复制
[root@summer ~]# elasticdump --input ./x_restree_data.json --output http://192.168.0.8:29200/ --type=data

# 6.官网例子

代码语言:javascript
复制
# Backup index data to a file:
elasticdump \
  --input=http://production.es.com:9200/my_index \
  --output=/data/my_index_mapping.json \
  --type=mapping
elasticdump \
  --input=http://production.es.com:9200/my_index \
  --output=/data/my_index.json \
  --type=data

# Backup and index to a gzip using stdout:
elasticdump \
  --input=http://production.es.com:9200/my_index \
  --output=$ \
  | gzip > /data/my_index.json.gz

# 7.报错解决

  • elasticdump遇到的错误node_modules/elasticdump/lib/processor.js:40
代码语言:javascript
复制
[root@summer ~]# elasticdump 
/usr/lib/node_modules/elasticdump/lib/processor.js:40
  async _loop (limit, offset, totalWrites) {
        ^^^^^

SyntaxError: Unexpected identifier
    at createScript (vm.js:56:10)
    at Object.runInThisContext (vm.js:97:10)
    at Module._compile (module.js:549:28)
    at Object.Module._extensions..js (module.js:586:10)
    at Module.load (module.js:494:32)
    at tryModuleLoad (module.js:453:12)
    at Function.Module._load (module.js:445:3)
    at Module.require (module.js:504:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/usr/lib/node_modules/elasticdump/elasticdump.js:3:28)
[root@summer ~]# npm install -g n 升级nodejs
/usr/bin/n -> /usr/lib/node_modules/n/bin/n
/usr/lib
└── n@7.0.0 
[root@summer ~]# n latest
  installing : node-v15.7.0
       mkdir : /usr/local/n/versions/node/15.7.0
       fetch : https://nodejs.org/dist/v15.7.0/node-v15.7.0-linux-x64.tar.xz
   installed : v15.7.0 (with npm 7.4.3)

Note: the node command changed location and the old location may be remembered in your current shell.
         old : /usr/bin/node
         new : /usr/local/bin/node
To reset the command location hash either start a new shell, or execute PATH="$PATH"
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2020-01-23,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • # 1.需要npm环境
  • # 2.安装elasticdump
  • # 3.使用方式
  • # 4.导出示例
  • # 5.导入示例
  • # 6.官网例子
  • # 7.报错解决
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档