snapshot的方式对es进行备份 (备份到磁盘)
创建共享目录
使用以下命令安装epel:yum -y install epel-release
键入以下命令刷新repo:yum repolist
安装sshfs: yum install sshfs
选取一个节点作为共享目录的存放节点, 其他节点可以免密登陆到该节点
1.创建共享目录/mnt/nvme
2.每个节点创建目录作为快照仓库的根目录/snap/back
3.挂载共享目录 sshfs <host>:/mnt/nvme /snap/back -o allow_other -o nonempty
或者sshfs <host>:mnt/nvme /snap/back -o allow_other -o nonempty
(两个的区别在于 <host>: 有没有 / ,应该是要加/表示根目录,但在操作过程中出现问题,加/操作失败,不加/操作成功,很奇怪)
nonempty: 忽略文件夹是否为空
allow_other: 允许其他用户访问
修改配置文件
每个节点添加path.repo: <快照仓库的根目录>
重启
创建备份仓库
curl -XPUT 'http://<host:port>/_snapshot/<仓库名>' -d '{
"type": "fs",
"settings": {
"location": "/snap/back/compress_snapshot", (快照保存位置)
"compress": true
}
}'
查看仓库
curl -XGET 'http://<host:port>/_snapshot?pretty'
创建快照
curl -XPUT 'http://<host:port>/_snapshot/<仓库名>/<快照名>' -d '{
"indices": "<index>", (多个索引","分割, 所有索引不用指定此参数)
"ignore_unavailable": true,
"include_global_state": false
}'
查询快照
GET /_snapshot/<仓库名>/_all(查询所有)
GET /_snapshot/<仓库名>/<快照名>(查询指定快照, 多个","分割)
恢复快照
POST /_snapshot/<仓库名>/<快照名>/_restore
{
"indices": "<index>", (指定索引恢复,不指定就是所有)
"ignore_unavailable": true, (忽略恢复时异常索引)
"include_global_state": false, (是否存储全局转态信息, fasle代表有一个或几个失败, 不会导致整个任务失败)
"rename_pattern": "(.+)", (是否需要重命名索引)
"rename_replacement": "<new_index>" (替换后的索引名)
}
报错{"error":"Content-Type header [application/x-www-form-urlencoded] is not supported","status":406}
添加参数 -H "Content-Type: application/json"