This guide provides step-by-step instructions for restoring Elasticsearch snapshots from a local backup directory using Docker.
- Docker and Docker Compose installed on your system.
- A local backup directory containing your Elasticsearch snapshots (e.g.,
/Users/Documents/es_backup/backup).
Create a docker-compose.yml file and start a new Elasticsearch container without mounting any volumes:
services:
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:8.14.0
container_name: elasticsearch
environment:
- discovery.type=single-node
- xpack.security.enabled=false
- xpack.security.http.ssl.enabled=false
# - bootstrap.memory_lock=true
# - ES_JAVA_OPTS=-Xms512m -Xmx512m
# ulimits:
# memlock:
# soft: -1
# hard: -1
# volumes:
# - /root/es_data:/usr/share/elasticsearch/data
ports:
- "9200:9200"
- "9300:9300"Use the docker cp command to copy the snapshot data from your local backup directory to the container:
docker cp /Users/Documents/es_backup/backup/ elasticsearch:/usr/share/elasticsearch/data/backupEnter the container and modify the elasticsearch.yml file to add the path.repo setting:
docker exec -it --user root elasticsearch /bin/bash
cat /usr/share/elasticsearch/config/elasticsearch.ymlAdd the following line:
path.repo: ["/usr/share/elasticsearch/data/backup"]Exit the container and restart it to apply the configuration changes:
exit
docker restart elasticsearchConfigure the snapshot repository in Elasticsearch:
curl -X PUT "http://localhost:9200/_snapshot/my_backup" -H "Content-Type: application/json" -d'
{
"type": "fs",
"settings": {
"location": "/usr/share/elasticsearch/data/backup"
}
}
'Verify that the snapshots are available in the repository:
curl -X GET "http://localhost:9200/_snapshot/my_backup/_all"Use the correct snapshot name to restore the data. For example, if the snapshot name is snapshot_1:
curl -X POST "http://localhost:9200/_snapshot/my_backup/snapshot_1/_restore"Verify that the data has been restored correctly:
curl -X GET "http://localhost:9200/_cat/indices?v"If you encounter any issues during the restore process, ensure that:
The snapshot files are correctly copied to the container. The path.repo setting in elasticsearch.yml matches the location of the snapshot files. The Elasticsearch container has the necessary permissions to read the snapshot files.
swag init -g /cmd/main.go -exclude model,pkg