备份solr index数据文件分成两种方式:冷备份和热备份
冷备:
冷备份的方法和传统数据库一样,就是指关闭solr,然后将SOLR_HOME/data下面的所有数据拷贝到指定备份路径。
优点:
1.方法简单
2.index数据文件不会产生不一致
缺点:solr要关闭,数据量大,复制时间较长,生产环境不推荐。
热备:
利用Solr Replication Handler,通过浏览器或curl等工具发送一个request,网址为:http://master_server:port/solr/replication?command=backup
例如:
[root@test data]# curl http://192.168.20.168:8983/solr/chenfeng/replication?command=backup
<?xml version="1.0" encoding="UTF-8"?>
<response>
<lst name="responseHeader"><int name="status">0</int><int name="QTime">4</int></lst><str name="status">OK</str>
</response>
或通过浏览器访问:
状态ok表示备份成功
备份后生成的文件在solr的data目录里,例如:
[root@test topic]# ll /data/solr-6.2.1/server/solr/topic
total 16
drwxr-xr-x 3 root root 4096 Jan 29 14:02 conf
-rw-r--r-- 1 root root 75 Jan 29 14:18 core.properties
drwxr-xr-x 5 root root 4096 Jan 29 14:22 data
drwxr-xr-x 2 root root 4096 Jan 29 14:19 snapshot.20180129061937748
以snapshot开头的文件目录snapshot.20180129061937748就是备份后生成的目录。
目录里的文件列表为:
[root@test topic]# ll snapshot.20180129061937748/
total 4
-rw-r--r-- 1 root root 71 Jan 29 14:19 segments_1
联机热备恢复一例:
模拟solr故障,删除data目录的所有文件:
[root@test data]# rm -rf /data/solr-6.2.1/server/solr/topic/data/*
将snapshot.20180129061937748目录里的segments_1文件copy到数据文件路径下:
[root@test snapshot.20180129061937748]# cp segments_1 /data/solr-6.2.1/server/solr/topic/data/
[root@test snapshot.20180129061937748]# ll /data/solr-6.2.1/server/solr/topic/data
total 4
-rw-r--r-- 1 root root 71 Jan 29 14:49 segments_1
数据COPY完毕,重启solr
[root@test bin]# ./solr restart
NOTE: Please install lsof as this script needs it to determine if Solr is listening on port 8983.
Started Solr server on port 8983 (pid=5888). Happy searching!
检查solr状态:
[root@test bin]# ./solr status
Found 1 Solr nodes:
Solr process 5888 running on port 8983
{
"solr_home":"/data/solr-6.2.1/server/solr",
"version":"6.2.1 43ab70147eb494324a1410f7a9f16a896a59bc6f - shalin - 2016-09-15 05:20:53",
"startTime":"2018-01-29T06:52:09.810Z",
"uptime":"0 days, 0 hours, 0 minutes, 54 seconds",
"memory":"74.6 MB (%15.2) of 490.7 MB"}
solr页面正常