记录如何创建es仓库快照,结合crontab定时任务备份es数据

#1. es配置仓库路径 elasticsearch.yaml文件配置,略

#2. 创建仓库 POST _snapshot/backup_xsw { "type": "fs", "settings": { "location": "/usr/share/elasticsearch/es_bak/backup_xsw", "max_snapshot_bytes_per_sec" : "100mb", "max_restore_bytes_per_sec" : "100mb", "compress": true } } #type:支持多种存储形式,这里只演示共享文件系统,其他形式请参看官方文档:https://www.elastic.co/guide/en/elasticsearch/reference/7.13/snapshots-register-repository.html#snapshots-repository-plugins #settings.location:仓库目录 #settings.max_snapshot_bytes_per_sec:最大备份速度 #settings.max_restore_bytes_per_sec:最大还原速度 #settings.compress:是否压缩 #3. 验证仓库

验证仓库在各节点是否注册成功

POST _snapshot/backup_xsw/_verify

查看仓库信息

GET _snapshot/backup_xsw

支持正则

GET /_snapshot/repo*,backup

删除仓库

DELETE _snapshot/backup_xsw #4. 查看索引

查看索引

GET /_cat/indices?v&pretty #5. 备份快照

开始备份

PUT _snapshot/backup_xsw/snapshot-01?wait_for_completion=false { "indices": "index1,index2,index3,index4", "ignore_unavailable": true, "include_global_state": false, "metadata": { "taken_by": "xsw.bie", "taken_because": "backup test" } }

#indices:备份指定的索引(index)和数据流(data stream),格式"data_stream_1,index_1,index_2"。 #ignore_unavailable:将其设置为 true 将导致在快照创建过程中忽略不存在的数据流和索引。

默认情况下,如果未设置 ignore_unavailable 选项且缺少数据流或索引,快照请求将失败。

#include_global_state:集群全局状态,设置为false将不备份。如果备份的数据包含data stream,建议将其打开。 #metadata:任意添加的数据,相当于备注。

备份进度

当wait_for_completion=false时不会等待备份完成

GET /_snapshot/backup_xsw/snapshot-01/_status

查看所有备份

GET /_snapshot/backup_xsw/_all

删除一个快照

DELETE /_snapshot/document_text_info_backup/snapshot-223 #6. 还原快照 POST /_snapshot/document_text_info_backup/snapshot-02/_restore { "indices": "document_text_info", "ignore_unavailable": true, "include_global_state": false,
"include_aliases": false }

查看还原进度

GET _cat/recovery/document_text_info GET _cat/recovery?v #7. 配置crontab任务

阿里云国内75折 回扣 微信号:monov8
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6