How to backup or restore elasticsearch

How to Backup snapshot of of old ES v6.x and Restore snapshot to new ES v7.x

** ref https://www.elastic.co/guide/en/elasticsearch/reference/6.6/modules-snapshots.html

elasticsearch backup (create snapshot) about specific indices
– All commands are processed by curl command with json options.

## setup backup location
$ curl -X PUT "localhost:9200/_snapshot/my_backup?pretty" -H 'Content-Type: application/json' -d'
{
  "type": "fs",
  "settings": {
    "location": "/Users/bgmin/Servers/elasticsearch/backup"
  }
}
'

## export snapshot (backup)
$ curl -X PUT "localhost:9200/_snapshot/my_backup/snapshot_agens?wait_for_completion=true&pretty" -H 'Content-Type: application/json' -d'
{
  "indices": "agensvertex,agensedge",
  "ignore_unavailable": true,
  "include_global_state": false
}
'

Before backup, you have to setup “path.repo” in elasticsearch.yml
– In case of MacOS, “/usr/local/etc/elasticsearch/elasticsearch.yml”

# ------------------------ Paths ------------------------------------
#
# Path to directory where to store the data (separate multiple locations by comma):
#
path.data: /usr/local/var/lib/elasticsearch/
#
# Path to log files:
#
path.logs: /usr/local/var/log/elasticsearch/
#
# Path to backup:
#
path.repo: ["/Users/bgmin/Workspaces/elastic/backup"]

If you do not, then you get this message as “repository_exception“.

After backup, and you can verify your snapshot.

curl -X GET "localhost:9200/_snapshot/my_backup/snapshot_agens?pretty"

And created shnapshots contains these files and directories.

ES version of old system (v6.6.1) ==> new system (v7.3.0)


When restore your snapshot in new or another ES, you have to check snapshot at first.

If repository exception arise, check elasticsearch.yml and register snapshot.

## Setup path.repo
$ grep path.repo config/elasticsearch.yml
path.repo: ["/Users/bgmin/Servers/elasticsearch"]

## Register snapshot
$ curl -X PUT "localhost:9200/_snapshot/my_backup?pretty" -H 'Content-Type: application/json' -d'
{
  "type": "fs",
  "settings": {
    "location": "/Users/bgmin/Servers/elasticsearch/backup"
  }
}
'
{
  "acknowledged" : true
}

## Verify snapshot
$ curl -X GET "localhost:9200/_snapshot/my_backup/snapshot_agens?pretty"
{
  "snapshots" : [
    {
      "snapshot" : "snapshot_agens",
      "uuid" : "wJb6vH_qQZSjo9twbekYCA",
      "version_id" : 6060199,
      "version" : "6.6.1",
      "indices" : [
        "agensedge",
        "agensvertex"
      ],
      "include_global_state" : false,
      "state" : "SUCCESS",
      "start_time" : "2019-08-11T04:05:17.038Z",
      "start_time_in_millis" : 1565496317038,
      "end_time" : "2019-08-11T04:05:17.101Z",
      "end_time_in_millis" : 1565496317101,
      "duration_in_millis" : 63,
      "failures" : [ ],
      "shards" : {
        "total" : 2,
        "failed" : 0,
        "successful" : 2
      }
    }
  ]
}

Then restore your snapshot again. Probably, you can see imported data immediately with accessing es index.

## run import
$ curl -X POST "localhost:9200/_snapshot/my_backup/snapshot_agens/_restore?pretty"
{
  "accepted" : true
}

## verify data
$ curl -X GET "localhost:9200/agensvertex/_search?pretty=true&q=*:*"

__END__

답글 남기기

아래 항목을 채우거나 오른쪽 아이콘 중 하나를 클릭하여 로그 인 하세요:

WordPress.com 로고

WordPress.com의 계정을 사용하여 댓글을 남깁니다. 로그아웃 /  변경 )

Google photo

Google의 계정을 사용하여 댓글을 남깁니다. 로그아웃 /  변경 )

Twitter 사진

Twitter의 계정을 사용하여 댓글을 남깁니다. 로그아웃 /  변경 )

Facebook 사진

Facebook의 계정을 사용하여 댓글을 남깁니다. 로그아웃 /  변경 )

%s에 연결하는 중

%d 블로거가 이것을 좋아합니다: