Elasticsearch数据迁移需要一个所有服务器都能访问到的目录,如果购买了存储服务直接挂载可以使用,如果没有需要搭建一个NFS服务;
我这边因为有购买的nas服务,所以直接使用:/data/storage/elasticsearch
修改elasticsearch.yml
添加:path.repo: /data/storage/elasticsearch
备份
1、创建快照仓库
PUT http://192.168.140.158:9200/_snapshot/vodjk_repo
{
"type": "fs",
"settings": {
"location": "/data/storage/elasticsearch/vodjk",
"compress": true
}
}
# 或者直接在服务器上执行
curl -H "Content-Type: application/json" -XPUT 'http://192.168.140.158:9200/_snapshot/vodjk_repo' -d '
{
"type": "fs",
"settings": {
"location": "/data/storage/elasticsearch/vodjk",
"compress": true
}
}'
vodjk_repo 是快照仓库的名称,可以自定义
type 的值指定为fs
location 指定仓库的路径
compress 表示开启压缩
2、创建索引的快照
# 备份所有索引
PUT http://192.168.140.158:9200/_snapshot/vodjk_repo/newask_snapshot
# 如果想等待返回结果 添加wait_for_completion=true 参数
PUT http://192.168.140.158:9200/_snapshot/vodjk_repo/newask_snapshot?wait_for_completion=true
# 或者直接在服务器上执行
curl -H "Content-Type:application/json" -XPUT 'http://192.168.140.158:9200/_snapshot/vodjk_repo/newask_snapshot' -d '
{
"indices": "newask_index,newask"
}'
# 还可以添加其他参数
# 忽略不可用的索引
"ignore_unavailable": true
# 公共部分
"include_global_state": false
2、查看
# 查看仓库
GET http://192.168.140.158:9200/_snapshot/
# 查看索引信息
GET http://192.168.140.158:9200/_snapshot/vodjk_repo/_all
# 查看查看索引快照信息
GET http://192.168.140.158:9200/_snapshot/vodjk_repo/newask_snapshot
3、删除
# 删除制定快照
DELETE http://192.168.140.158:9200/_snapshot/vodjk_repo/newask_snapshot
# 删除仓库
DELETE http://192.168.140.158:9200/_snapshot/vodjk_repo