首先先了解一下官网中提到的如何backup your elasticsearch
https://www.elastic.co/guide/en/elasticsearch/guide/current/backing-up-your-cluster.html
知识点
1.关于repository的几种类型。
(来自官网)To use this functionality, you must first create a repository to save data. There are several repository types that you may choose from:
- Shared filesystem, such as a NAS
- Amazon S3
- HDFS (Hadoop Distributed File System)
- Azure Cloud
下面截图是来自kopf这个插件,url在上面没有提到,其他的都能对上
总结一下:fs---->Shared filesystem
s3---->Amazon S3
hdfs--->HDFS (Hadoop Distributed File System)
azure--->Azure Cloud
下面是google的一篇不错的关于snapshot es的 java 代码。
https://dzone.com/articles/how-use-elasticsearch-snapshot
下面是我自己写的代码
String repositoryPath = "E:\snapshot";
boolean compress = true;
String repositoryType = "fs";
// es 2.4
Settings setting = Settings.builder()
.put("location", repositoryPath)
.put("compress", compress).build();
PutRepositoryResponse putRepositoryResponse = clusterAdminClient.preparePutRepository(defaultRepositoryName)
.setType(repositoryType).setSettings(setting)
.execute().actionGet();
if (putRepositoryResponse.isAcknowledged()) {
System.out.println(defaultRepositoryName + " have been created");
repositoryMetaDataList = clusterAdminClient.prepareGetRepositories(defaultRepositoryName).get().repositories();
System.out.println(repositoryMetaDataList.size());
}
Exception in thread "main" RepositoryVerificationException[[hippo_Repository] [VMYox38PS9qXN3hYhf588Q, 'RemoteTransportException[[node-hippo3][10.12.198.242:9300][internal:admin/repository/verify]]; nested: RepositoryVerificationException[[hippo_Repository] a file written by master to the store [/opt/hippo/snapshot/E:snapshot] cannot be accessed on the node [{node-hippo3}{VMYox38PS9qXN3hYhf588Q}{10.12.198.242}{10.12.198.242:9300}{master=true}]. This might indicate that the store [/opt/hippo/snapshot/E:snapshot] is not shared between this node and the master node or that permissions on the store don't allow reading files written by the master node];'], [EZQYXYKcTtuDCgjr17_M6g, 'RemoteTransportException[[node-hippo1][10.12.198.240:9300][internal:admin/repository/verify]]; nested: RepositoryVerificationException[[hippo_Repository] a file written by master to the store [/opt/hippo/snapshot/E:snapshot] cannot be accessed on the node [{node-hippo1}{EZQYXYKcTtuDCgjr17_M6g}{10.12.198.240}{10.12.198.240:9300}{master=false}]. This might indicate that the store [/opt/hippo/snapshot/E:snapshot] is not shared between this node and the master node or that permissions on the store don't allow reading files written by the master node];']]]
at org.elasticsearch.repositories.RepositoriesService$VerifyingRegisterRepositoryListener$1.onResponse(RepositoriesService.java:440)
......
一开始我以为,这个repositoryPath应该是绝对路径,从报错看到设置的应该是相对路径(开头不能是/,直接输入文件夹名字就好了),那么绝对的文件夹位置在哪里设置的,google了一下,发现在elasticsearch.yml中有个变量path.repo,恍然大悟。。。