Line 0
Link Here
|
0 |
- |
1 |
#!/usr/bin/zsh |
|
|
2 |
|
3 |
# Copyright 2011 BibLibre SARL |
4 |
# This file is part of Koha. |
5 |
# |
6 |
# Koha is free software; you can redistribute it and/or modify it under the |
7 |
# terms of the GNU General Public License as published by the Free Software |
8 |
# Foundation; either version 2 of the License, or (at your option) any later |
9 |
# version. |
10 |
# |
11 |
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY |
12 |
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR |
13 |
# A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
14 |
# |
15 |
# You should have received a copy of the GNU General Public License along |
16 |
# with Koha; if not, write to the Free Software Foundation, Inc., |
17 |
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
18 |
|
19 |
|
20 |
INCREMENT=$1 |
21 |
BIBLIOSTART=$2 |
22 |
BIBLIOEND=$3 |
23 |
|
24 |
#echo " | $INCREMENT , $BIBLIOSTART , $BIBLIOEND | "; |
25 |
# this script rebuild the zebra index recursively |
26 |
# BIBLIOSTART is the record number to BIBLIOSTART on |
27 |
# BIBLIOEND is the record number to BIBLIOEND on |
28 |
# increment specify how many records we must try at once |
29 |
# At the BIBLIOEND of each "chunk", this script checks if the indexing process has been OK |
30 |
# if it hasn't, the slice is splitted in 10, and the reindexing is called again on each smaller chunk |
31 |
# if the increment goes to 1, it means we tried to reindex 1 by 1, and the failing indexing concern wrong records |
32 |
|
33 |
# the logs are stored in a directory called logs/ that must be a subdirectory of reindex.zsh |
34 |
|
35 |
# at the BIBLIOEND of the script, just type : |
36 |
#grep -l "previous transaction" `ls rebuild1.*.err` |
37 |
# the result contains all the biblios that have not been indexed |
38 |
# WARNING : the numbers are not the biblionumber but the record number, they can be reached by : |
39 |
# SELECT biblionumber FROM biblio LIMIT YourNumberHere,1; |
40 |
|
41 |
# EXAMPLE to run the script on a 800 000 biblios database : |
42 |
# ./reindex.zsh 50000 0 800000 |
43 |
# will reindex the DB, BIBLIOSTARTing with chunks of 50k biblios |
44 |
#if { grep -E "previous transaction" `dirname $0`/logs/rebuild$INCREMENT.$i.err } ; then |
45 |
|
46 |
lastbiblionumber=`perl -e '#!/usr/bin/perl |
47 |
use C4::Context; |
48 |
my $dbh = C4::Context->dbh; |
49 |
my $querylastbiblionumber = "SELECT max(biblionumber) FROM biblio;"; |
50 |
my $sthlastbiblionumber = $dbh->prepare($querylastbiblionumber); |
51 |
$sthlastbiblionumber->execute(); |
52 |
my ( $lastbiblionumber ) = $sthlastbiblionumber->fetchrow_array; print $lastbiblionumber;'` |
53 |
#echo $lastbiblionumber; |
54 |
let "maxbiblionumber = $lastbiblionumber + 1" |
55 |
if [ $# = 2 ] |
56 |
then |
57 |
BIBLIOEND=$lastbiblionumber |
58 |
elif [ $# = 1 ] |
59 |
then |
60 |
BIBLIOSTART=0 |
61 |
BIBLIOEND=$lastbiblionumber |
62 |
elif [ $# = 0 ] |
63 |
then |
64 |
INCREMENT=10000 |
65 |
BIBLIOSTART=0 |
66 |
BIBLIOEND=$lastbiblionumber |
67 |
fi |
68 |
if [[ $INCREMENT =~ ^10*$ ]] |
69 |
then |
70 |
else |
71 |
echo "The first argument (INCREMENT) must be 1 or a multiple of 10" |
72 |
exit 2 |
73 |
fi |
74 |
if [[ $BIBLIOSTART =~ ^[0-9]*$ ]] |
75 |
then |
76 |
else |
77 |
echo "The second argument (BIBLIOSTART) must be an integer" |
78 |
exit 2 |
79 |
fi |
80 |
if [[ $BIBLIOEND =~ ^[0-9]*$ ]] |
81 |
then |
82 |
else |
83 |
echo "The third argument (BIBLIOEND) must be an integer" |
84 |
exit 2 |
85 |
fi |
86 |
if [ $BIBLIOSTART -lt $BIBLIOEND ] |
87 |
then |
88 |
else |
89 |
echo "The second argument (BIBLIOSTART) must be lower than the third argument (BIBLIOEND)" |
90 |
exit 2 |
91 |
fi |
92 |
if [ $BIBLIOEND -lt $maxbiblionumber ] |
93 |
then |
94 |
else |
95 |
echo "end" |
96 |
exit 1 |
97 |
fi |
98 |
ls `dirname $0`/logs/ >/dev/null 2>&1 |
99 |
if [ $? != 0 ] |
100 |
then |
101 |
mkdir `dirname $0`/logs |
102 |
else |
103 |
rm `dirname $0`/logs/* |
104 |
fi |
105 |
#/home/koha/src/misc/migration_tools/rebuild_zebra.pl -r -b -v -x -nosanitize -offset 1 -length 1 |
106 |
for ((i=$BIBLIOSTART ; i<$BIBLIOEND ; i=i+$INCREMENT)) |
107 |
do |
108 |
echo "I = " $i "with increment " $INCREMENT |
109 |
`dirname $0`/rebuild_zebra.pl -b -v -x -nosanitize -d /tmp/rebuild -k -offset $INCREMENT -length $i > `dirname $0`/logs/rebuild$INCREMENT.$i.log 2> `dirname $0`/logs/rebuild$INCREMENT.$i.err |
110 |
if (($INCREMENT >1 )); |
111 |
then |
112 |
if { grep -q "previous transaction" `dirname $0`/logs/rebuild$INCREMENT.$i.err } ; |
113 |
then |
114 |
echo "I must split $i (increment $INCREMENT) because previous transaction didn't reach commit" |
115 |
((subincrement=$INCREMENT/10)) |
116 |
((newBIBLIOEND=$i+$INCREMENT)) |
117 |
$0 $subincrement $i $newBIBLIOEND |
118 |
elif { ! grep -q "Records: $INCREMENT" `dirname $0`/logs/rebuild$INCREMENT.$i.err } ; |
119 |
then |
120 |
echo "I must split $i (increment $INCREMENT) because index was uncomplete, less than $INCREMENT records indexed" |
121 |
((subincrement=$INCREMENT/10)) |
122 |
((newBIBLIOEND=$i+$INCREMENT)) |
123 |
$0 $subincrement $i $newBIBLIOEND |
124 |
fi |
125 |
fi |
126 |
done |
127 |
exit 0 |