# Elasticsearch creating snapshots to gce with the ability to put it into a folder

**URL:** <https://discuss.elastic.co/t/elasticsearch-creating-snapshots-to-gce-with-the-ability-to-put-it-into-a-folder/78021>\
**Category:** Elasticsearch\
**Created:** [March 9, 2017, 4:45pm UTC](https://discuss.elastic.co/t/elasticsearch-creating-snapshots-to-gce-with-the-ability-to-put-it-into-a-folder/78021 "2017-03-09T16:45:25Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![zozo6015](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/zozo6015/32/12117_2.png) [@zozo6015](https://discuss.elastic.co/u/zozo6015)\
**Post date:** [March 9, 2017, 4:45pm UTC](https://discuss.elastic.co/t/elasticsearch-creating-snapshots-to-gce-with-the-ability-to-put-it-into-a-folder/78021/1 "2017-03-09T16:45:26Z")

</div>

Hello,

I am using elasticsearch v5 and I am trying to create snapshots to the gce storage. I have a bucket created for all kind of backups that is why I would like to puthe elasticsearch backups into their own folder.

If I use the following command everything is OK but the indexes are placed into the root of the bucket

```
curl -XPUT http://localhost:19270/_snapshot/test?pretty -H 'Content-Type: application/json' -d'
{
  "type": "gcs",
  "settings": {
    "bucket": "gce_snapshots",
    "service_account": "service_account.json"
  }
}
'

```

I have tried precreating the folders on the gce bucket and use it like this:

```
curl -XPUT http://localhost:19270/_snapshot/test?pretty -H 'Content-Type: application/json' -d'
{
  "type": "gcs",
  "settings": {
    "bucket": "gce_snapshot/test",
    "service_account": "service_account.json"
  }
}
'

```

but I get the following error:

```
{
  "error" : {
    "root_cause" : [
      {
        "type" : "blob_store_exception",
        "reason" : "Unable to check if bucket [gce_snapshot/test] exists"
      }
    ],
    "type" : "repository_exception",
    "reason" : "[test] failed to create repository",
    "caused_by" : {
      "type" : "blob_store_exception",
      "reason" : "Unable to check if bucket [gce_snapshot/test] exists",
      "caused_by" : {
        "type" : "google_json_response_exception",
        "reason" : "400 Bad Request\n{\n \"code\" : 400,\n \"errors\" : [{\n \"domain\" : \"global\",\n \"message\" : \"Invalid bucket name: 'gce_snapshot/test'\",\n \"reason\" : \"invalid\"\n }],\n \"message\" : \"Invalid bucket name: 'snapshots.wpcloud.io/test'\"\n}"
      }
    }
  },
  "status" : 500
}

```

Any idea how to achieve this?

---

<div class="post-metadata">

**Author:** ![jkuang](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jkuang/32/72637_2.png) [@jkuang](https://discuss.elastic.co/u/jkuang)\
**Post date:** [March 9, 2017, 8:29pm UTC](https://discuss.elastic.co/t/elasticsearch-creating-snapshots-to-gce-with-the-ability-to-put-it-into-a-folder/78021/2 "2017-03-09T20:29:02Z")

</div>

Did you install the ES GCE plugin?

[https://www.elastic.co/guide/en/elasticsearch/plugins/current/repository-gcs.html](https://www.elastic.co/guide/en/elasticsearch/plugins/current/repository-gcs.html)

---

<div class="post-metadata">

**Author:** ![zozo6015](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/zozo6015/32/12117_2.png) [@zozo6015](https://discuss.elastic.co/u/zozo6015)\
**Post date:** [March 9, 2017, 8:38pm UTC](https://discuss.elastic.co/t/elasticsearch-creating-snapshots-to-gce-with-the-ability-to-put-it-into-a-folder/78021/3 "2017-03-09T20:38:31Z")

</div>

Of course I did, only the information the url gives does not tell how to take a snapshot into a folder on the bucket which I need.

---

<div class="post-metadata">

**Author:** ![jkuang](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jkuang/32/72637_2.png) [@jkuang](https://discuss.elastic.co/u/jkuang)\
**Post date:** [March 9, 2017, 8:50pm UTC](https://discuss.elastic.co/t/elasticsearch-creating-snapshots-to-gce-with-the-ability-to-put-it-into-a-folder/78021/4 "2017-03-09T20:50:09Z")

</div>

Didn't mean to ask the obvious , but my job habits tend to creep up on me. Does the snapshot work if you didn't specify the "test" folder?

Nevermind, I see that you said it did work.

---

<div class="post-metadata">

**Author:** ![zozo6015](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/zozo6015/32/12117_2.png) [@zozo6015](https://discuss.elastic.co/u/zozo6015)\
**Post date:** [March 9, 2017, 8:56pm UTC](https://discuss.elastic.co/t/elasticsearch-creating-snapshots-to-gce-with-the-ability-to-put-it-into-a-folder/78021/5 "2017-03-09T20:56:19Z")

</div>

As I previously said, the snapshot works if the folder is not specified but I need to do that cause we are taking snapshots on different elasticsearch clusters for different customers. Therefore each needs to have their own place without the interference of other customers.

---

<div class="post-metadata">

**Author:** ![jkuang](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jkuang/32/72637_2.png) [@jkuang](https://discuss.elastic.co/u/jkuang)\
**Post date:** [March 9, 2017, 9:08pm UTC](https://discuss.elastic.co/t/elasticsearch-creating-snapshots-to-gce-with-the-ability-to-put-it-into-a-folder/78021/6 "2017-03-09T21:08:06Z")

</div>

From the code it looks like it will check for privileges to create the folder. If you do have that setup I would restarting ES then issue the snapshot command again.

```auto
  104 boolean doesBucketExist(String bucketName) {
  105 try {
  106 return doPrivileged(() -> {
  107 try {
  108 Bucket bucket = client.buckets().get(bucketName).execute();
  109 if (bucket != null) {
  110 return Strings.hasText(bucket.getId());
  111 }
  112 } catch (GoogleJsonResponseException e) {
  113 GoogleJsonError error = e.getDetails();
  114 if ((e.getStatusCode() == HTTP_NOT_FOUND) || ((error != null) && (error.getCode() == HTTP_NOT_FOUND))) {
  115 return false;
  116 }
  117 throw e;
  118 }
  119 return false;
  120 });
  121 } catch (IOException e) {
  122 throw new BlobStoreException("Unable to check if bucket [" + bucketName + "] exists", e);
  123 }
  124 }

```

---

<div class="post-metadata">

**Author:** ![zozo6015](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/zozo6015/32/12117_2.png) [@zozo6015](https://discuss.elastic.co/u/zozo6015)\
**Post date:** [March 9, 2017, 10:07pm UTC](https://discuss.elastic.co/t/elasticsearch-creating-snapshots-to-gce-with-the-ability-to-put-it-into-a-folder/78021/7 "2017-03-09T22:07:02Z")

</div>

What kind of privileges do I need for that? I have the service user with write access to the bucket. I didn't see any other privileges possible but read or write. Also how to mention that I want to put the snapshots into xxx folder?

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [March 9, 2017, 10:09pm UTC](https://discuss.elastic.co/t/elasticsearch-creating-snapshots-to-gce-with-the-ability-to-put-it-into-a-folder/78021/8 "2017-03-09T22:09:20Z")

</div>

I'd do:

```auto
curl -XPUT http://localhost:19270/_snapshot/test?pretty -H 'Content-Type: application/json' -d'
{
  "type": "gcs",
  "settings": {
    "bucket": "gce_snapshot",
    "service_account": "service_account.json",
    "base_path": "test"
  }
}
'

```

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [March 9, 2017, 10:11pm UTC](https://discuss.elastic.co/t/elasticsearch-creating-snapshots-to-gce-with-the-ability-to-put-it-into-a-folder/78021/9 "2017-03-09T22:11:14Z")

</div>

This is unrelated. `doPriviliged()` has been introduced recently for other reasons.

---

<div class="post-metadata">

**Author:** ![zozo6015](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/zozo6015/32/12117_2.png) [@zozo6015](https://discuss.elastic.co/u/zozo6015)\
**Post date:** [March 9, 2017, 10:24pm UTC](https://discuss.elastic.co/t/elasticsearch-creating-snapshots-to-gce-with-the-ability-to-put-it-into-a-folder/78021/10 "2017-03-09T22:24:42Z")

</div>

Perfect. As always you get me to the right direction. Thank you very much

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [April 6, 2017, 10:25pm UTC](https://discuss.elastic.co/t/elasticsearch-creating-snapshots-to-gce-with-the-ability-to-put-it-into-a-folder/78021/11 "2017-04-06T22:25:22Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
