ようへいの日々精進XP

よかろうもん

elasticsearch 1.0.0 RC1 の Snapshot と Restore 機能を触ってみる(Amazon S3 にスナップショットを取る)

はじめに

  • 前回の続き
  • スナップショットが Amazon S3 に取れるようだけど設定がイマイチ解らなかったが...
  • これ を使うといけるようだ

参考


とりあえず試す

インストール

cd /usr/share/elasticsearch
sudo bin/plugin -install elasticsearch/elasticsearch-cloud-aws/2.0.0.RC1

elasticsearch.yml の設定

/etc/elasticsearch/elasticsearch.yml に S3 への接続に必要なアクセスキーとシークレットキーを設定する。

cloud:
    aws:
        access_key: AKxxxxxxxxxxxxxxxxxx
        secret_key: yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy

設定後、念のために elasticsearch を再起動する。

リポジトリの登録

先ほどのローカルホストにリポジトリを登録したのと同じようにリポジトリを登録する。

curl -XPUT 'http://localhost:9200/_snapshot/my_s3_repository' -d '{
    "type": "s3",
    "settings": {
        "bucket": "elasticsearch-snapshot",
        "region": "ap-northeast-1"
    }
}'

ローカルホストの時と異なるのが typeS3 になっている点、bucketregion の指定が必要となる。正常に登録出来ると以下のように出力される。

{"acknowledged":true}

スナップショット

後は前回と同じようにスナップショットを取得する。

curl -XPUT localhost:9200/_snapshot/my_s3_repository/snapshot_20140204

正常に終了すると以下のようなレスポンスが出力される。

{"accepted":true}

こわごわ S3 のバケットを確認すると...

f:id:inokara:20140204024540p:plain

おお、まじかよ...素晴らし。aws-cli でも確認してみる。

aws s3api list-objects --bucket elasticsearch-snapshot | jq '.Contents[]|.Key'

以下のように出力れる。

"index"
"indices/test01/0/__0"
"indices/test01/0/snapshot-snapshot_20140204"
"indices/test01/1/__0"
"indices/test01/1/snapshot-snapshot_20140204"
"indices/test01/2/__0"
"indices/test01/2/__1"
"indices/test01/2/__2"
"indices/test01/2/__3"
"indices/test01/2/snapshot-snapshot_20140204"
"indices/test01/3/__0"
"indices/test01/3/__1"
"indices/test01/3/__2"
"indices/test01/3/__3"
"indices/test01/3/snapshot-snapshot_20140204"
"indices/test01/4/__0"
"indices/test01/4/snapshot-snapshot_20140204"
"indices/test01/snapshot-snapshot_20140204"
"metadata-snapshot_20140204"
"snapshot-snapshot_20140204"

せっかくなのでレストア

前回と同じデータをレストア!

curl -XPOST localhost:9200/_snapshot/my_s3_repository/snapshot_20140204/_restore

念のために確認!

curl -X GET localhost:9200/test01/hogehuga/_search?pretty

以下の通りレストアされている。

{
  "took" : 11,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "failed" : 0
  },
  "hits" : {
    "total" : 2,
    "max_score" : 1.0,
    "hits" : [ {
      "_index" : "test01",
      "_type" : "hogehuga",
      "_id" : "1",
      "_score" : 1.0, "_source" : {"name":"MasaharuFukuyama","email" :"masha@tfm.com","age":45}
    }, {
      "_index" : "test01",
      "_type" : "hogehuga",
      "_id" : "2",
      "_score" : 1.0, "_source" : {"name":"YoheiKawahara","email" :"hage@tfm.com","age":38}
    } ]
  }
}

この興奮を生でお伝え出来ないのが非常に残念!


とりあえず

  • elasticsearch 1.0.0 からはバックアップ(スナップショット)とレストアは使い易くなったと思われる(今までこれらを本気でやった事が無かったのであくまでも推測)
  • 但し、Amazon S3 との連携はプラグインが必要となるので注意する
  • ただ、プラグインのインストールや設定は鬼のように簡単