# 1.需要npm环境
- 上传node-v8.9.0包并解压
[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
- 验证
[root@summer ~]# node -v
v8.9.0
[root@summer ~]# npm -v
5.5.1
# 2.安装elasticdump
- 在线安装
[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缓存
# 查看缓存目录位置 npm config get cache
cd /root/.npm/
# 压缩缓存,并拷贝到待安装机器
tar -cf npm-cache.tar .npm
- 上传npm-cache.tar到需要离线安装机器上
[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隐藏文件,解压后生成
[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结构
[root@summer ~]# elasticdump --input http://192.168.0.8:29200/x_restree --output ./x_restree_mapping.json --type=mapping
- 导出当前索引下的所有真实数据
[root@summer ~]# elasticdump --input http://192.168.0.8:29200/x_restree --output ./x_restree_data.json --type=data
# 5.导入示例
- 创建索引并导入数据
[root@summer ~]# curl -XPUT http://192.168.0.8:29200/x_restree
- 导入mapping,设置type为mapping
[root@summer ~]# elasticdump --input ./x_restree_mapping.json --output http://192.168.0.8:29200/ --type=mapping
- 导入data(真实数据)设置type为data
[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
[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"