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
10
# http://www.apache.org/licenses/LICENSE-2.0
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.
18
# Shell script to make an Atomic Backup after Commit of
19
# a Solr Lucene collection.
27
unset solr_hostname solr_port data_dir webapp_name user verbose debug solr_url
28
. ${solr_root}/bin/scripts-util
32
log=${solr_root}/logs/${prog}.log
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)
44
-V output debugging info
48
while getopts h:p:d:w:u:U:vV OPTION
52
solr_hostname="$OPTARG"
81
[[ -n $debug ]] && set -x
91
logMessage started by $oldwhoami
92
logMessage command: $0 $@
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/>"`
98
logMessage failed to connect to Solr server at ${curl_url}
99
logMessage commit failed
103
# check status of commit request - original format
104
echo $rs | grep '<result.*status="0"' > /dev/null 2>&1
107
# check status of commit request - new format
108
echo $rs | grep '<lst name="responseHeader"><int name="status">0</int>' > /dev/null 2>&1
111
logMessage commit request to Solr at ${curl_url} failed:
117
# successful commit creates a snapshot file synchronously
118
lastsnap=`find ${data_dir} -type d -name 'snapshot.*' 2>/dev/null| sort -r | head -1`
120
if [[ $lastsnap == "" ]]
122
logMessage commit did not create snapshot at ${curl_url}, backup failed:
126
name=backup.${lastsnap##*snapshot.}
129
if [[ -d ${data_dir}/${name} ]]
131
logMessage backup directory ${data_dir}/${name} already exists
135
if [[ -d ${data_dir}/${temp} ]]
137
logMessage backingup of ${data_dir}/${name} in progress
140
logMessage making backup ${data_dir}/${name}
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
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" ]]
150
mkdir ${data_dir}/${temp}
152
find . -print|cpio -pdlmu ${data_dir}/${temp} 1>/dev/null 2>&1
155
cp -lr ${lastsnap} ${data_dir}/${temp}
157
mv ${data_dir}/${temp} ${data_dir}/${name}