elastic_tutorial/The Elasticsearch Documentation/10-backup restore snapshot remote/old/simple backup and restore.md
2025-04-09 10:37:46 +03:30

2.1 KiB

Old server:

elasticsearch.yml add path.repo, for example

nano /etc/elasticsearch/elasticsearch.yml
path.repo:["/data/backup"]

Restart Elasticsearch services

sytemctl restart elasticsearch
curl -H "Content-Type: application/json" 
    -XPUT  http://192.168.50.247:9200/_snapshot/my_backup 
    -d '{ "type": "fs", "settings": 
    { "location": "/data/backup","compress": true }}'

Create backup

curl -XPUT http://192.168.50.247:9200/_snapshot/my_backup/news0618

#New server:

Restore database(new server ip:192.168.10.49 ):

curl -XPOST http://192.168.10.49:9200/_snapshot/my_backup/news0618/_restore

Answer:

If you are using fs as a snapshot repository location then it will not work as your new instance is hosted on different host it will not have access to your old hosts file system. You need to use any shared location like volume mounts, S3 or Azure blob etc.

You should use reindexing rather than snapshot and restore. Its pretty simpler. Refer this link for remote reindexing:

Steps:

Whitelist remote host in elasticsearch.yaml using the reindex.remote.whitelist property in your new Elasticsearch instance:
    reindex.remote.whitelist: "192.168.50.247:9200"    
Restart new Elasticsearch instance.

Reindexing:
    curl -X POST "http://192.168.10.49:9200/_reindex?pretty" -H 'Content-Type: application/json' -d'
    {
      "source": {
        "remote": {
          "host": "http://192.168.50.247:9200"
        },
        "index": "source-index-name",
        "query": {
          "match_all": {}
        }
      },
      "dest": {
        "index": "dest-index-name"
      }
    }
    '

Refer this link for reindexing many indices

Warning: The destination should be configured as wanted before calling _reindex. Reindex does not copy the settings from the source or its associated template. Mappings, shard counts, replicas, and so on must be configured ahead of time.

Hope this helps!

منبع