14.4.1.7. snapshot

elasticsearch集群中要使用snapshot备份数据的快照,需要用到共享存储。 假设有3个节点,那么三个节点要挂在相同的共享存储,并且mount点要一样。

1sudo mkdir share2lxc
2sudo chmod -R 777 share2lxc/
3lxc config device add elasticsearch-cluster-node-1 mydisk disk source=/vm/share2lxc path=/mnt/data
4lxc config device add elasticsearch-cluster-node-2 mydisk disk source=/vm/share2lxc path=/mnt/data
5lxc config device add elasticsearch-cluster-node-3 mydisk disk source=/vm/share2lxc path=/mnt/data
# 创建snapshot仓库
curl -X PUT "http://10.196.126.18:9200/_snapshot/my_backup" -H 'Content-Type: application/json' -d'
{
    "type": "fs",
    "settings": {
        "location": "/mnt/data/es-snapshot-repo",
        "compress": true
    }
}
'

# 查看集群中注册了那些仓库
curl http://10.196.126.38:9200/_snapshot

# 删除snapshot仓库
curl -X DELETE "http://10.196.126.18:9200/_snapshot/my_backup"

# 查看有那些snapshot
curl "HTTP://10.196.126.193:9200/_snapshot/my_backup/_all?pretty"
{
    "snapshots": [
        {
            "snapshot": "snapshot_1",
            "uuid": "wU3WpvnnR9SOpShRMsnQww",
            "version_id": 6040399,
            "version": "6.4.3", # 版本
            "indices": [ # 索引列表
                "knowledgeindex",
                "onequestionindex",
                "trainmanualindex",
                "knowattachindex"
            ],
            "include_global_state": true,
            "state": "SUCCESS",
            "start_time": "2024-12-13T16:34:25.287Z",
            "start_time_in_millis": 1734107665287,
            "end_time": "2024-12-13T16:34:34.473Z",
            "end_time_in_millis": 1734107674473,
            "duration_in_millis": 9186,
            "failures": [],
            "shards": {
                "total": 20,
                "failed": 0,
                "successful": 20
            }
        }
    ]
}

# 恢复快照
curl -X POST "10.196.126.193:9200/_snapshot/my_backup/snapshot_1/_restore?pretty"

# 查看索引是否恢复进去了
curl http://10.196.126.38:9200/_cat/indices?v&pretty
health status index            uuid                   pri rep docs.count docs.deleted store.size pri.store.size
green  open   onequestionindex 7WYSLyk3TJGrP2QcTHIFYw   5   1        722           99      2.3mb          1.1mb
green  open   trainmanualindex bxseCPEtTe6QAj2CKnBFfA   5   1       4840          100      4.3mb          2.1mb
green  open   knowattachindex  HdEpQFkQQdKGsg6iUslZSg   5   1       2787           33      1.8mb        923.1kb
green  open   knowledgeindex   XbB_kFWbRGG6Kq1kRZI-9g   5   1      53599        19417    440.5mb        220.2mb