elasticsearch-curator 实现索引删除、索引备份snapshot、删除snapshot

官方地址:https://www.elastic.co/guide/en/elasticsearch/client/curator/current/index.html
特性介绍:https://www.elastic.co/guide/en/elasticsearch/client/curator/current/about-features.html

1.下载安装

wget https://packages.elastic.co/curator/5/centos/7/Packages/elasticsearch-curator-5.6.0-1.x86_64.rpm
yum install elasticsearch-curator-5.6.0-1.x86_64.rpm
#进入elasticsearch-curator,curator运行需两个配置文件config.yml(用于连接ES集群配置)、action.yml(用于配置要执行的操作),文件名称可以随意命名
touch action.yml
touch config.yml

2.配置action.yml & config.yml

以下示例:索引删除、索引备份snapshot、删除snapshot

actions:
  1:
    action: delete_indices
    description: >-
      Delete indices older than 7 days (based on index name), for testjiwei-
      prefixed indices. Ignore the error if the filter does not result in an
      actionable list of indices (ignore_empty_list) and exit cleanly.
    options:
       ignore_empty_list: True
      disable_action: False
      timeout_override: 300
      continue_if_exception: False
    filters:
    - filtertype: pattern
      kind: prefix
      value: testjiwei-
    - filtertype: age
      source: name
      direction: older
      timestring: '%Y.%m.%d'
      unit: days
      unit_count: 7
 2:
    action: snapshot
    description: >-
      Snapshot selected indices to 'repository' with the snapshot name or name
    options:
      repository: dev_data
      name:
      #name: ''  #自命名的snapshot测试有点问题,name空时默认已curator_时间戳自动生成
      wait_for_completion: True
      max_wait: 3600
      wait_interval: 10
      # true 不执行
      disable_action: False 
    filters:
    - filtertype: pattern
      kind: regex
      value: '^(ua_paper|course_exercise_extra|playback_info)'
 3:
    action: delete_snapshots
    description: >-
      Delete selected snapshots from 'repository'
    options:
      repository: dev_data     
      ignore_empty_list: True
      disable_action: False
      timeout_override: 3000
      continue_if_exception: False
    filters:
    - filtertype: pattern
      kind: prefix
      value: curator-
    - filtertype: age
      source: creation_date
      direction: older
      unit: days
      unit_count: 2  #删除2天以前的,0删除当天的

3.运行

# --dry-run 模拟执行,实际不做任何操作,可用于测试索引匹配是否正确
curator --config /opt/elasticsearch-curator/config.yml --dry-run /opt/elasticsearch-curator/action.yml
# 真实执行
curator --config /opt/elasticsearch-curator/config.yml /opt/elasticsearch-curator/action.yml

你可能感兴趣的:(elasticsearch)