먼저 저장소 경로를 등록한다. vi conf/elasticsearch.yml에서 다음을 추가한다. 


path.repo: ["/tmp/mnt"] 



파일 시스템 저장소를 등록한다.


curl -XPUT 'http://localhost:9200/_snapshot/es-backup' -d '{

"type": "fs",

"settings": {

"location": "/tmp/mnt/es-backup",

"compress": true

}

}'



만약 conf/elasticsearch.yml 파일에서 path.repo를 등록하지 않으면 다음 에러가 발생한다. 


{"error":{"root_cause":[{"type":"repository_exception","reason":"[es-backup] location [/tmp/es-backup] doesn't match any of the locations specified by path.repo because this setting is empty"}],"type":"repository_exception","reason":"[es-backup] failed to create repository","caused_by":{"type":"repository_exception","reason":"[es-backup] location [/tmp/es-backup] doesn't match any of the locations specified by path.repo because this setting is empty"}},"status":500}





snapshot 저장하기


$ curl -XPUT 'http://localhost:9200/_snapshot/es-backup/snapshot_1?wait_for_completion=true' -d '{

> "indices": "index_1,index_2",

> "ignore_unavailable": "true",

> "include_global_state": false

> }'

{"snapshot":{"snapshot":"snapshot_1","uuid":"gD2dYNYzQjevg3S6PbV0Fg","version_id":5030199,"version":"5.3.1","indices":[],"state":"SUCCESS","start_time":"2017-06-08T02:41:58.489Z","start_time_in_millis":1496889718489,"end_time":"2017-06-08T02:41:58.496Z","end_time_in_millis":1496889718496,"duration_in_millis":7,"failures":[],"shards":{"total":0,"failed":0,"successful":0}}}[/usr/local/elasticsearch-5.3.1/bin]





스냅샷 정보를 얻어오려면 다음 커맨드를 사용한다. 


curl -XGET 'http://localhost:9200/_snapshot/es-backup/snapshot_1'

{"snapshots":[{"snapshot":"snapshot_1","uuid":"gD2dYNYzQjevg3S6PbV0Fg","version_id":5030199,"version":"5.3.1","indices":[],"state":"SUCCESS","start_time":"2017-06-08T02:41:58.489Z","start_time_in_millis":1496889718489,"end_time":"2017-06-08T02:41:58.496Z","end_time_in_millis":1496889718496,"duration_in_millis":7,"failures":[],"shards":{"total":0,"failed":0,"successful":0}}]}





curl -XGET 'http://localhost:9200/_snapshot/es-backup/snapshot_1,snapshot_2'





curl -XGET 'http://localhost:9200/_snapshot/es-backup/_all'

'{"snapshots":[{"snapshot":"snapshot_1","uuid":"gD2dYNYzQjevg3S6PbV0Fg","version_id":5030199,"version":"5.3.1","indices":[],"state":"SUCCESS","start_time":"2017-06-08T02:41:58.489Z","start_time_in_millis":1496889718489,"end_time":"2017-06-08T02:41:58.496Z","end_time_in_millis":1496889718496,"duration_in_millis":7,"failures":[],"shards":{"total":0,"failed":0,"successful":0}}]}




스냅샷 삭제하는 방법은 다음과 같다. 


curl -XDELETE 'http://localhost:9200/_snapshot/es-backup/snapshot_1'



Posted by '김용환'
,