2025-02-17 10:58AM
2.在新服务器创建一个快照存储库
$ curl -X PUT "localhost:9200/_snapshot/social_data" -H 'Content-Type: application/json' -d '{
"type": "fs",
"settings": {
"compress": "true",
"location": "/opt/social_data_backup"
}
}'
{"acknowledged":true}
$ scp /opt/social_data_backup/ -r root@4xxxxx4:/opt/
4.增加 elasticsearch 用户对/opt/social_data_backup 目录具有读写权限
$ sudo chown -R elasticsearch:elasticsearch /opt/social_data/backup
$ sudo chmod -R 755 /opt/social_data_backup
5.配置 /etc/elasticsearch/elasticsearch.yml 文件,增加 path.repo
path.repo: ["/opt/social_data_backup"]
6. 重启 elasticsearch
$ sudo systemctl restart elasticsearch
7.开始导入数据,报错了:
原因: Elasticsearch 中已经存在一个同名的开放索引 social_data。(我之前创建了一个social_data快照存储库)
$ curl -X POST "localhost:9200/_snapshot/social_data/snapshot_1/_restore" -H 'Content-Type: application/json'
{"error":{"root_cause":[{"type":"snapshot_restore_exception","reason":"[social_data:snapshot_1/vl9we_DqTXS6a9AQA0D2Ag] cannot restore index [social_data] because an open index with same name already exists in the cluster. Either close or delete the existing index or restore the index under a different name by providing a rename pattern and replacement name"}],"type":"snapshot_restore_exception","reason":"[social_data:snapshot_1/vl9we_DqTXS6a9AQA0D2Ag] cannot restore index [social_data] because an open index with same name already exists in the cluster. Either close or delete the existing index or restore the index under a different name by providing a rename pattern and replacement name"},"status":500}root@iZj6c2scqrd12s0j7xolydZ:/opt/social_data_backup/indices/YNDl40h_Qkyp7tHGS9XhfA/0# curl -X POST "localhost:9200/social_data/_close"
{"acknowledged":true,"shards_acknowledged":true,"indices":{"social_data":{"closed":true}}}root@iZj6c2scqrd12s0j7xolydZ:/opt/social_data_backup/indices/YNDl40h_Qkyp7tHGS9XhfA/0#
8.关闭现有索引:
$ curl -X POST "localhost:9200/social_data/_close"
9. 再次尝试恢复快照:
$ curl -X POST "localhost:9200/_snapshot/social_data/snapshot_1/_restore" -H 'Content-Type: application/json'
{"accepted":true}
10. 检查恢复状态
$ curl -X GET "localhost:9200/_cat/recovery?v"
index shard time type stage source_host source_node target_host target_node repository snapshot files files_recovered files_percent files_total bytes bytes_recovered bytes_percent bytes_total translog_ops translog_ops_recovered translog_ops_percent
social_data 0 26.3s snapshot index n/a n/a 127.0.0.1 iZj6c2scqrd12s0j7xolydZ social_data snapshot_1 453 4 0.9% 453 357968141091 1051526949 0.3% 357968141091 0 0 100.0%
目前,只有 0.9%
的文件和 0.3%
的字节已被恢复,这表明恢复过程仍在进行中。
11.验证是否导入成功
确认快照的状态,确保它已成功恢复(应显示为 SUCCESS,
分片状态: 确保所有分片都已完成,且没有失败的分片)
root@iZj6c2scqrd12s0j7xolydZ:~# curl -X GET "localhost:9200/_snapshot/social_data/snapshot_1/_status?pretty"
{
"snapshots" : [
{
"snapshot" : "snapshot_1",
"repository" : "social_data",
"uuid" : "vl9we_DqTXS6a9AQA0D2Ag",
"state" : "SUCCESS",
"include_global_state" : false,
"shards_stats" : {
"initializing" : 0,
"started" : 0,
"finalizing" : 0,
"done" : 1,
"failed" : 0,
"total" : 1
},
"stats" : {
"incremental" : {
"file_count" : 453,
"size_in_bytes" : 357968141091
},
"total" : {
"file_count" : 453,
"size_in_bytes" : 357968141091
},
"start_time_in_millis" : 1739411133637,
"time_in_millis" : 11223252
},
"indices" : {
"social_data" : {
"shards_stats" : {
"initializing" : 0,
"started" : 0,
"finalizing" : 0,
"done" : 1,
"failed" : 0,
"total" : 1
},
"stats" : {
"incremental" : {
"file_count" : 453,
"size_in_bytes" : 357968141091
},
"total" : {
"file_count" : 453,
"size_in_bytes" : 357968141091
},
"start_time_in_millis" : 1739411133837,
"time_in_millis" : 11222251
},
"shards" : {
"0" : {
"stage" : "DONE",
"stats" : {
"incremental" : {
"file_count" : 453,
"size_in_bytes" : 357968141091
},
"total" : {
"file_count" : 453,
"size_in_bytes" : 357968141091
},
"start_time_in_millis" : 1739411133837,
"time_in_millis" : 11222251
}
}
}
}
}
}
]
}
12 检查索引状态(确认目标索引(例如 social_data
)在列表中,并且状态为 green
或 yellow
(表示可用))
$ curl -X GET "localhost:9200/_cat/indices?v"
health status index uuid pri rep docs.count docs.deleted store.size pri.store.size
yellow open social_data 6hluh9ViRf61mL9OZQBY8g 1 1 993084680 75058653 333.3gb 333.3gb
登录
请登录后再发表评论。
评论列表:
目前还没有人发表评论