LoginSignup
5
5

More than 5 years have passed since last update.

elasticsearchのindexバックアップ

Posted at

・elasticsearchのデータのバックアップをesclientを使用してダンプ取得する
・easy_installだと楽だけど、クローズドなオンプレミス環境向けにローカルインストールする手順
・python 2.6.6環境向けです(2.7だとargparse不要)

必要なものの配置

下記3本のtar.gzファイルをダウンロードして、インストール先サーバの/tmpに配置する
argparse

requests
http://goo.gl/dyOy4a

ESClient
http://goo.gl/lNkt4n

インストール

argparseインストール

# cd /tmp

# tar zxvf argparse-1.2.2.tar.gz

# cd argparse-1.2.2

# python setup.py install
〜省略〜
Installed /usr/lib/python2.6/site-packages/argparse-1.2.2-py2.6.egg
Processing dependencies for argparse==1.2.2
Finished processing dependencies for argparse==1.2.2

requestsインストール

# cd /tmp

# tar zxvf kennethreitz-requests-v2.4.3-44-g9dc6602.tar.gz

# cd kennethreitz-requests-9dc6602/

# python setup.py install
〜省略〜
Installed /usr/lib/python2.6/site-packages/requests-2.4.3-py2.6.egg
Processing dependencies for requests==2.4.3
Finished processing dependencies for requests==2.4.3

ESClientインストール

# tar zxvf ESClient-0.5.8.tar.gz

# cd ESClient-0.5.8

# python setup.py install
〜省略〜
Installed /usr/lib/python2.6/site-packages/ESClient-0.5.8-py2.6.egg
Processing dependencies for ESClient==0.5.8
Searching for argparse==1.2.2
Best match: argparse 1.2.2
Processing argparse-1.2.2-py2.6.egg
argparse 1.2.2 is already the active version in easy-install.pth

Using /usr/lib/python2.6/site-packages/argparse-1.2.2-py2.6.egg
Searching for requests==2.4.3
Best match: requests 2.4.3
Processing requests-2.4.3-py2.6.egg
requests 2.4.3 is already the active version in easy-install.pth

Using /usr/lib/python2.6/site-packages/requests-2.4.3-py2.6.egg
Finished processing dependencies for ESClient==0.5.8

日本語対応

データに日本語があるとesimportする時にこんなエラーが出ます

UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-3: ordinal not in range(128)

その対策で、pythonのデフォルトエンコードをUTF8に変更

# vi /usr/lib/python2.6/site-packages/sitecustomize.py
import sys
sys.setdefaultencoding("utf-8")

インストール確認

esdumpコマンド、esimportコマンドがインストールされてる事を確認

# which esdump
/usr/bin/esdump
# which esimport
/usr/bin/esimport

使い方

usage参照

# esdump
usage: esdump [-h] --url URL [--file FILE] [--mappingfile MAPPINGFILE]
              [--indexes INDEXES [INDEXES ...]] [--gzip] [--bzip2]
              [--stored-fields STORED_FIELDS [STORED_FIELDS ...]] [--count]
esdump: error: argument --url/-u is required

# esimport
usage: esimport [-h] --url URL [--file FILE] [--index INDEX]
                [--doctype DOCTYPE] [--recreate] [--mappingfile MAPPINGFILE]
esimport: error: argument --url/-u is required

特定のインデックスのバックアップ

例)kibanaのダッシュボード情報が入ってるkibana-intのバックアップ

# esdump --url http://localhost:9200/  --indexes kibana-int --bzip2 --file /tmp/esdump_kibana-int.bz2

バックアップファイルからのリストア

# esimport --url http://localhost:9200/  --file esdump_kibana-int.bz2
5
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
5