
Old server:

elasticsearch.yml add path.repo, for example

```r
nano /etc/elasticsearch/elasticsearch.yml
```

```r
path.repo:["/data/backup"]
```

Restart Elasticsearch services

```r
sytemctl restart elasticsearch
```


```r
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 ):

```r
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:

```r
    reindex.remote.whitelist: "192.168.50.247:9200"    
```
    Restart new Elasticsearch instance.

    Reindexing:

```r
    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!

[منبع](https://stackoverflow.com/questions/68031767/how-to-migrate-elasticsearch-to-a-new-server)