es的备份和恢复是非常方便的
这里就给大家演示下
我es的index 如下
查看index的mapping
GET test_customer1*/_mapping
{
"test_customer1": {
"mappings": {
"customer1": {
"properties": {
"age": {
"type": "long"
},
"createTime": {
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss"
},
"firstName": {
"type": "keyword"
},
"lastName": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
}
}
}
}
查看index里的数据
GET test_customer1*/_search
{
"query": {"match_all": {}}
}
结果如下
{
"took": 0,
"timed_out": false,
"_shards": {
"total": 2,
"successful": 2,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 2,
"max_score": 1,
"hits": [
{
"_index": "test_customer1",
"_type": "customer1",
"_id": "IySNm2oBvow2ILpBBmvX",
"_score": 1,
"_source": {
"id": null,
"firstName": "river-test1",
"lastName": "007",
"valid": null,
"age": 12,
"des": null,
"createTime": "2019-05-09 15:44:31"
}
},
{
"_index": "test_customer1",
"_type": "customer1",
"_id": "JCSQm2oBvow2ILpBSWsO",
"_score": 1,
"_source": {
"id": null,
"firstName": "river-test1",
"lastName": "007",
"valid": null,
"age": 12,
"des": null,
"createTime": "2019-05-09 15:48:05"
}
}
]
}
}
配置备份的目录
创建目录 backup 并配置到es的配置文件中
elasticsearch.yml 追加如下配置:
path.repo: [ "D:\\my-program\\elasticsearch-6.3.2\\backup" ]
重新启动es
注册备份的仓库 registering a backup repository
PUT _snapshot/my_backup
{
"type": "fs",
"settings": {
"location": "D:\\my-program\\elasticsearch-6.3.2\\backup",
"compress": true
}
}
备份index 内容
PUT _snapshot/my_backup/snapshot_3
{
"indices": "test_customer1*"
}
删除index
DELETE /test_customer1*
恢复备份数据
POST _snapshot/my_backup/snapshot_3/_restore
这时候查看index 发现 数据和mapping都恢复过来了
调用之前的查看方法,数据是一致的
查看备份仓库
GET _snapshot/my_backup/_all?pretty
删除备份仓库
DELETE _snapshot/my_backup/snapshot_3
参考地址
https://z0z0.me/how-to-create-snapshot-and-restore-snapshot-with-elasticsearch/
https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-snapshots.html#_repository_verification
最近在看一拳超人
image.png
网友评论