elasticsearch 快照迁移

1. 启用es
并且配置:- path.repo=/usr/share/elasticsearch/backup

2. 创建快照仓库
curl -X PUT "localhost:9200/_snapshot/baolin?pretty" -H 'Content-Type: application/json' -d'
{
"type": "fs",
"settings": {
"location": "baolin",
"compress": true
}
}
'

3. 查看仓库状态
curl -X POST "localhost:9600/_snapshot/baolin/_verify?pretty"

4. 创建快照策略(每天一个快照),只能是UTC,不支持其他时间地区
curl -X PUT "localhost:9200/_slm/policy/baolin-day?pretty" -H 'Content-Type: application/json' -d'
{
"schedule": "0 30 16 * * ?",
"name": "",
"repository": "baolin",
"config": {
"indices": "baolin*",
"include_global_state": true
},
"retention": {
"expire_after": "30d",
"min_count": 5,
"max_count": 50
}
}
'
保存30天,快照数量5 ~ 50个

5. 查看快照策略
curl -X GET "localhost:9200/_slm/policy/baolin-day?pretty"

# 查看所有的仓库
curl -H "Content-Type: application/json" -X GET http://localhost:9200/_snapshot/_all
# 查看某一个具体的仓库的快照情况
curl -H "Content-Type: application/json" -X GET 'http://localhost:9200/_snapshot/baolin/_all?pretty‘
# 列出所有当前正在运行的快照以及显示他们的详细状态信息
GET /_snapshot/_status?pretty
# 列出所有当前正在运行的快照以及显示他们的详细状态信息
GET /_snapshot/baolin/_status?pretty
# 查看指定快照的详细状态信息即使不是正在运行
GET /_snapshot/baolin/snapshot_2/_status?pretty
#删除某一个快照
DELETE /_snapshot/baolin/snapshot_2

#手动备份快照,不实用slm的情况下
curl -H "Content-Type: application/json" -XPUT 'http://localhost:9200/_snapshot/baolin/baolin_20220107?pretty&wait_for_completion=true'

6. 执行策略
curl -X POST "localhost:9200/_slm/policy/baolin-day/_execute?pretty"

7. 快照恢复(顺序不能错)

a. 启用新集群
b. 创建仓库
curl -X PUT "localhost:9200/_snapshot/baolin?pretty" -H 'Content-Type: application/json' -d'
{
"type": "fs",
"settings": {
"location": "baolin",
"compress": true
}
}
'
c. 把快照移动到当前集群仓库位置
cp -rf ../es/data/elasticsearch/backup/baolin/* data/elasticsearch/backup/baolin/

d. 在新集群中查看快照
curl -X GET "localhost:9600/_snapshot/baolin/_all?pretty" -H 'Content-Type: application/json'

f. 恢复快照
curl -X POST "localhost:9600/_snapshot/baolin/[快照名字]/_restore?pretty" -H 'Content-Type: application/json' -d'
{
"indices": "baolin*"
}
'

curl -X GET "localhost:9600/_snapshot/baolin/baolin-day-2022.01.07-o0zryaxtq1mzlvxeqnwm4q/_restore?pretty" -H 'Content-Type: application/json' -d'
{
"indices": "baolin*"
}
'

此条目发表在es分类目录。将固定链接加入收藏夹。