[elasticsearch笔记] Back up a cluster

note

  • 不能通过简单的复制节点数据实现备份,因为在复制数据的时候,可能集群中相关节点在写数据。
  • 可靠的备份集群的方法是使用 snapshot 和 restore 功能
  • snapshot 是在一个运行的ES集群中生成备份,并且其备份是增量备份。备份的数据可以存储到 共享文件系统,也有插件支持把备份文件保存在S3,HDFS,Azure,Google Cloud Storage 中。
GET /_snapshot/my_backup
GET /_snapshot/repo*,*backup*
GET /_snapshot
GET /_snapshot/_all
DELETE /_snapshot/my_backup/snapshot_1

shared file system repository

  • type 1
path.repo: ["/mount/backups", "/mount/longterm_backups"] in elasticsearch.yml

PUT /_snapshot/my_backup
{
  "type": "fs",
  "settings": {
    "location": "my_backup_location",
    "compress":true
  }
}
  • type 2
PUT /_snapshot/my_backup
{
  "type": "fs",
  "settings": {
    "location": "/mount/backups/my_backup_location",
    "compress":true
  }
}

unverified backup

PUT /_snapshot/my_unverified_backup?verify=false
{
  "type": "fs",
  "settings": {
    "location": "my_unverified_backup_location"
  }
}

POST /_snapshot/my_unverified_backup/_verify

S3 repository

more

sudo bin/elasticsearch-plugin install repository-s3
sudo bin/elasticsearch-plugin remove repository-s3

PUT _snapshot/my_s3_repository
{
  "type": "s3",
  "settings": {
    "bucket": "my_bucket"
  }
}
PUT _snapshot/my_s3_repository
{
  "type": "s3",
  "settings": {
    "bucket": "my_bucket",
    "client": "my_alternate_client"
  }
}

back up a cluster’s configuration

  • transient settings 不被考虑做备份
  • Elastic Stack 中其他组件(如 Kibana、Machine learning)存储配置文件到特定的index中。所以不需要额外考虑这些组件的配置备份问题。
    GET _cluster/settings?pretty&flat_settings&filter_path=persistent

Back up the security configuration

  • step1
PUT /_snapshot/my_backup
{
  "type": "fs",
  "settings": {
    "location": "my_backup_location"
  }
}
  • step2
POST /_security/user/snapshot_user
{
  "password" : "secret",
  "roles" : [ "snapshot_user" ]
}
  • step3
PUT /_snapshot/my_backup/snapshot_1
{
  "indices": ".security",
  "include_global_state": true 
}

Restore a cluster’s security configuration

GET /_snapshot/my_backup
GET /_snapshot/my_backup/snapshot_1

bin/elasticsearch-users useradd restore_user -p password -r superuser
curl -u restore_user -X DELETE "localhost:9200/.security-*"

 curl -u restore_user -X POST "localhost:9200/_snapshot/my_backup/snapshot_1/_restore" -H 'Content-Type: application/json' -d'
 {
    "indices": ".security-*",
    "include_global_state": true 
 }
 '

restore a cluster’s data

POST /_snapshot/my_backup/snapshot_1/_restore

POST /_snapshot/my_backup/snapshot_1/_restore
{
  "indices": "index_1,index_2",
  "ignore_unavailable": true,
  "include_global_state": true,
  "rename_pattern": "index_(.+)",
  "rename_replacement": "restored_index_$1"
}

POST /_snapshot/my_backup/snapshot_1/_restore
{
  "indices": "index_1",
  "index_settings": {
    "index.number_of_replicas": 0
  },
  "ignore_index_settings": [
    "index.refresh_interval"
  ]
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值