Elasticsearch

Elasticsearch index backup(AWS S3 사용)

babbeolicoding 2023. 5. 16. 21:41

1. Elasticsearch config 수정

  - jvm.options

  - elasticsearch.yml

각 config 위치에 아래 값 추가

- vim config/jvm.options 
  => Des.allow_insecure_settings=true
    
- vim config/elasticsearch.yml
  => network.host: 0.0.0.0

 

2. S3 플러그인 설치(elasticsearch 재시작 필요)

#elasticbsearch 설치된 경로에서 실행
/usr/share/elasticsearch/bin/elasticsearch-plugin install repository-s3

#elasticsearch s3 플러그인 삭제
/usr/share/elasticsearch/bin/elasticsearch-plugin remove repository-s3

 

3. S3 백업 폴더 지정하기

curl --user '{user}:{password}' --header "content-type: application/JSON" -XPUT 'http://localhost:9200/_snapshot/{snapshot_name}?pretty' -d '{
  "type":"s3",
  "settings":{
    "access_key":"{aws_access_key}",
    "secret_key":"{aws_secret_key}",
    "bucket":"{bucket_name}",
    "base_path":"{bucket_path}",
    "region":"{region}",
    "compress": true
  }
}'
   
- localhost:9200/_snapshot/${name} : name은 스냅샵 이름
- bucket : S3 버킷이름
- base_path : S3 경로
- region : 리전이름
- access_key : AWS 접속 가능한 키
- secret_key :  AWS 접속 가능한 키

 

4. S3 백업하기

curl --user '{user}:{password}' --header "content-type: application/JSON"  -XPUT 'localhost:9200/_snapshot/{snapshot_name}/{backup_key}?pretty=true&wait_for_completion=true' -d '{
 	"indices": "{index명}",
 	"ignore_unavailable": true,
 	"include_global_state": false
}'

- wait_for_completion : 작업이 완료될때까지 기다림
- ignore_unavailable : index를 이용하지 못할때 그냥 ignore하고 계속 진행 (true)
- include_global_state : snapshot에 cluster global status 저장되는거 방지(false)
   전역 상태에는 클러스터 상태, 매핑, 샤드 할당 등이 포함
- localhost:9200/_snapshot/${name}/${backup_key} : name은 스냅샷 이름, backup_key는 복구할때 키기반으로 복구.
- indices : 백업 index 지정

 

5. 백업확인

#백업 이름 리스트 확인
curl --user '{user}:{password}' -XGET 'http://localhost:9200/_snapshot?pretty'
#백업 키 리스트 확인
curl --user '{user}:{password}' -XGET 'http://localhost:9200/_snapshot/{snapshot_name}/_all?pretty'