备份 ======== 参考链接 -------------------------------- * 准备 https://www.elastic.co/guide/en/elasticsearch/reference/current/snapshots-register-repository.html * 备份 https://www.elastic.co/guide/en/elasticsearch/reference/current/snapshots-take-snapshot.html * 恢复 https://www.elastic.co/guide/en/elasticsearch/reference/current/snapshots-restore-snapshot.html * 备份你的集群(中文) https://www.elastic.co/guide/cn/elasticsearch/guide/current/backing-up-your-cluster.html Shared file system repository -------------------------------- 使用共享存储必须配置repo.path,请修改配置文件:elasticsearch.yml,添加如下代码: .. code-block:: yaml path.repo: ["/mount/bak"] 配置完后,所有节点必须重启,才能创建备份仓库。 创建配置仓库 -------------------------------- .. code-block:: bash curl -X PUT "localhost:9200/_snapshot/my_repository?pretty" -H 'Content-Type: application/json' -d' { "type": "fs", "settings": { "location": "/mount/bak/my_backup_location" } } ' 查看已经创建的仓库 -------------------------------- .. code-block:: bash curl -X GET "localhost:9200/_snapshot?pretty" .. code-block:: bash curl -X GET "localhost:9200/_snapshot/_all?pretty" 删除备份仓库 -------------------------------- .. code-block:: bash curl -X DELETE "localhost:9200/_snapshot/my_repository?pretty" 创建备份 -------------------------------- .. code-block:: bash curl -X PUT "localhost:9200/_snapshot/my_repository/snapshot_1?wait_for_completion=true&pretty" 日志: .. code-block:: bash [2020-08-26T16:28:35,966][INFO ][o.e.s.SnapshotsService ] [JhlpWg_] snapshot [my_repository:snapshot_1/AfjZrgYfSxiYU-MZovC3HQ] started [2020-08-26T16:28:36,353][INFO ][o.e.s.SnapshotsService ] [JhlpWg_] snapshot [my_repository:snapshot_1/AfjZrgYfSxiYU-MZovC3HQ] completed with state [SUCCESS] 接口返回: .. code-block:: json { "snapshot" : { "snapshot" : "snapshot_1", "uuid" : "AfjZrgYfSxiYU-MZovC3HQ", "version_id" : 6040399, "version" : "6.4.3", "indices" : [ "cmccyn_doc_bomc_202004", "cmccyn_file_bomc_202006", "cmccyn_doc_oa_201912", "cmccyn_doc_eip_202006", "cmccyn_doc_wiki_post_201910", "cmccyn_doc_oa_202004", "twitter", "cmccyn_doc_eip_202004", "cmccyn_doc_oa_202001", "cmccyn_doc_oa_202003", "cmccyn_doc_oa_201911", "cmccyn_doc_eip_202005", "cmccyn_doc_bomc_202005", "new_twitter", "cmccyn_doc_eip_201906" ], "include_global_state" : true, "state" : "SUCCESS", "start_time" : "2020-08-26T08:28:35.917Z", "start_time_in_millis" : 1598430515917, "end_time" : "2020-08-26T08:28:36.347Z", "end_time_in_millis" : 1598430516347, "duration_in_millis" : 430, "failures" : [ ], "shards" : { "total" : 19, "failed" : 0, "successful" : 19 } } } 查看备份目录的内容: .. code-block:: bash $ls -lh total 64 -rw-r--r-- 1 kyle staff 1.5K Aug 26 16:28 index-0 -rw-r--r-- 1 kyle staff 8B Aug 26 16:28 index.latest drwxr-xr-x 17 kyle staff 544B Aug 26 16:28 indices -rw-r--r-- 1 kyle staff 19K Aug 26 16:28 meta-AfjZrgYfSxiYU-MZovC3HQ.dat -rw-r--r-- 1 kyle staff 549B Aug 26 16:28 snap-AfjZrgYfSxiYU-MZovC3HQ.dat 恢复 -------------------------------- .. code-block:: bash curl -X POST "localhost:9200/_snapshot/my_backup/snapshot_1/_restore?pretty"