031b91a62d25106ae69d4693475c79618dd5e884fielding# Licensed to the Apache Software Foundation (ASF) under one or more
031b91a62d25106ae69d4693475c79618dd5e884fielding# contributor license agreements. See the NOTICE file distributed with
031b91a62d25106ae69d4693475c79618dd5e884fielding# this work for additional information regarding copyright ownership.
031b91a62d25106ae69d4693475c79618dd5e884fielding# The ASF licenses this file to You under the Apache License, Version 2.0
031b91a62d25106ae69d4693475c79618dd5e884fielding# (the "License"); you may not use this file except in compliance with
031b91a62d25106ae69d4693475c79618dd5e884fielding# the License. You may obtain a copy of the License at
0b0582a3aa10227767e359e693c4b43fec272388nd# Unless required by applicable law or agreed to in writing, software
0b0582a3aa10227767e359e693c4b43fec272388nd# distributed under the License is distributed on an "AS IS" BASIS,
0b0582a3aa10227767e359e693c4b43fec272388nd# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0b0582a3aa10227767e359e693c4b43fec272388nd# See the License for the specific language governing permissions and
0b0582a3aa10227767e359e693c4b43fec272388nd# limitations under the License.
0b0582a3aa10227767e359e693c4b43fec272388nd# Shell script to clean up snapshots of a Solr Lucene collection.
0b0582a3aa10227767e359e693c4b43fec272388ndcd ${0%/*}/..
a546d8ff17af2eb98179377f39a02ac81459f0bend# set up variables
a546d8ff17af2eb98179377f39a02ac81459f0bend# define usage string
a546d8ff17af2eb98179377f39a02ac81459f0bendusage: $prog -D <days> | -N <num> [-d dir] [-u username] [-v] [-V]
a546d8ff17af2eb98179377f39a02ac81459f0bend -D <days> cleanup snapshots more than <days> days old
a546d8ff17af2eb98179377f39a02ac81459f0bend -N <num> keep the most recent <num> number of snapshots and
a546d8ff17af2eb98179377f39a02ac81459f0bend cleanup up the remaining ones that are not being pulled
a546d8ff17af2eb98179377f39a02ac81459f0bend -d specify directory holding index data
a546d8ff17af2eb98179377f39a02ac81459f0bend -u specify user to sudo to before running script
a546d8ff17af2eb98179377f39a02ac81459f0bend -v increase verbosity
a546d8ff17af2eb98179377f39a02ac81459f0bend -V output debugging info
a546d8ff17af2eb98179377f39a02ac81459f0bend# parse args
0b0582a3aa10227767e359e693c4b43fec272388nd[[ -n $debug ]] && set -x
ada7369deaf47fb16f6079f0c9af273f33050ff4nd syncing=`ps -www -U ${user} |grep -w rsync|grep -v grep|grep -w $1`
0b0582a3aa10227767e359e693c4b43fec272388nd syncing=`ps -fwwwu ${user}|grep -w rsync|grep -v grep|grep -w $1`
e5576107d28b5d7f76c4515e39f197e6b8bcba9and if [[ -n $syncing ]]
0b0582a3aa10227767e359e693c4b43fec272388nd# trap control-c
0b0582a3aa10227767e359e693c4b43fec272388ndtrap 'echo "caught INT/TERM, exiting now but partial cleanup may have already occured";logExit aborted 13' INT TERM
0b0582a3aa10227767e359e693c4b43fec272388ndif [[ -n ${days} ]]
0b0582a3aa10227767e359e693c4b43fec272388nd #is maxdepth supported?
ada7369deaf47fb16f6079f0c9af273f33050ff4nd find ${data_dir} -maxdepth 0 -name foobar >/dev/null 2>&1
ada7369deaf47fb16f6079f0c9af273f33050ff4nd if [ $? = 0 ]; then
0b0582a3aa10227767e359e693c4b43fec272388nd logMessage cleaning up snapshots more than ${days} days old
ada7369deaf47fb16f6079f0c9af273f33050ff4nd for i in `find ${data_dir} ${maxdepth} -name 'snapshot.*' -mtime +${days} -print`
0b0582a3aa10227767e359e693c4b43fec272388ndelif [[ -n ${num} ]]
0b0582a3aa10227767e359e693c4b43fec272388nd logMessage cleaning up all snapshots except for the most recent ${num} ones
61d237f7e3a54089a7514227d663fac296d7d8f0bnicholes snapshots=`find ${data_dir} -type d -name 'snapshot.*' 2>/dev/null| sort -r`
61d237f7e3a54089a7514227d663fac296d7d8f0bnicholes if [[ $? == 0 ]]