ElasticSearch单索引的备份与还原

文章目录

  • 1、创建共享仓库
  • 2、备份索引数据
  • 3、索引还原
  • 参考脚本

操作系统:

[root@host-192-168-213-23 config]# cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core)

1、创建共享仓库

linux下命令行使用时格式改为一行(文档只是利于理解)

curl -i -H ""'Content-Type:application/json;charset=UTF-8'"" -X PUT --data   
'{
	"type": "fs",
    "settings":
	{
    	"location": "/data/bk/",	#共享仓库的路径,确定ES用户有目录权限
      	"compress": true
	}
}' http://192.168.199.199:9200/_snapshot/my_backup  #ES的IP地址

修改elasticsearch.yml文件,在文档中添加共享仓库的路径,之后需要重启ES

path.repo: /data/bk

2、备份索引数据

curl -i -H ""'Content-Type:application/json;charset=UTF-8'"" -X PUT --data
'{
	"indices": "'$name'"	 #需要备份的索引名称
}' http://192.168.199.199:9200/_snapshot/my_backup/$name

查看某个索引的备份状态

curl -X GET http://192.168.199.199:9200/_snapshot/my_backup/$name/_status

3、索引还原

还原某个索引数据

curl -i -X POST http://192.168.199.199:9200/_snapshot/my_backup/$name/_restore

参考脚本

#创建共享仓库
echo -n "输入要备份的索引名称:"
read name
curl -i -H ""'Content-Type:application/json;charset=UTF-8'"" -X PUT --data '{"type": "fs","settings": {"location": "/data/bk/","compress": true}}' http://192.168.199.199:9200/_snapshot/my_backup
#备份索引
curl -i -H ""'Content-Type:application/json;charset=UTF-8'"" -X PUT --data '{"indices": "'$name'"}' http://192.168.199.199:9200/_snapshot/my_backup/$name
#还原索引
curl -i -X POST http://192.168.199.199:9200/_snapshot/my_backup/$name/_restore

参考文档:
https://blog.csdn.net/sd4015700/article/details/49964083
https://blog.csdn.net/u014431852/article/details/52905821/
https://blog.csdn.net/github_26672553/article/details/70255458
https://www.jianshu.com/p/a757f77cf126

你可能感兴趣的:(ELK,ES索引数据备份)