ec527b70a3ede0d1ca410ab4f6855f9704a1a468
[debian/amanda] / server-src / amcheckdb.sh
1 #! @SHELL@
2 #
3 # check tapelist against database and vice versa
4 #
5
6 prefix="@prefix@"
7 exec_prefix="@exec_prefix@"
8 sbindir="@sbindir@"
9 amlibexecdir="@amlibexecdir@"
10 . "${amlibexecdir}/amanda-sh-lib.sh"
11
12 ConfigDir=@CONFIG_DIR@
13
14 # add sbin and ucb dirs
15 PATH="$PATH:/usr/sbin:/sbin:/usr/ucb"
16 export PATH
17
18 USE_VERSION_SUFFIXES="@USE_VERSION_SUFFIXES@"
19 if test "$USE_VERSION_SUFFIXES" = "yes"; then
20         SUF="-@VERSION@"
21 else
22         SUF=
23 fi
24
25 Program=`basename $0`
26
27 log () {
28         echo 1>&2 "$@"
29         return 0
30 }
31
32 Config=$1
33 if [ "$Config" = "" ]; then
34         log "usage: ${Program} <config>"
35         exit 1
36 fi
37 shift;
38
39 #
40 # Check if the configuration directory exists.  Make sure that the
41 # necessary files can be found, such as amanda.conf and tapelist.
42 #
43 if [ ! -d ${ConfigDir}/${Config} ]; then
44         log "${Program}: configuration directory ${ConfigDir}/${Config} does not exist."
45         exit 1
46 fi
47 (cd ${ConfigDir}/${Config} >/dev/null 2>&1) || exit $?
48 cd ${ConfigDir}/${Config}
49 if [ ! -r amanda.conf ]; then
50         log "${Program}: amanda.conf not found or is not readable in ${ConfigDir}."
51         exit 1
52 fi
53
54 # Get the location and name of the tapelist filename.  If tapelist is not
55 # specified in the amanda.conf file, then use tapelist in the config
56 # directory.
57 TapeList=`amgetconf${SUF} $Config tapelist "@$"`
58 if [ ! "$TapeList" ]; then
59         TapeList="$ConfigDir/$Config/tapelist"
60 fi
61 if [ ! -r $TapeList ]; then
62         log "${Program}: $TapeList not found or is not readable."
63         exit 1
64 fi
65
66 Amadmin=$sbindir/amadmin$SUF
67
68 [ ! -f $Amadmin ] \
69         && echo `_ '%s was not found' $Amadmin` >&2 \
70         && exit 1
71 [ ! -x $Amadmin ] \
72         && echo `_ '%s is not executable' $Amadmin` >&2 \
73         && exit 1
74
75 $Amadmin $Config export "$@"\
76         | grep "^stats: " \
77         | while read LINE; do
78                 [ "$LINE" = "" ] && continue
79                 set $LINE
80                 echo $8
81         done \
82         | sort -u \
83         | while read TAPE; do
84                 [ "$TAPE" = "" ] && continue
85                 grep " $TAPE " $TapeList 2>/dev/null >/dev/null
86                 [ $? != 0 ] \
87                         && echo `_ 'Tape %s missing in %s' "$TAPE" "$TapeList"`
88         done
89
90 echo `_ 'Ready.'`
91
92 exit 0