es异机恢复(不带验证)
ES版本:6.5.0
前置条件:ES已经安装部署好,并在运行状态
1.将备份文件解压到新服务器的备份目录
备份目录有es参数决定path.repo: /home/elasticsearch/esbak
[root@hxl elasticsearch]# cd /home/yeemiao/
[root@hxl elasticsearch]#tar -xvf esbak_20221212.tar.gz -C /home/elasticsearch/
该文件大小70GB
输出信息
./esbak/indices/tAHN9QicR2KVm1h0lCq3iw/1/__d
./esbak/indices/tAHN9QicR2KVm1h0lCq3iw/1/__e
./esbak/indices/tAHN9QicR2KVm1h0lCq3iw/1/__f
./esbak/indices/tAHN9QicR2KVm1h0lCq3iw/1/__g
./esbak/indices/tAHN9QicR2KVm1h0lCq3iw/1/__h
./esbak/indices/tAHN9QicR2KVm1h0lCq3iw/1/__i
./esbak/indices/tAHN9QicR2KVm1h0lCq3iw/1/__j
./esbak/indices/tAHN9QicR2KVm1h0lCq3iw/1/__k
./esbak/indices/tAHN9QicR2KVm1h0lCq3iw/1/__l
./esbak/indices/tAHN9QicR2KVm1h0lCq3iw/1/__m
.
.
.
我这里tar打包是包含esbak目录的,所以解压的时候直接指定/home/elasticsearch/即可
2.修改目录权限
[root@hxl yeemiao]# cd /home/elasticsearch/
[root@hxl elasticsearch]# chown -R elasticsearch:elasticsearch ./esbak
3.恢复
查看当前的es是没有数据的
[root@hxl elasticsearch]# su - elasticsearch
[elasticsearch@hxl ~]$ curl -X GET 'http://192.168.1.100:19200/_cat/indices?v'
health status index uuid pri rep docs.count docs.deleted store.size pri.store.size
创建备份指定目录
curl -H "Content-Type: application/json" -XPUT http://192.168.1.100:19200/_snapshot/esbackup -d'{
"type": "fs",
"settings": {
"location": "/home/elasticsearch/esbak"
}
}'
查看备份信息,这个时候备份信息已经注册进来了(机器内存太小,发现执行很久,操作系统差不多hang住了)
[elasticsearch@hxl ~]$ curl -X GET "http://192.168.1.100:19200/_snapshot/esbackup/_all?pretty"
{
"snapshots" : [
{
"snapshot" : "snapshot_20221212",
"uuid" : "mPLiQ-3rSpOLPy3c4TS8kQ",
"version_id" : 6050099,
"version" : "6.5.0",
"indices" : [
"child_inocexamine_student",
"reservation_new",
"child_inocexamine_vacc",
"orc_hospital_content",
"inoculate_new",
"vacc_update"
],
"include_global_state" : true,
"state" : "SUCCESS",
"start_time" : "2022-12-11T17:10:02.285Z",
"start_time_in_millis" : 1670778602285,
"end_time" : "2022-12-11T18:02:07.053Z",
"end_time_in_millis" : 1670781727053,
"duration_in_millis" : 3124768,
"failures" : [ ],
"shards" : {
"total" : 30,
"failed" : 0,
"successful" : 30
}
}
]
}
执行恢复
执行恢复
curl -XPOST http://172.17.10.80:19200/_snapshot/esbackup/snapshot_20221212/_restore?wait_for_completion=true
wait_for_completion选项是需要执行完成后才返回
查看恢复进度(具体索引)
curl -X GET 'http://192.168.1.100:19200/child_inocexamine_student/_recovery?pretty'
4.验证
[elasticsearch@localhost esbak]$ curl -X GET 'http://192.168.1.100:19200/_cat/indices?v'
5.记录数
curl -H "Content-Type: application/json" -XGET 'http://192.168.1.100:19200/_cat/count/reservation_new?v&format=json&pretty'
说明:
1.恢复的机器上建议使用大一些内存的机器,否则内存不够会把es进程kill掉
more /var/log/messages
Dec 12 11:44:02 hxl kernel: Out of memory: Kill process 4650 (java) score 837 or sacrifice child
2.添加交换分区
[root@hxl ~]# free -m
total used free shared buff/cache available
Mem: 7821 7498 134 0 188 94
Swap: 9694 189 9505
内存不够的情况下 使用交换分区
-- The End --