推广 热搜: page  使用  音视频  个数  选择  搜索引擎  企业  可以  百度  父亲 

ElasticSearch7.x基于Java API 快照备份和恢复

   日期:2024-12-31     作者:o93v3    caijiyuan   评论:0    移动:http://ww.kub2b.com/mobile/news/17247.html
核心提示:1. 配置es环境 我这里用的是windowns版本的,在es官网下载压缩包 https://www.elastic.co/cn/downloads/elasticsearch 解

1. 配置es环境
我这里用的是windowns版本的,在es官网下载压缩包
https://www.elastic.co/cn/downloads/elasticsearch
解压后在connfig找到elasticsearch.yml进行以下配置修改

  1. 服务名称 cluster.name: my-application
  2. 节点名称 node.name: node-1
  3. 快照本地路径 path.repo: [E:/es/data]
  4. 地址network.host: localhost
  5. 端口 http.port: 9200

在 bin 目录下,找到elasticsearch.bat 双击 启动es

依赖说一下,避免找不到对应jar包里的方法,当使用springboot + Elasticsearch时,需要明确指定依赖.

 
  1. 创建快照仓库

    RestHighLevelClient client = new RestHighLevelClient(
    RestClient.builder(new HttpHost(“localhost”,9200))
    );
    System.out.println(“es已成功链接”);
    //创建快照仓库
    PutRepositoryRequest request = new PutRepositoryRequest();
    request.name(“my_backup0001”);
    request.type(FsRepository.TYPE);
    request.masterNodeTimeout(Timevalue.timevalueMinutes(1));
    request.verify(true);

     
  1. 创建快照

    RestHighLevelClient client = new RestHighLevelClient(
    RestClient.builder(new HttpHost(“localhost”,9200))
    );
    System.out.println(“es已成功链接”);
    //快照开始时间
    System.out.println(“快照开始时间:” + new Date());
    //创建快照
    CreateSnapshotRequest request = new CreateSnapshotRequest();
    //快照仓库名称
    request.repository(“my_backup0001”);
    //快照名称
    String snapshotName = “backup”+System.currentTimeMillis();
    request.snapshot(snapshotName);
    //快照的索引 第一次全量备份,以后是增量备份
    request.indices(“shopping_demo”, “test_demo”);
    request.indicesOptions(IndicesOptions.fromOptions(false, false, true, true));
    request.partial(false);
    request.includeGlobalState(true);
    request.masterNodeTimeout(“1m”);
    request.waitForCompletion(true);
    //同步请求客户端
    CreateSnapshotResponse response = client.snapshot().create(request, RequestOptions.DEFAULT);
    //快照信息
    SnapshotInfo snapshotInfo = response.getSnapshotInfo();
    //快照索引信息
    System.out.println(snapshotInfo.indices());
    //快照结束时间
    System.out.println(“快照结束时间:” + snapshotInfo.endTime());
    //快照创建响应状态 200 ok
    RestStatus status = response.status();
    System.out.println(“es快照响应状态:”+status);

     
本文地址:http://ww.kub2b.com/news/17247.html     企库往 http://ww.kub2b.com/ ,  查看更多

特别提示:本信息由相关用户自行提供,真实性未证实,仅供参考。请谨慎采用,风险自负。

 
 
更多>同类最新文章
0相关评论

文章列表
相关文章
最新动态
推荐图文
最新文章
点击排行
网站首页  |  关于我们  |  联系方式  |  使用协议  |  版权隐私  |  网站地图  |  排名推广  |  广告服务  |  积分换礼  |  网站留言  |  RSS订阅  |  违规举报  |  鄂ICP备2020018471号