vim /etc/elasticsearch/elasticsearch.yml path.repo: ["/data/backups/es_backup"] #备份目录,根据自己情况进行填写 systemctl restart elasticsearch.service mkdir -pv /data/backups/es_backup chmod 755 /data/backups/es_backup chown elasticsearch:elasticsearch /data/backups/es_backup
2、创建仓库
备份数据之前,要创建一个仓库来保存数据,仓库的类型支持Shared filesystem, Amazon S3, HDFS和Azure Cloud。下面以文件系统为例
curl -H "Content-Type:application/json" -XPUT '127.0.0.1:9200/_snapshot/es_backup' -d ' {"type": "fs", "settings": {"location": "/data/backups/es_backup" } }'
3、备份索引
curl -H "Content-Type:application/json" -XPUT '127.0.0.1:9200/_snapshot/es_backup/snapshot_1'
如果只想备份部分索引的话,可以加上indices 参数:
curl -H "Content-Type:application/json" -XPUT '127.0.0.1:9200/_snapshot/es_backup/snapshot_2' -d ' {"indices": "index_1,index_2"}'
5 、查看备份信息
curl -H "Content-Type:application/json" -XGET '127.0.0.1:9200/_snapshot/es_backup/snapshot_1?pretty=true' {
参考:https://www.jianshu.com/p/3b4d869f2fd1
参考:https://blog.csdn.net/jiahao1186/article/details/81058022
6、数据恢复
curl -H "Content-Type:application/json" -XPOST '127.0.0.1:9200/_snapshot/es_backup/snapshot_1/_restore'