elasticdump

elasticdump备份elasticsearch里面的某个索引数据

1、     安装环境

需要node、npm、yarn

# 去官方下载最新版本的nodejs

#wget https://nodejs.org/dist/v6.10.2/node-v6.10.2-linux-x64.tar.xz --no-check-certificate

# npm install –g yarn

# yarn install –g elasticdump

 

 

2、     备份操作

!备份到文件:

# elasticdump  --input=http://192.168.1.11:9200/userlog  --output=/data/userlog.json --type=data

 

!备份到另外的索引

# elasticdump  --input=http://192.168.1.11:9200/userlog  --output=http://192.168.1.11:9200/userlognew --type=data

 

3、     恢复索引

 # elasticdump --input=/data/userlog.json --output=http://192.168.1.11:9200/userlog  --type=data

 

以下摘自https://www.npmjs.com/package/elasticdump

 

# Copy an index from production to staging with analyzer and mapping:

elasticdump 

  --input=http://production.es.com:9200/my_index 

  --output=http://staging.es.com:9200/my_index 

  --type=analyzer

elasticdump 

  --input=http://production.es.com:9200/my_index 

  --output=http://staging.es.com:9200/my_index 

  --type=mapping

elasticdump 

  --input=http://production.es.com:9200/my_index 

  --output=http://staging.es.com:9200/my_index 

  --type=data

 

# 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

 

# Backup the results of a query to a file

elasticdump 

  --input=http://production.es.com:9200/my_index 

  --output=query.json 

  --searchBody '{"query":{"term":{"username": "admin"}}}'

 

Docker install

# docker pull taskrabbit/elasticsearch-dump
# docker run --rm -ti taskrabbit/elasticsearch-dump
you'll need to mount your file storage dir -v <your dumps dir>:<your mount point> to your docker container:挂载存储目录,存储备份数据
example:
 
# Copy an index from production to staging with mappings:
docker run --rm -ti taskrabbit/elasticsearch-dump 
  --input=http://production.es.com:9200/my_index 
  --output=http://staging.es.com:9200/my_index 
  --type=mapping
docker run --rm -ti taskrabbit/elasticsearch-dump 
  --input=http://production.es.com:9200/my_index 
  --output=http://staging.es.com:9200/my_index 
  --type=data
 
# Backup index data to a file:
docker run --rm -ti -v /data:/tmp taskrabbit/elasticsearch-dump 
  --input=http://production.es.com:9200/my_index 
  --output=/tmp/my_index_mapping.json 
  --type=mapping

 

原文地址:https://www.cnblogs.com/cuishuai/p/7839172.html