备份和还原Fess索引文件

这是在Windows环境下使用Fess创建索引,并进行备份和恢复操作验证的记录。

    • 本記事では Fess + Elasticsearch が稼働中のローカルストレージに対してバックアップを作成

 

    記事中の curl コマンドは全て Windows 標準のコマンドプロンプトにて実行

环境 –

    • Windows10 Pro 64bit

 

    • Fess 13.9.3

 

    Elasticsearch 7.9.3

快照(备份)

Fess使用的数据以Elasticsearch索引的方式进行管理。关于索引备份的方法,Elasticsearch提供了快照功能。有关详细步骤和信息,请参考快照功能。

备份=快照

创建并指定存储库目录

创建一个名为C:\ elasticsearch-snapshot的文件夹来存储快照(备份)。
并在配置文件中添加以下内容。

path.repo: ["C:/elasticsearch-snapshot/"]

在进行设置之前,请确认仓库。

C:\>curl -XGET "http://localhost:9200/_snapshot?pretty"
{}

不需要进行注册。

创建存储库

请求在_snapshot API上创建elasticsearch-snapshot仓库。(仓库名称任意)

C:\>curl -H "Content-Type: application/json" -XPUT "http://localhost:9200/_snapshot/elasticsearch-snapshot?pretty" -d "{"type": "fs","settings": {"location": "/elasticsearch-snapshot","compress": true}}"
{
  "error" : {
    "root_cause" : [
      {
        "type" : "json_parse_exception",
        "reason" : "Unexpected character ('t' (code 116)): was expecting double-quote to start field name\n at [Source: (org.elasticsearch.common.bytes.AbstractBytesReference$MarkSupportingStreamInputWrapper); line: 1, column: 3]"
      }
    ],
    "type" : "json_parse_exception",
    "reason" : "Unexpected character ('t' (code 116)): was expecting double-quote to start field name\n at [Source: (org.elasticsearch.common.bytes.AbstractBytesReference$MarkSupportingStreamInputWrapper); line: 1, column: 3]"
  },
  "status" : 400
}

在Windows 10中,curl默认可用,但直接指定请求数据会导致错误。通过在外部json文件中定义请求数据来解决问题。在执行命令时,需要在json文件所在的目录中运行。

{
  "type": "fs",
  "settings": {
    "location": "/elasticsearch-snapshot",
    "compress": true
  }
}
C:\>curl -H "Content-Type: application/json" -XPUT "http://localhost:9200/_snapshot/elasticsearch-snapshot?pretty" -d @snapshot.json
{
  "acknowledged" : true
}

确认存储库(配置后)

C:\>curl -XGET "http://localhost:9200/_snapshot?pretty"
{
  "elasticsearch-snapshot" : {
    "type" : "fs",
    "settings" : {
      "compress" : "true",
      "location" : "/elasticsearch-snapshot"
    }
  }
}

删除存储库

如果需要删除的话。

C:\>curl -XDELETE "http://localhost:9200/_snapshot/elasticsearch-snapshot?pretty"
{
  "acknowledged" : true
}

获取快照

C:\>curl -XPUT "http://localhost:9200/_snapshot/elasticsearch-snapshot/test_snapshot?wait_for_completion=true"

当成功时,将生成以下文件存储库中。

C:\elasticsearch-snapshot
    ├── indices
    │    ├── hogehoge
    │    ├── fugafuga
    │    略
    │    └── piyopiyo
    ├── index.latest
    ├── index-0
    ├── meta-<uuid>.dat
    └── snap-<uuid>.dat

查看快照

C:\>curl -XGET "http://localhost:9200/_snapshot/elasticsearch-snapshot/test_snapshot?pretty"
{
  "snapshots" : [
    {
      "snapshot" : "test_snapshot",
      "uuid" : "hogehoge",
      "version_id" : 7090399,
      "version" : "7.9.3",
      "indices" : [
        ".fess_config.scheduled_job",
        ".fess_config.job_log",
        ".fess_config.failure_url",
        ".crawler.queue",
        ".fess_config.duplicate_host",
        ".fess_config.access_token",
        ".fess_config.label_type",
        ………
      ],
      "data_streams" : [ ],
      "include_global_state" : true,
      "state" : "SUCCESS",
      "start_time" : "2021-01-27T03:20:03.048Z",
      "start_time_in_millis" : 1611717603048,
      "end_time" : "2021-01-27T03:20:04.453Z",
      "end_time_in_millis" : 1611717604453,
      "duration_in_millis" : 1405,
      "failures" : [ ],
      "shards" : {
        "total" : 88,
        "failed" : 0,
        "successful" : 88
      }
    }
  ]
}

删除快照

如果要删除的话

C:\>curl -XDELETE "http://localhost:9200/_snapshot/elasticsearch-snapshot/test_snapshot?pretty"
{
  "acknowledged" : true
}

如果成功,存储库内将如下所示。

C:\elasticsearch-snapshot
    ├── indices
    ├── index.latest
    └── index-1

在indices文件夹内,每个索引文件都已被删除。是从index-0计数增加到 index-1了吗?

恢复备份

search1.png
search2.png

执行还原

C:\>curl -H "Content-Type: application/json" -XPOST "http://localhost:9200/_snapshot/elasticsearch-snapshot/test_snapshot/_restore?pretty"
{
  "error" : {
    "root_cause" : [
      {
        "type" : "snapshot_restore_exception",
        "reason" : "[elasticsearch-snapshot:test_snapshot/hogehoge] cannot restore index [.fess_config.related_content] because an open index with same name already exists in the cluster. Either close or delete the existing index or restore the index under a different name by providing a rename pattern and replacement name"
      }
    ],
    "type" : "snapshot_restore_exception",
    "reason" : "[elasticsearch-snapshot:test_snapshot/hogehoge] cannot restore index [.fess_config.related_content] because an open index with same name already exists in the cluster. Either close or delete the existing index or restore the index under a different name by providing a rename pattern and replacement name"
  },
  "status" : 500
}

由于某些索引正在使用中,我被责备无法进行恢复(可能)。

C:\>curl -XDELETE "http://localhost:9200/*?pretty"
{
  "acknowledged" : true
}

请自行负责,完全删除所有索引。
※请注意,由于不能确认“已删除的索引”是否可以从快照中恢复,所以在执行此操作时请自行承担责任。

C:\>curl -H "Content-Type: application/json" -XPOST "http://localhost:9200/_snapshot/elasticsearch-snapshot/test_snapshot/_restore?pretty"
{
  "accepted" : true
}

当再次执行恢复命令时,成功地完成了任务。

search3.png

请提供更多上下文信息,以便我能够给出准确的中文翻译。

以下是一种可能的中国话的表达方式:

https://suzuki.tdiary.net/20141113.html
https://note.com/wi_curation/n/nd8338fc8af60
https://orebibou.com/ja/home/201806/20180606_001/
https://kohei.life/elasticsearch-backup/
https://www.bluecore.net/archives/6769
https://qiita.com/shouta-dev/items/c2d2eb6cf61bb1fa8e1b

广告
将在 10 秒后关闭
bannerAds