迁移注意事项
-
保证ES集群不再接受新的数据(如果是备份的话,这一点可以不考虑,但是做数据迁移的话,建议这样做).
-
不建议直接在生产环境做这些操作,最好是先在本地搭建一个和生产环境一样的集群环境,创建一些测试数据,把整个过程先跑一遍,然后再到生产环境操作。
-
配置文件中指定path.repo路径,如:path.repo: /data/backups/elasticsearch
注册快照仓库
-
共享的文件系统,如NAS
-
Amazon S3
-
HDFS (Hadoop Distributed File System)
-
Azure Cloud
$ curl -XPUT http://192.168.0.1:9200/_snapshot/my_backup -d '
{
"type": "fs",
"settings": {
"location": "/data/backups/elasticsearch"
}
}
'
-
compress 是否压缩
-
max_snapshot_bytes_per_sec 制作快照的速度,默认20mb/s
-
max_restore_bytes_per_sec 快照恢复的速度,默认20mb/s
$ curl -XPOST http://192.168.0.1:9200/_snapshot/my_backup/
{
"type": "fs",
"settings": {
"location": "/data/backups/elasticsearch",
"max_snapshot_bytes_per_sec" : "50mb",
"max_restore_bytes_per_sec" : "50mb",
"compress" : true
}
}
检查注册的仓库信息
$ curl -XGET http://192.168.0.1:9200/_snapshot/my_backup
开始备份
$ curl -XPUT http://192.168.0.1:9200/_snapshot/my_backup/snapshot_20150812
$ curl -XPUT http://192.168.0.1:9200/_snapshot/my_backup/snapshot_20150812?wait_for_completion=true
默认是备份所有的索引indices, 如果要指定index,可以
$ curl -XPUT http://192.168.0.1:9200/_snapshot/my_backup/snapshot_20150812
{
"indices": "index_1,index_2"
}
查看备份状态
$ curl -XGET http://192.168.0.1:9200/_snapshot/my_backup/snapshot_20150812/_status
-
INITIALIZING 集群状态检查,检查当前集群是否可以做快照,通常这个过程会非常快
-
STARTED 正在转移数据到仓库
-
FINALIZING 数据转移完成,正在转移元信息
-
DONE 完成
-
FAILED 备份失败
取消备份
$ curl -XDELETE http://192.168.0.1:9200/_snapshot/my_backup/snapshot_20150812
恢复备份
$ curl -XPOST http://192.168.0.1:9200/_snapshot/my_backup/snapshot_20150812/_restore
同备份一样,也可以设置wait_for_completion=true等待恢复结果
$ curl -XPOST http://192.168.0.1:9200/_snapshot/my_backup/snapshot_20150812/_restore?wait_for_completion=true
$ curl -XPOST http://192.168.0.1:9200/_snapshot/my_backup/snapshot_20150812/_restore
{
"indices": "index_1",
"rename_pattern": "index_(.+)",
"rename_replacement": "restored_index_$1"
}
-
上面的indices, 表示只恢复索引’index_1’
-
renamepattern: 表示重命名索引以’index‘开头的索引.
-
rename_replacement: 表示将所有的索引重命名为’restored_index_xxx’.如index_1会被重命名为restored_index_1.
查看恢复进度
# 查看所有索引的恢复进度
$ curl -XGET http://192.168.0.1:9200/_recovery/
# 查看索引restored_index_1的恢复进度
$ curl -XGET http://192.168.0.1:9200/_recovery/restored_index_1
取消恢复
$ curl -XDELETE http://192.168.0.1:9200/restored_index_1