Skip to content

Instantly share code, notes, and snippets.

@TomonoriSoejima
Last active August 2, 2017 05:58
Show Gist options
  • Save TomonoriSoejima/d27e565bc07d81d97c2008f4acc9705e to your computer and use it in GitHub Desktop.
Save TomonoriSoejima/d27e565bc07d81d97c2008f4acc9705e to your computer and use it in GitHub Desktop.
snapshot and restore
DELETE test
PUT test/
{
"settings" : {
"index" : {
"number_of_shards" : 1,
"number_of_replicas" : 1
}
}
}
PUT _snapshot/move_test
{
"type": "fs",
"settings": {
"location": "/Users/surfer/elastic/labs/5.4-xpack/elasticsearch/snapshots/",
"compress": true
}
}
PUT test/test/1
{
"data" : 1
}
PUT /_snapshot/move_test/snap1?wait_for_completion=true
{
"indices": "test",
"include_global_state": true
}
PUT test/test/2
{
"data" : 2
}
PUT /_snapshot/move_test/snap2?wait_for_completion=true
{
"indices": "test",
"include_global_state": true
}
# check uuid for snap2
GET /_snapshot/move_test/snap2
# then delete or move all of them that matches the uuid.
[mbp:snapshots]$ pwd
/Users/surfer/elastic/labs/5.4-xpack/elasticsearch/snapshots
[mbp:snapshots]$ find . | grep z5b1HRX5QHO0zFHGvVhA8Q
./indices/1br2Jf5ESRGoNvR7VC8kOw/0/snap-z5b1HRX5QHO0zFHGvVhA8Q.dat
./indices/1br2Jf5ESRGoNvR7VC8kOw/1/snap-z5b1HRX5QHO0zFHGvVhA8Q.dat
./indices/1br2Jf5ESRGoNvR7VC8kOw/2/snap-z5b1HRX5QHO0zFHGvVhA8Q.dat
./indices/1br2Jf5ESRGoNvR7VC8kOw/3/snap-z5b1HRX5QHO0zFHGvVhA8Q.dat
./indices/1br2Jf5ESRGoNvR7VC8kOw/4/snap-z5b1HRX5QHO0zFHGvVhA8Q.dat
./indices/1br2Jf5ESRGoNvR7VC8kOw/meta-z5b1HRX5QHO0zFHGvVhA8Q.dat
./meta-z5b1HRX5QHO0zFHGvVhA8Q.dat
./snap-z5b1HRX5QHO0zFHGvVhA8Q.dat
[mbp:snapshots]$
# check snap2 and note that snapshot_missing_exception execption is thrown to ensure that snap2 is moved.
GET /_snapshot/move_test/snap2
# delete 2nd document
DELETE test/test/2
# do search to ensure 2nd document is removed.
GET test/_search
# add one more document
PUT test/test/3
{
"data" : 3
}
# get another snapshot
PUT /_snapshot/move_test/snap3?wait_for_completion=true
{
"indices": "test",
"include_global_state": true
}
# close test index before restoring.
POST /test/_close
# restore
POST /_snapshot/move_test/snap3/_restore
# do search and ensure 2nd document is back.
GET test/_search
POST /_xpack/security/user/jacknich
{
"password" : "j@rV1s",
"roles" : [ "admin", "other_role1" ],
"full_name" : "Jack Nicholson",
"email" : "[email protected]",
"metadata" : {
"intelligence" : 7
}
}
GET /.security/_search
GET /_cat/indices
PUT _snapshot/my_backup
{
"type": "fs",
"settings": {
"location": "/Users/surfer/elastic/labs/5.4-xpack/elasticsearch/config/role",
"compress": true
}
}
PUT /_snapshot/my_backup/snapshot_1?wait_for_completion=true
{
"indices": ".security",
"include_global_state": true
}
DELETE /_xpack/security/user/jacknich
POST /.security/_close
POST /_snapshot/my_backup/snapshot_1/_restore
# https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-snapshots.html
# before migration in old cluster
# check all your indexes
GET _cat/indices
# Please make sure that elasticsearch is started with path.repo parameter like this.
# path.repo: ["/home/surfer/backup"]
# shapshot repository registration
PUT _snapshot/my_backup
{
"type": "fs",
"settings": {
"location": "/home/surfer/backup",
"compress": true
}
}
# create snapshot
# with indices parameter, you can choose which indices to backup
# with include_global_state true, it backs up configuration such as mappings.
PUT /_snapshot/my_backup/snapshot_1?wait_for_completion=true
{
"indices": "index1,index2",
"include_global_state": true
}
# check the result of backup you just created.
GET /_snapshot/my_backup/_all
# next make a copy of backup directory and place it on new server
$ zip bk.zip -r backup/
$ scp bk.zip <new server>:
# from here all operation will be done on new server.
# 1. Now login to new server and stop elasticsearch.
# 2. change elasticsearch.yml with path.repo parameter whose value should be pointed to the same location in old server.
# 3. unzip bk.zip on new server
# 4. start elasticsearch
# check the backup is acknowledged on new server
GET /_snapshot/my_backup/_all
# The restore operation can be performed on a functioning cluster.
# However, an existing index can be only restored if it’s closed and
# has the same number of shards as the index in the snapshot.
# restore indices
POST /_snapshot/my_backup/snapshot_1/_restore
{
"indices": "index1,index2",
"include_global_state": true
}
# check indices
GET /_cat/indices
# check mappings
GET /index1/_mapping
GET /index2/_mapping
# check template
GET /_template
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment