2018-11-01 elasticsearch数据备份和恢复
2018-11-01 本文已影响0人
张大志的博客
1、设置备份目录(用于存储备份文件)
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'
{
"snapshots" : [
{
"snapshot" : "snapshot_1",
"uuid" : "jcWREhvyT72FR-A-UyFrQw",
"version_id" : 6040299,
"version" : "6.4.2",
"indices" : [
"test"
],
"include_global_state" : true,
"state" : "SUCCESS",
"start_time" : "2018-11-01T05:52:02.824Z",
"start_time_in_millis" : 1541051522824,
"end_time" : "2018-11-01T05:52:02.964Z",
"end_time_in_millis" : 1541051522964,
"duration_in_millis" : 140,
"failures" : [ ],
"shards" : {
"total" : 1,
"failed" : 0,
"successful" : 1
}
}
]
}
6、数据恢复
curl -H "Content-Type:application/json" -XPOST '127.0.0.1:9200/_snapshot/es_backup/snapshot_1/_restore'
参考:https://blog.csdn.net/jiahao1186/article/details/81058022