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 clean up snapshots of a Solr Lucene collection.
25
unset days num data_dir user verbose debug
26
. ${solr_root}/bin/scripts-util
30
log=${solr_root}/logs/${prog}.log
34
usage: $prog -D <days> | -N <num> [-d dir] [-u username] [-v] [-V]
35
-D <days> cleanup snapshots more than <days> days old
36
-N <num> keep the most recent <num> number of snapshots and
37
cleanup up the remaining ones that are not being pulled
38
-d specify directory holding index data
39
-u specify user to sudo to before running script
41
-V output debugging info
45
while getopts D:N:d:u:vV OPTION
72
[[ -n $debug ]] && set -x
74
if [[ -z ${days} && -z ${num} ]]
86
if [[ "${OS}" == "Darwin" || "${OS}" == "FreeBSD" ]]
88
syncing=`ps -www -U ${user} |grep -w rsync|grep -v grep|grep -w $1`
90
syncing=`ps -fwwwu ${user}|grep -w rsync|grep -v grep|grep -w $1`
95
logMessage $1 not removed - rsync in progress
97
logMessage removing snapshot $1
104
logMessage started by $oldwhoami
105
logMessage command: $0 $@
108
trap 'echo "caught INT/TERM, exiting now but partial cleanup may have already occured";logExit aborted 13' INT TERM
112
#is maxdepth supported?
113
find ${data_dir} -maxdepth 0 -name foobar >/dev/null 2>&1
115
maxdepth="-maxdepth 1"
120
logMessage cleaning up snapshots more than ${days} days old
121
for i in `find ${data_dir} ${maxdepth} -name 'snapshot.*' -mtime +${days} -print`
127
logMessage cleaning up all snapshots except for the most recent ${num} ones
128
unset snapshots count
129
snapshots=`find ${data_dir} -type d -name 'snapshot.*' 2>/dev/null| sort -r`
132
count=`echo $snapshots|wc -w`
133
startpos=`expr $num + 1`
134
if [[ $count -gt $num ]]
136
for i in `echo $snapshots|cut -f${startpos}- -d" "`