14.4.1.4. 备份

14.4.1.4.1. 参考链接

14.4.1.4.2. Shared file system repository

使用共享存储必须配置repo.path,请修改配置文件:elasticsearch.yml,添加如下代码:

path.repo: ["/mount/bak"]

配置完后,所有节点必须重启,才能创建备份仓库。

14.4.1.4.3. 创建配置仓库

curl -X PUT "localhost:9200/_snapshot/my_repository?pretty" -H 'Content-Type: application/json' -d'
{
    "type": "fs",
    "settings": {
        "location": "/mount/bak/my_backup_location"
    }
}
'

14.4.1.4.4. 查看已经创建的仓库

curl -X GET "localhost:9200/_snapshot?pretty"
curl -X GET "localhost:9200/_snapshot/_all?pretty"

14.4.1.4.5. 删除备份仓库

curl -X DELETE "localhost:9200/_snapshot/my_repository?pretty"

14.4.1.4.6. 创建备份

curl -X PUT "localhost:9200/_snapshot/my_repository/snapshot_1?wait_for_completion=true&pretty"

日志:

[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]

接口返回:

{
    "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
        }
    }
}

查看备份目录的内容:

$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

14.4.1.4.7. 恢复

curl -X POST "localhost:9200/_snapshot/my_backup/snapshot_1/_restore?pretty"