elasticsearch备份工具elasticsearch-dump(十)

携手创作,共同成长!这是我参与「掘金日新计划 · 8 月更文挑战」的第15天,点击查看活动详情

1.elasticsearch备份工具介绍

elasticsearch备份工具由elasticsearch-dump实现

官网:github.com/elasticsear…

2.安装elasticsearch-dump

1.下载elasticsearch-dump
[root@elasticsearch ~/soft]# git clone https://github.com/taskrabbit/elasticsearch-dump

2.安装elasticsearch-dump
[root@elasticsearch ~/soft]# mv elasticsearch-dump/ /data/
[root@elasticsearch ~/soft]# cd /data/elasticsearch-dump
[root@elasticsearch /data/elasticsearch-dump]# npm install elasticdump -g

3.查看版本
[root@elasticsearch /data/elasticsearch-dump]# elasticdump --version
6.62.1

复制代码

3.elasticsearch-dump备份实战

3.1.使用elasticsearch-dump备份xinwen索引库

命令语法:elasticdump --input es地址/索引 --output 备份到某个路径

[root@elasticsearch ~]# mkdir /data/es-backer
[root@elasticsearch ~]# elasticdump --input http://192.168.81.210:9200/xinwen --output /data/es-backer/xinwen.json
Thu, 14 Jan 2021 02:57:08 GMT | starting dump
Thu, 14 Jan 2021 02:57:09 GMT | got 4 objects from source elasticsearch (offset: 0)
Thu, 14 Jan 2021 02:57:09 GMT | sent 4 objects to destination file, wrote 4
Thu, 14 Jan 2021 02:57:09 GMT | got 0 objects from source elasticsearch (offset: 4)
Thu, 14 Jan 2021 02:57:09 GMT | Total Writes: 4
Thu, 14 Jan 2021 02:57:09 GMT | dump complete

复制代码

在这里插入图片描述

3.2.删除xinwen索引库

在kibana中删除

Delete xinwen

复制代码

在这里插入图片描述

删除成功 在这里插入图片描述

3.3.使用elasticsearch-dump还原xinwen索引库

命令语法:elasticdump --input 备份文件路径 --output es地址/索引

[root@elasticsearch ~]# elasticdump --input /data/es-backer/xinwen.json --output http://192.168.81.210:9200/xinwen
Thu, 14 Jan 2021 03:04:45 GMT | starting dump
Thu, 14 Jan 2021 03:04:45 GMT | got 4 objects from source file (offset: 0)
Thu, 14 Jan 2021 03:04:50 GMT | sent 4 objects to destination elasticsearch, wrote 4
Thu, 14 Jan 2021 03:04:50 GMT | got 0 objects from source file (offset: 4)
Thu, 14 Jan 2021 03:04:50 GMT | Total Writes: 4
Thu, 14 Jan 2021 03:04:50 GMT | dump complete
复制代码

还原xinwen索引库成功 在这里插入图片描述

4..两个es之间进行数据迁移

elasticdump --input 要迁移es1地址/索引 --output 迁移到es2地址/索引

[root@elasticsearch ~]# elasticdump --input http://192.168.81.210:9200/xinwen --output http://192.168.81.220:9200/xinwen
Thu, 14 Jan 2021 03:08:24 GMT | starting dump
Thu, 14 Jan 2021 03:08:24 GMT | got 4 objects from source elasticsearch (offset: 0)
Thu, 14 Jan 2021 03:08:32 GMT | sent 4 objects to destination elasticsearch, wrote 4
Thu, 14 Jan 2021 03:08:32 GMT | got 0 objects from source elasticsearch (offset: 4)
Thu, 14 Jan 2021 03:08:32 GMT | Total Writes: 4
Thu, 14 Jan 2021 03:08:32 GMT | dump complete
复制代码

5.安装elasticsearch-dump报错问题排查

报错内容如下

[root@elasticsearch /data/elasticsearch-dump]# npm install elasticdump
npm ERR! code ENOSELF
npm ERR! Refusing to install package with name "elasticdump" under a package
npm ERR! also called "elasticdump". Did you name your project the same
npm ERR! as the dependency you're installing?
npm ERR! 
npm ERR! For more information, see:
npm ERR!     <https://docs.npmjs.com/cli/install#limitations-of-npms-install-algorithm>

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2021-01-13T06_36_56_956Z-debug.log

报错内容翻译如下
错误的ERR! 代码ENOSELF
错误的ERR! 拒绝在包下安装名为“webpack”的包
错误的ERR! 也被称为“webpack”。 你的项目名称是否相同?
错误的ERR! 作为您正在安装的依赖项?
错误的ERR!
错误的ERR! 有关更多信息,请参阅:
错误的ERR!<https://docs.npmjs.com/cli/install#limitations-of-npms-install-algorithm>

错误的ERR! 可以在以下位置找到此运行的完整日志:
复制代码

在这里插入图片描述

错误解决

根据翻译的内容提示说我们包安装名相同,elasticsearch-dump目录下有个package.json的文件,打开文件,将里面的name字段值换成和npm安装插件的名称不一致就行

[root@elasticsearch /data/elasticsearch-dump]# vim package.json 
{
  "author": "Evan Tahler <[email protected]>",
  "name": "elasticdump1",				#随便改就行
	······
	
再次致谢npm install
[root@elasticsearch /data/elasticsearch-dump]# npm install elasticdump
npm WARN deprecated [email protected]: request has been deprecated, see https://github.com/request/request/issues/3142
npm WARN deprecated [email protected]: this library is no longer supported
npm WARN deprecated [email protected]: This module is no longer maintained. It is provided as is.
npm notice created a lockfile as package-lock.json. You should commit this file.
+ [email protected]
added 114 packages from 201 contributors in 37.994s
复制代码

在这里插入图片描述

猜你喜欢

转载自juejin.im/post/7131903014788399117
今日推荐