#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Shell script to copy snapshots of a Solr Lucene collection from the master
orig_dir=$(pwd)
cd ${0%/*}/..
solr_root=$(pwd)
cd ${orig_dir}
# set up variables
# define usage string
USAGE="\
usage: $prog [-M master] [-P portnum] [-D mdir] [-S sdir] [-n snapshot] [-d dir] [-u username] [-svVz]
-M master specify hostname of master server from where to pull index
snapshot
-P port specify rsyncd port number of master server from where to
pull index snapshot
-D specify directory holding index data on master server
-S specify directory holding snapshot status on master server
-n snapshot pull a specific snapshot by name
-d specify directory holding index data on local machine
-u specify user to sudo to before running script
-s use the --size-only option with rsync
-v increase verbosity (-vv show file transfer stats also)
-V output debugging info
-z enable compression of data
"
# parse args
do
M)
;;
P)
;;
D)
;;
S)
;;
n)
;;
d)
;;
u)
;;
s)
sizeonly="--size-only"
;;
v)
;;
V)
debug="V"
;;
z)
compress="z"
;;
*)
echo "$USAGE"
exit 1
esac
done
[[ -n $debug ]] && set -x
if [[ -z ${master_host} ]]
then
echo "name of master server missing in $confFile or command line."
echo "$USAGE"
exit 1
fi
# try to determine rsyncd port number from $confFile if not specified on
# command line, default to solr_port+10000
if [[ -z ${rsyncd_port} ]]
then
if [[ "${solr_port}" ]]
then
rsyncd_port=`expr 10000 + ${solr_port}`
else
echo "rsyncd port number of master server missing in $confFile or command line."
echo "$USAGE"
exit 1
fi
fi
if [[ -z ${master_data_dir} ]]
then
echo "directory holding index data on master server missing in $confFile or command line."
echo "$USAGE"
exit 1
fi
if [[ -z ${master_status_dir} ]]
then
echo "directory holding snapshot status on master server missing in $confFile or command line."
echo "$USAGE"
exit 1
fi
fixUser "$@"
# assume relative path to start at ${solr_root}
then
fi
then
fi
function pushStatus
{
scp -q -o StrictHostKeyChecking=no ${solr_root}/logs/snappuller.status ${master_host}:${master_status_dir}/snapshot.status.`uname -n`
}
logMessage command: $0 $@
then
exit 2
fi
# make sure we can ssh to master
if
then
exit 1
fi
# get directory name of latest snapshot if not specified on command line
if [[ -z ${snap_name} ]]
then
snap_name=`ssh -o StrictHostKeyChecking=no ${master_host} "perl -e 'chdir q|${master_data_dir}|; print ((sort grep {/^snapshot[.][1-9][0-9]{13}$/} <*>)[-1])'"`
fi
if [[ "${snap_name}" == "" ]]
then
else
fi
trap 'echo cleaning up, please wait ...;/bin/rm -rf ${data_dir}/${name} ${data_dir}/${name}-wip;echo ${startStatus} aborted:$(timeStamp)>${solr_root}/logs/snappuller.status;pushStatus;logExit aborted 13' INT TERM
then
fi
# take a snapshot of current index so that only modified files will be rsync-ed
# put the snapshot in the 'work-in-progress" directory to prevent it from
# being installed while the copying is still in progress
if [[ "${OS}" == "SunOS" || "${OS}" == "Darwin" || "${OS}" == "FreeBSD" ]]
then
orig_dir=$(pwd)
cd ${orig_dir}
else
fi
# force rsync of segments and .del files since we are doing size-only
if [[ -n ${sizeonly} ]]
then
fi
# start new distribution stats
if [[ "${OS}" == "Darwin" || "${OS}" == "FreeBSD" ]]
then
else
fi
# rsync over files that have changed
rc=$?
if [[ "${OS}" == "Darwin" || "${OS}" == "FreeBSD" ]]
then
else
fi
if [[ $rc != 0 ]]
then
fi
# move into place atomically
# finish new distribution stats`
echo ${startStatus} ended:$endTimestamp rsync-elapsed:${elapsed} > ${solr_root}/logs/snappuller.status