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
path.repo: ["/mount/backups", "/mount/longterm_backups"] in elasticsearch.yml
PUT /_snapshot/my_backup
{
"type": "fs",
"settings": {
"location": "my_backup_location",
"compress":true
}
}
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
PUT /_snapshot/my_backup
{
"type": "fs",
"settings": {
"location": "my_backup_location"
}
}
POST /_security/user/snapshot_user
{
"password" : "secret",
"roles" : [ "snapshot_user" ]
}
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"
]
}