# 创建快照仓库,需要先在elasticsearch.yml中配置path.repo: /usr/share/elasticsearch/data
create_registry() {
curl -H "Content-Type: application/json" -XPUT http://192.168.1.62:30920/_snapshot/2021-12-07 -d '
{
"type": "fs",
"settings": {
"location": "/usr/share/elasticsearch/data/2021-12-07",
"max_snapshot_bytes_per_sec": "50mb",
"max_restore_bytes_per_sec": "50mb"
}
}'
}

# 需要操作的索引对象放到数组中
indexs=(operlog_process operlog_security .signals_settings operlog_customer)

# 备份快照
backup() {
curl -H "Content-Type: application/json" -XPUT http://192.168.1.62:9200/_snapshot/2021-12-07/$1?wait_for_completion=true -d '
{
"indices": "'$1'"
}'
}

#删除索引
delete() {
curl -XDELETE http://192.168.1.62:30920/$1
}

# 恢复索引
restore() {
curl -XPOST http://192.168.1.62:30920/_snapshot/2021-12-07/$1/_restore
}

# for循环进行以上其中一个模块
for index in ${indexs[@]}
do
restore $index
done