~slub.team/goobi-indexserver/3.x

« back to all changes in this revision

Viewing changes to solr/scripts/abc

  • Committer: Sebastian Meyer
  • Date: 2012-08-03 09:12:40 UTC
  • Revision ID: sebastian.meyer@slub-dresden.de-20120803091240-x6861b0vabq1xror
Remove Lucene and Solr source code and add patches instead
Fix Bug #985487: Auto-suggestion for the search interface

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/bin/bash
2
 
#
3
 
# Licensed to the Apache Software Foundation (ASF) under one or more
4
 
# contributor license agreements.  See the NOTICE file distributed with
5
 
# this work for additional information regarding copyright ownership.
6
 
# The ASF licenses this file to You under the Apache License, Version 2.0
7
 
# (the "License"); you may not use this file except in compliance with
8
 
# the License.  You may obtain a copy of the License at
9
 
#
10
 
#     http://www.apache.org/licenses/LICENSE-2.0
11
 
#
12
 
# Unless required by applicable law or agreed to in writing, software
13
 
# distributed under the License is distributed on an "AS IS" BASIS,
14
 
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 
# See the License for the specific language governing permissions and
16
 
# limitations under the License.
17
 
#
18
 
# Shell script to make an Atomic Backup after Commit of
19
 
# a Solr Lucene collection.
20
 
 
21
 
orig_dir=$(pwd)
22
 
cd ${0%/*}/..
23
 
solr_root=$(pwd)
24
 
cd ${orig_dir}
25
 
curl_url=""
26
 
 
27
 
unset solr_hostname solr_port data_dir webapp_name user verbose debug solr_url
28
 
. ${solr_root}/bin/scripts-util
29
 
 
30
 
# set up variables
31
 
prog=${0##*/}
32
 
log=${solr_root}/logs/${prog}.log
33
 
 
34
 
# define usage string
35
 
USAGE="\
36
 
usage: $prog [-h hostname] [-p port] [-d dir] [-w webapp_name] [-u username] [-U url] [-v] [-V]
37
 
       -h          specify Solr hostname (defaults to localhost)
38
 
       -p          specify Solr port number
39
 
       -w          specify name of Solr webapp (defaults to solr)
40
 
       -u          specify user to sudo to before running script
41
 
       -U          specify full update url (overrides -h,-p,-w parameters)
42
 
       -d          specify directory holding index data (defaults to data)
43
 
       -v          increase verbosity
44
 
       -V          output debugging info
45
 
"
46
 
 
47
 
# parse args
48
 
while getopts h:p:d:w:u:U:vV OPTION
49
 
do
50
 
    case $OPTION in
51
 
    h)
52
 
        solr_hostname="$OPTARG"
53
 
        ;;
54
 
    p)
55
 
        solr_port="$OPTARG"
56
 
        ;;
57
 
    d)
58
 
        data_dir="$OPTARG"
59
 
        ;;
60
 
    w)
61
 
        webapp_name="$OPTARG"
62
 
        ;;
63
 
    u)
64
 
        user="$OPTARG"
65
 
        ;;
66
 
    U)
67
 
        solr_url="$OPTARG"
68
 
        ;;
69
 
    v)
70
 
        verbose="v"
71
 
        ;;
72
 
    V)
73
 
        debug="V"
74
 
        ;;
75
 
    *)
76
 
        echo "$USAGE"
77
 
        exit 1
78
 
    esac
79
 
done
80
 
 
81
 
[[ -n $debug ]] && set -x
82
 
 
83
 
dataDir
84
 
 
85
 
curlUrl
86
 
 
87
 
fixUser "$@"
88
 
 
89
 
setStartTime
90
 
 
91
 
logMessage started by $oldwhoami
92
 
logMessage command: $0 $@
93
 
 
94
 
logMessage sending commit to Solr server at ${curl_url}
95
 
rs=`curl ${curl_url} -s -H 'Content-type:text/xml; charset=utf-8' -d "<commit/>"`
96
 
if [[ $? != 0 ]]
97
 
then
98
 
  logMessage failed to connect to Solr server at ${curl_url}
99
 
  logMessage commit failed
100
 
  logExit failed 1
101
 
fi
102
 
 
103
 
# check status of commit request - original format
104
 
echo $rs | grep '<result.*status="0"' > /dev/null 2>&1
105
 
if [[ $? != 0 ]]
106
 
then
107
 
# check status of commit request - new format
108
 
  echo $rs | grep '<lst name="responseHeader"><int name="status">0</int>' > /dev/null 2>&1
109
 
  if [[ $? != 0 ]]
110
 
  then
111
 
    logMessage commit request to Solr at ${curl_url} failed:
112
 
    logMessage $rs
113
 
    logExit failed 2
114
 
  fi
115
 
fi
116
 
 
117
 
# successful commit creates a snapshot file synchronously
118
 
lastsnap=`find ${data_dir} -type d -name 'snapshot.*' 2>/dev/null| sort -r | head -1`
119
 
 
120
 
if [[ $lastsnap == "" ]]
121
 
then
122
 
  logMessage commit did not create snapshot at ${curl_url}, backup failed:
123
 
  logExit failed 3
124
 
fi
125
 
 
126
 
name=backup.${lastsnap##*snapshot.}
127
 
temp=temp-${name}
128
 
 
129
 
if [[ -d ${data_dir}/${name} ]]
130
 
then
131
 
    logMessage backup directory ${data_dir}/${name} already exists
132
 
    logExit aborted 1
133
 
fi
134
 
 
135
 
if [[ -d ${data_dir}/${temp} ]]
136
 
then
137
 
    logMessage backingup of ${data_dir}/${name} in progress
138
 
    logExit aborted 1
139
 
fi
140
 
logMessage making backup ${data_dir}/${name}
141
 
 
142
 
# clean up after INT/TERM
143
 
trap 'echo cleaning up, please wait ...;/bin/rm -rf ${data_dir}/${name} ${data_dir}/${temp};logExit aborted 13' INT TERM
144
 
 
145
 
# make a backup using hard links into temporary location
146
 
# then move it into place atomically
147
 
if [[ "${OS}" == "SunOS" || "${OS}" == "Darwin" || "${OS}" == "FreeBSD" ]]
148
 
then
149
 
  orig_dir=$(pwd)
150
 
  mkdir ${data_dir}/${temp}
151
 
  cd ${lastsnap}
152
 
  find . -print|cpio -pdlmu ${data_dir}/${temp} 1>/dev/null 2>&1
153
 
  cd ${orig_dir}
154
 
else
155
 
  cp -lr ${lastsnap} ${data_dir}/${temp}
156
 
fi
157
 
mv ${data_dir}/${temp} ${data_dir}/${name}
158
 
 
159
 
logExit ended 0