简化的步骤是:
- 定义存储在哪里(注册仓库)
- 把数据存储进去(创建快照)
- 从备份中恢复数据(从快照中还原)
前期准备
ES 安装
从官网下载linux源码包 https://www.elastic.co/downloads/elasticsearch
curl -L -O https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.9.2-linux-x86_64.tar.gz
tar -xzvf elasticsearch-7.9.2-linux-x86_64.tar.gz
cd elasticsearch-7.9.2
修改配置文件 config/elasticsearch.yml 添加
path.repo: ["/hadoop/backup"]
这个目录要提前创建,并且ES 用户有写权限。
然后启动服务
./bin/elasticsearch
提供要备份的索引
Create index
curl -XPUT 'localhost:9200/customer?pretty'
Create documents
for i in {1..100};
do
curl -s -X POST "localhost:9200/customer/_doc/" -H 'Content-Type: application/json' -d"
{
\"id\": ${i},
\"num\": ${i},
\"name\": \"John Doe\"
}"
done
Check
$ curl 'localhost:9200/_cat/indices?v'
health status index uuid pri rep docs.count docs.deleted store.size pri.store.size
yellow open customer MTqBTUhGTyqajUGDUCJj_g 1 1 100 0 17.7kb 17.7kb
注册仓库
curl -X PUT "localhost:9200/_snapshot/my_backup?pretty" -H 'Content-Type: application/json' -d'
{
"type": "fs",
"settings": {
"location": "/hadoop/backup"
}
}
'
创建快照
curl -X PUT "localhost:9200/_snapshot/my_backup/snapshot_1?wait_for_completion=true&pretty"
其它相关命令
curl -X GET "localhost:9200/_snapshot/my_backup/*?pretty"
curl -X GET "localhost:9200/_snapshot/my_backup/snapshot_1/_status?pretty"
curl -X DELETE "localhost:9200/_snapshot/my_backup/snapshot_1?pretty"
恢复
delete the index
curl -XDELETE 'localhost:9200/customer'
restore
curl -X POST "localhost:9200/_snapshot/my_backup/snapshot_1/_restore?pretty"
check again
$ curl 'localhost:9200/_cat/indices?v'
health status index uuid pri rep docs.count docs.deleted store.size pri.store.size
yellow open customer so8ALpCSTe2_loc4hOdtpg 1 1 100 0 18kb 18kb
网友评论