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 backups 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 backups more than <days> days old
36
-N <num> keep the most recent <num> number of backups 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
logMessage removing backup $1
92
logMessage started by $oldwhoami
93
logMessage command: $0 $@
96
trap 'echo "caught INT/TERM, exiting now but partial cleanup may have already occured";logExit aborted 13' INT TERM
100
#is maxdepth supported?
101
find ${data_dir} -maxdepth 0 -name foobar >/dev/null 2>&1
103
maxdepth="-maxdepth 1"
108
logMessage cleaning up backups more than ${days} days old
109
for i in `find ${data_dir} ${maxdepth} -name 'backup.*' -mtime +${days} -print`
115
logMessage cleaning up all backups except for the most recent ${num} ones
117
backups=`find ${data_dir} -type d -name 'backup.*' 2>/dev/null| sort -r`
120
count=`echo $backups|wc -w`
121
startpos=`expr $num + 1`
122
if [[ $count -gt $num ]]
124
for i in `echo $backups|cut -f${startpos}- -d" "`