Doubts and possible 'curl' problem to create and restore indices snapshot from pods CLI

Good morning.

Some colleagues in the office requested me to investigate how could they create a backup policy for their indices.

The first doubt I have is if using a NFS directory could work as an approach.
The master nodes and data nodes would include the path.repo to that directory.

This is something I managed to do at home with VMs but I would like to apply that strategy also to K8s

If this is possible my colleagues dont want to use Kibana to manage the snapshot. So the option would be creating snapshot on daily basis and eventually running a restore from CLI too.

From the dev tool at home I managed to run succesfully the restore from the DevTools section in Kibana.
I runned:

POST /_snapshot/my_fs_backup/my_snapshot_2022.11.12/_restore
{
  "indices": ".ds-filebeat-8.4.3-2022.11.04-000001,filebeat-8.4.3"
}

And it work perfectly

Now I tried to do it from the ubuntu's cli at home by using:

curl -XPUT --cacert /etc/elasticsearch/certs/http_ca.crt -u elastic:blablabla  "https://localhost:9200/_snapshot/my_fs_backup/my_snapshot_2022.11.12/_restore" -d '{ "indices": ".dWs-filebeat-8.4.3-2022.11.04-000001,filebeat-8.4.3"}}'

Which returned:
{"error":"Incorrect HTTP method for uri [/_snapshot/my_fs_backup/my_snapshot_2022.11.12/_restore] and method [PUT], allowed: [POST]","status":405}

I tried

curl -PUT --cacert /etc/elasticsearch/certs/http_ca.crt -u elastic:blablabla  "https://localhost:9200/_snapshot/my_fs_backup/my_snapshot_2022.11.12/_restore" -d '{ "indices": ".dWs-filebeat-8.4.3-2022.11.04-000001,filebeat-8.4.3"}}'

which returned
{"error":"Content-Type header [application/x-www-form-urlencoded] is not supported","status":406}

And well, this are basically my questions.
A) Can I use this approach in our own self-manage K8s cluster to backup snapshot (NFS+CLI commands)?
B) what is the right syntax I should use?

Thank you very much and best regards.

Have you tried to use POST instead of PUT? The error message is saying that PUT is not allowed, you need to use POST.

Good evening.

Thank you Leandro for you fast answer.
Indeed, POST is what I had to use. And I did but I had an error related to the certificates and that's why I stop trying it.
The issue dissapaired once I combined 'sudo' and 'POST'.

I tried more than restoring, so here you are some examples:

Creating NFS repository:

sudo curl -POST --cacert /etc/elasticsearch/certs/http_ca.crt -u elastic:blablaba -H'Content-Type: application/json' "https://localhost:9200/_snapshot/my_fs_backup?pretty" -d '{ "type": "fs", "settings": { "location": "/backups" }}'

Creating NFS snapshot (It makes a backup of all indices)

sudo curl -X PUT --cacert /etc/elasticsearch/certs/http_ca.crt -u elastic:blablabla "https://192.168.0.111:9200/_snapshot/my_fs_backup/%3Cmy_snapshot_%7Bnow%2Fd%7D%3E?pretty"

**Restoring a couple of indices (filebeat and filebeat's datastream) from the snapshot I created yesterday with this name 'my_snapshot_2022.11.13' **

sudo curl -POST --cacert /etc/elasticsearch/certs/http_ca.crt -u elastic:blablabla -H'Content-Type: application/json' "https://localhost:9200/_snapshot/my_fs_backup/my_snapshot_2022.11.13/_restore" -d '{ "indices": ".ds-filebeat-8.4.3-2022.11.13-000001,filebeat-8.4.3"}}'`

Everythink worked fine

I just hope I can use it in the K8s environment.

I have more doubts about how to deal with the already existing indices that force me to rename the restored ones, how to merge data so dashboard can show them,etc...

Thank you very much Leandro, and the rest of you who read it too.

Have a nice week :slight_smile:

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