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

« back to all changes in this revision

Viewing changes to solr/scripts/snapcleaner

  • 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 snapshots 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 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
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
 
    if [[ "${OS}" == "Darwin" || "${OS}" == "FreeBSD" ]]
87
 
    then
88
 
     syncing=`ps -www -U ${user} |grep -w rsync|grep -v grep|grep -w $1`
89
 
    else
90
 
     syncing=`ps -fwwwu ${user}|grep -w rsync|grep -v grep|grep -w $1`
91
 
    fi
92
 
 
93
 
    if [[ -n $syncing ]]
94
 
    then
95
 
        logMessage $1 not removed - rsync in progress
96
 
    else
97
 
        logMessage removing snapshot $1
98
 
        /bin/rm -rf $1
99
 
    fi
100
 
}
101
 
 
102
 
setStartTime
103
 
 
104
 
logMessage started by $oldwhoami
105
 
logMessage command: $0 $@
106
 
 
107
 
# trap control-c
108
 
trap 'echo "caught INT/TERM, exiting now but partial cleanup may have already occured";logExit aborted 13' INT TERM
109
 
 
110
 
if [[ -n ${days} ]]
111
 
then
112
 
    #is maxdepth supported?
113
 
    find ${data_dir} -maxdepth 0 -name foobar >/dev/null 2>&1
114
 
    if [ $? = 0 ]; then
115
 
      maxdepth="-maxdepth 1"
116
 
    else
117
 
      unset maxdepth
118
 
    fi
119
 
 
120
 
    logMessage cleaning up snapshots more than ${days} days old
121
 
    for i in `find ${data_dir} ${maxdepth} -name 'snapshot.*' -mtime +${days} -print`
122
 
    do
123
 
        remove $i
124
 
    done
125
 
elif [[ -n ${num} ]]
126
 
then
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`
130
 
    if [[ $? == 0 ]]
131
 
    then
132
 
        count=`echo $snapshots|wc -w`
133
 
        startpos=`expr $num + 1`
134
 
        if [[ $count -gt $num ]]
135
 
        then
136
 
            for i in `echo $snapshots|cut -f${startpos}- -d" "`
137
 
            do
138
 
                remove $i
139
 
            done
140
 
        fi
141
 
    fi
142
 
fi
143
 
 
144
 
logExit ended 0
145
 
 
146