[ Elasticsearch Backup (Snapshots) Restore On Server from S3 Bucket ]
[ first create snapshot path using postman ]
PUT http://192.168.1.22:9200/_snapshot/s3_repository
{
"type": "s3",
"settings": {
"bucket": "mylocals3backup",
"base_path": "elasticsearch_backup/local_elasticsearch_backup",
"region": "ap-southeast-1",
"access_key": "XXXXXXXXXXXXXXXXXXXX",
"secret_key": "XXXXXXXXXXXXXXXXXXXX"
}
}'
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# vim elasticserch_index_restore.sh
#!/bin/bash
## DELETE INDEX FROM EXISTING HOSTS ##
curl -XDELETE http://192.168.1.22:9200/index1
curl -XDELETE http://192.168.1.22:9200/index2
curl -XDELETE http://192.168.1.22:9200/index3
curl -XDELETE http://192.168.1.22:9200/index4
## GET LATEST SNAPSHOT ID ##
curl -X GET "http://192.168.1.22:9200/_cat/snapshot/s3_repository?v&s=id&pretty" > /tmp/get_latest_snapshot_id.txt
LATEST_SNAP_ID=`tail -n1 /tmp/get_latest_snapshot_id.txt | awk {'print $1'}`
## RESTORE SNAPSHOT ##
curl -X POST http://192.168.1.22:9200/_snapshot/s3_repository/$LATEST_SNAP_ID/_restore
sleep 5m
## EMAIL NOTIFICATION ##
mailx -r "system@mylocal.com" -s "ELASTICSEARCH SNAPSHOT RESTORED ON SERVER" -S smtp="127.0.0.1:25" user1@mylocal.com,user2@mylocal.com<<EOF
Hi Team,
elasticsearch snapshot restored successfully on 192.168.1.22 server.
restore snapshot_id = $LATEST_SNAP_ID
"curl -XGET 'http://192.168.1.22:9200/_cat/indices?v&pretty"
`curl -XGET http://192.168.1.22:9200/_cat/indices?v`
EOF
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# sh -x elasticserch_index_restore.sh
[ first create snapshot path using postman ]
PUT http://192.168.1.22:9200/_snapshot/s3_repository
{
"type": "s3",
"settings": {
"bucket": "mylocals3backup",
"base_path": "elasticsearch_backup/local_elasticsearch_backup",
"region": "ap-southeast-1",
"access_key": "XXXXXXXXXXXXXXXXXXXX",
"secret_key": "XXXXXXXXXXXXXXXXXXXX"
}
}'
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# vim elasticserch_index_restore.sh
#!/bin/bash
## DELETE INDEX FROM EXISTING HOSTS ##
curl -XDELETE http://192.168.1.22:9200/index1
curl -XDELETE http://192.168.1.22:9200/index2
curl -XDELETE http://192.168.1.22:9200/index3
curl -XDELETE http://192.168.1.22:9200/index4
## GET LATEST SNAPSHOT ID ##
curl -X GET "http://192.168.1.22:9200/_cat/snapshot/s3_repository?v&s=id&pretty" > /tmp/get_latest_snapshot_id.txt
LATEST_SNAP_ID=`tail -n1 /tmp/get_latest_snapshot_id.txt | awk {'print $1'}`
## RESTORE SNAPSHOT ##
curl -X POST http://192.168.1.22:9200/_snapshot/s3_repository/$LATEST_SNAP_ID/_restore
sleep 5m
## EMAIL NOTIFICATION ##
mailx -r "system@mylocal.com" -s "ELASTICSEARCH SNAPSHOT RESTORED ON SERVER" -S smtp="127.0.0.1:25" user1@mylocal.com,user2@mylocal.com<<EOF
Hi Team,
elasticsearch snapshot restored successfully on 192.168.1.22 server.
restore snapshot_id = $LATEST_SNAP_ID
"curl -XGET 'http://192.168.1.22:9200/_cat/indices?v&pretty"
`curl -XGET http://192.168.1.22:9200/_cat/indices?v`
EOF
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# sh -x elasticserch_index_restore.sh
No comments:
Post a Comment