~slub.team/goobi-indexserver/3.x

« back to all changes in this revision

Viewing changes to solr/scripts/backupcleaner

  • Committer: Sebastian Meyer
  • Date: 2012-08-03 09:12:40 UTC
  • Revision ID: sebastian.meyer@slub-dresden.de-20120803091240-x6861b0vabq1xror
Remove Lucene and Solr source code and add patches instead
Fix Bug #985487: Auto-suggestion for the search interface

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/bin/bash
2
 
#
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
9
 
#
10
 
#     http://www.apache.org/licenses/LICENSE-2.0
11
 
#
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.
17
 
#
18
 
# Shell script to clean up backups of a Solr Lucene collection.
19
 
 
20
 
orig_dir=$(pwd)
21
 
cd ${0%/*}/..
22
 
solr_root=$(pwd)
23
 
cd ${orig_dir}
24
 
 
25
 
unset days num data_dir user verbose debug
26
 
. ${solr_root}/bin/scripts-util
27
 
 
28
 
# set up variables
29
 
prog=${0##*/}
30
 
log=${solr_root}/logs/${prog}.log
31
 
 
32
 
# define usage string
33
 
USAGE="\
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
40
 
       -v          increase verbosity
41
 
       -V          output debugging info
42
 
"
43
 
 
44
 
# parse args
45
 
while getopts D:N:d:u:vV OPTION
46
 
do
47
 
    case $OPTION in
48
 
    D)
49
 
        days="$OPTARG"
50
 
        ;;
51
 
    N)
52
 
        num="$OPTARG"
53
 
        ;;
54
 
    d)
55
 
        data_dir="$OPTARG"
56
 
        ;;
57
 
    u)
58
 
        user="$OPTARG"
59
 
        ;;
60
 
    v)
61
 
        verbose="v"
62
 
        ;;
63
 
    V)
64
 
        debug="V"
65
 
        ;;
66
 
    *)
67
 
        echo "$USAGE"
68
 
        exit 1
69
 
    esac
70
 
done
71
 
 
72
 
[[ -n $debug ]] && set -x
73
 
 
74
 
if [[ -z ${days} && -z ${num} ]]
75
 
then
76
 
    echo "$USAGE"
77
 
    exit 1
78
 
fi
79
 
 
80
 
fixUser "$@"
81
 
 
82
 
dataDir
83
 
 
84
 
function remove
85
 
{
86
 
    logMessage removing backup $1
87
 
    /bin/rm -rf $1
88
 
}
89
 
 
90
 
setStartTime
91
 
 
92
 
logMessage started by $oldwhoami
93
 
logMessage command: $0 $@
94
 
 
95
 
# trap control-c
96
 
trap 'echo "caught INT/TERM, exiting now but partial cleanup may have already occured";logExit aborted 13' INT TERM
97
 
 
98
 
if [[ -n ${days} ]]
99
 
then
100
 
    #is maxdepth supported?
101
 
    find ${data_dir} -maxdepth 0 -name foobar >/dev/null 2>&1
102
 
    if [ $? = 0 ]; then
103
 
      maxdepth="-maxdepth 1"
104
 
    else
105
 
      unset maxdepth
106
 
    fi
107
 
  
108
 
    logMessage cleaning up backups more than ${days} days old
109
 
    for i in `find ${data_dir} ${maxdepth} -name 'backup.*' -mtime +${days} -print`
110
 
    do
111
 
        remove $i
112
 
    done
113
 
elif [[ -n ${num} ]]
114
 
then
115
 
    logMessage cleaning up all backups except for the most recent ${num} ones
116
 
    unset backups count
117
 
    backups=`find ${data_dir} -type d -name 'backup.*' 2>/dev/null| sort -r`
118
 
    if [[ $? == 0 ]]
119
 
    then
120
 
        count=`echo $backups|wc -w`
121
 
        startpos=`expr $num + 1`
122
 
        if [[ $count -gt $num ]]
123
 
        then
124
 
            for i in `echo $backups|cut -f${startpos}- -d" "`
125
 
            do
126
 
                remove $i
127
 
            done
128
 
        fi
129
 
    fi
130
 
fi
131
 
 
132
 
logExit ended 0
133
 
 
134