es備份與恢復 on windows local file system

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

最近在看一拳超人


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章