elasticdump 遷移 elasticsearch 數據
elasticdump github地址
https://github.com/taskrabbit/elasticsearch-dump
折騰了一會nodejs耐心盡失,果斷使用docker方式。
1、下載docker鏡像
拉取鏡像
docker pull taskrabbit/elasticsearch-dump
2、導出數據
如果將數據導出爲文件形式,需要將宿主機目錄掛載至容器上。
# 提前創建數據目錄。
mkdir /data
導出數據至json文件中,將宿主機/data目錄掛載到容器/tmp目錄上,--output指定文件導出至/tmp目錄中。
docker run --net=host --rm -ti -v /data:/tmp taskrabbit/elasticsearch-dump \
--input=http://localhost:9200/info-ad \
--output=/tmp/info-ad-map.json \
--type=data
# 導出日誌
Wed, 11 Dec 2019 09:45:35 GMT | starting dump
Wed, 11 Dec 2019 09:45:35 GMT | got 16 objects from source elasticsearch (offset: 0)
Wed, 11 Dec 2019 09:45:35 GMT | sent 16 objects to destination file, wrote 16
Wed, 11 Dec 2019 09:45:35 GMT | got 0 objects from source elasticsearch (offset: 16)
Wed, 11 Dec 2019 09:45:35 GMT | Total Writes: 16
Wed, 11 Dec 2019 09:45:35 GMT | dump complete
# 導出文件
[root@localhost /data]# ll
total 20
-rw-r--r--. 1 root root 18192 Dec 11 17:45 info-ad-map.json
3、導入數據
docker run --net=host --rm -ti -v /data:/tmp taskrabbit/elasticsearch-dump \
--input=/tmp/info-ad-map.json \
--output=http://localhost:9200/abcd
# 導入日誌
Wed, 11 Dec 2019 09:47:43 GMT | starting dump
Wed, 11 Dec 2019 09:47:43 GMT | got 16 objects from source file (offset: 0)
Wed, 11 Dec 2019 09:47:44 GMT | sent 16 objects to destination elasticsearch, wrote 16
Wed, 11 Dec 2019 09:47:44 GMT | got 0 objects from source file (offset: 16)
Wed, 11 Dec 2019 09:47:44 GMT | Total Writes: 16
Wed, 11 Dec 2019 09:47:44 GMT | dump complete
ps:在使用localhost:9200時需要使用--net=host將網絡掛載到容器上