ElasticSearch备份工具

8/16/2022 ElasticSearch

# ElasticSearch备份工具介绍

ElasticSearch备份工具由elasticsearch-dump (opens new window)实现

# 安装elasticsearch-dump

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

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

# 3.查看版本
[root@elasticsearch /data/elasticsearch-dump]# elasticdump --version
6.62.1
1
2
3
4
5
6
7
8
9
10

# 可能报错

[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! 可以在以下位置找到此运行的完整日志:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

# 解决方案

  • 修改 package.jsonname,然后再次执行npm install
[root@elasticsearch /data/elasticsearch-dump]# vim package.json 
{
  "author": "Evan Tahler <evantahler@gmail.com>",
  "name": "elasticdump1",				#随便改就行
}
1
2
3
4
5

# 备份索引库

# 语法:elasticdump --input es地址/索引 --output 备份到某个路径
[root@elasticsearch ~]# mkdir /data/es-backer
[root@elasticsearch ~]# elasticdump --input http://172.31.80.1:9200/ajia --output /data/es-backer/ajia.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
1
2
3
4
5
6
7
8
9

# 测试还原

# 删除索引

  • 在kibana中删除:Delete ajia

# 还原索引库

# 语法:elasticdump --input 备份文件路径 --output es地址/索引
[root@elasticsearch ~]# elasticdump --input /data/es-backer/ajia.json --output http://172.31.80.1:9200/ajia
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
1
2
3
4
5
6
7
8

# 两个es之间进行数据迁移

# 语法:elasticdump --input 要迁移es1地址/索引 --output 迁移到es2地址/索引
[root@elasticsearch ~]# elasticdump --input http://172.31.80.1:9200/ajia --output http://172.31.80.2:9200/ajia
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
1
2
3
4
5
6
7
8