1 部署NFS
root@ubuntu2204-98:~
root@ubuntu2204-98:~
root@ubuntu2204-98:~
root@ubuntu2204-98:~
/root/nfs *(rw,sync,no_root_squash,no_subtree_check,insecure)
root@ubuntu2204-98:~
root@ubuntu2204-98:~
root@ubuntu2204test99:~
root@ubuntu2204test99:~
root@ubuntu2204test99:~
root@ubuntu2204test99:~
192.168.1.98:/root/nfs nfs4 48G 22G 24G 48% /root/nfs98
root@ubuntu2204test99:~
192.168.1.98:/root/nfs /root/nfs98 nfs defaults 0 0
2 Elasticsearch7设置备份路径
root@ubuntu2204test99:~
path.repo: /usr/share/elasticsearch/nfs
volumes:
- /root/nfs98:/usr/share/elasticsearch/nfs
3 创建备份仓库
# 创建备份仓库
root@ubuntu2204test99:~/elkf# curl -XPOST 'http://192.168.1.99:9201/_snapshot/_esbackup' -H 'Content-Type:application/json' -u 'elastic:123456' -d '{
"type":"fs",
"settings":{"compress":"true",
"location":"/usr/share/elasticsearch/nfs"
}
}'
# 查看仓库
root@ubuntu2204test99:~/elkf# curl -XGET 'http:
-H 'Content-Type: application/json' \
-u 'elastic:123456'
{"_esbackup":{"type":"fs","settings":{"compress":"true","location":"/usr/share/elasticsearch/nfs"}}}
4 备份索引到仓库中
root@ubuntu2204test99:~/elkf
-H 'Content-Type: application/json' \
-u 'elastic:123456' \
-d '{
"indices": "*,-.kibana*",
"ignore_unavailable": true,
"include_global_state": false
}'
root@ubuntu2204test99:~
total 100
drwxrwxrwx 3 root root 4096 Nov 3 03:21 ./
drwx------ 16 root root 4096 Nov 3 02:56 ../
-rw-rw-r-- 1 wolf root 11105 Nov 3 03:21 index-0
-rw-rw-r-- 1 wolf root 8 Nov 3 03:21 index.latest
drwxrwxr-x 39 wolf root 4096 Nov 3 03:21 indices/
-rw-rw-r-- 1 wolf root 68339 Nov 3 03:21 meta-Ta9qZ2WzTwSo7h6G2-4VNw.dat
-rw-rw-r-- 1 wolf root 1165 Nov 3 03:21 snap-Ta9qZ2WzTwSo7h6G2-4VNw.dat
5 恢复备份
root@ubuntu2204test98:~
path.repo: /usr/share/elasticsearch/nfs
volumes:
- /root/nfs98:/usr/share/elasticsearch/nfs
root@ubuntu2204test98:~/elkf
"type":"fs",
"settings":{"compress":"true",
"location":"/usr/share/elasticsearch/nfs"
}
}'
# 查看备份目录中的内容
root@ubuntu2204test98:~/elkf# curl -XGET 192.168.1.99:9201/_snapshot/_esbackup/_all \
-H 'Content-Type: application/json' \
-u 'elastic:123456'
# 恢复仓库中的备份
root@ubuntu2204test98:~/elkf# curl -XPOST 'http://192.168.1.98:9201/_snapshot/_esbackup/snapshot_1/_restore' \
-u 'elastic:123456' \
-H 'Content-Type: application/json' \
-d '{
"indices": "*",
"ignore_unavailable": true,
"include_global_state": false
}'
6 常用命令
root@ubuntu2204test99:~/elkf
stage字段含义:
INITIALIZING:检查分片状态是否符合备份条件。这通常非常快。
TARTED:正在传输到存储库。
FINALIZING:数据传输完成,分片现在正在发送快照元数据。
DONE:快照成功
FAILED:快照遇到错误。
root@ubuntu2204test99:~/elkf
root@ubuntu2204test99:~/elkf
root@ubuntu2204test99:~
root@ubuntu2204test99:~/elkf
root@ubuntu2204test99:~/elkf
-H 'Content-Type:application/json' \
-u 'elastic:123456' \
-d '{"indices": "filebeat-javalog-mutli-2025.10.20"}'
默认恢复该快照中的所有索引,默认异步,可使用wait_for_completion=true,改为同步
POST _snapshot/esbackup/snapshot_1/_restore
