External Docker Volume for Elasticsearch Snapshot

I'm trying to use snapshot for backup and restore, I added the backup path in elasticsearch.yml as:

path.repo: ["/opt/elasticsearch/backup"]

Also in my elasticsearch docker-compose.yml I bind this path to an external volume as:

version: '2'

services:

  elasticsearch:
    build:
      context: elasticsearch/
      args:
        ELK_VERSION: 7.2.0
    volumes:
      - ./elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml:ro
      - elastic_data:/usr/share/elasticsearch/data
      - elastic_data_backup:/opt/elasticsearch/backup
    ports:
      - "9200:9200"
      - "9300:9300"
    environment:
      ES_JAVA_OPTS: "-Xmx1g -Xms1g"
      ELASTIC_PASSWORD: changeme
    networks:
      - elk

networks:
  elk:
    driver: bridge

volumes:
  elastic_data:
    external: true
  elastic_data_backup:
    external: true

Now, to create an snapshot, first:

PUT /_snapshot/my-snapshot
{
  "type": "fs",
  "settings": {
    "compress" : true,
    "location": "/opt/elasticsearch/backup"
  }
}

but when I use this command to create snapshot:

PUT /_snapshot/my-snapshot/backup_1?wait_for_completion=true

I get the following error:

{"error":"RepositoryVerificationException[[es_backup] path  is not accessible on master node]; nested: FileNotFoundException[/opt/elasticsearch/backup/tests-Y1AbUndPQ_O1je_zyFGa1Q-master (Permission denied)]; ","status":500}

Following this link I could resolved the issue by changing the folders ownership as follows:

# Change the ownership of user-mutable directories to elasticsearch
for path in \
	/usr/share/elasticsearch/data \
	/usr/share/elasticsearch/logs \
	/opt/elasticsearch/backup \
; do
	chown -R elasticsearch:elasticsearch "$path"
done

But I wonder if there is a better workaround, and is the above method safe!? or it may break some functionalities of Elasticsearch!

1 Like

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