Imported Upstream version 3.1.0
[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 Program=`basename $0`
19
20 log () {
21         echo 1>&2 "$@"
22         return 0
23 }
24
25 Config=$1
26 if [ "$Config" = "" ]; then
27         log "usage: ${Program} <config>"
28         exit 1
29 fi
30 shift;
31
32 #
33 # Check if the configuration directory exists.  Make sure that the
34 # necessary files can be found, such as amanda.conf and tapelist.
35 #
36 if [ ! -d ${ConfigDir}/${Config} ]; then
37         log "${Program}: configuration directory ${ConfigDir}/${Config} does not exist."
38         exit 1
39 fi
40 (cd ${ConfigDir}/${Config} >/dev/null 2>&1) || exit $?
41 cd ${ConfigDir}/${Config}
42 if [ ! -r amanda.conf ]; then
43         log "${Program}: amanda.conf not found or is not readable in ${ConfigDir}."
44         exit 1
45 fi
46
47 # Get the location and name of the tapelist filename.  If tapelist is not
48 # specified in the amanda.conf file, then use tapelist in the config
49 # directory.
50 TapeList=`amgetconf${SUF} $Config tapelist "@$"`
51 if [ ! "$TapeList" ]; then
52         TapeList="$ConfigDir/$Config/tapelist"
53 fi
54 if [ ! -r $TapeList ]; then
55         log "${Program}: $TapeList not found or is not readable."
56         exit 1
57 fi
58
59 Amadmin=$sbindir/amadmin
60
61 [ ! -f $Amadmin ] \
62         && echo `_ '%s was not found' $Amadmin` >&2 \
63         && exit 1
64 [ ! -x $Amadmin ] \
65         && echo `_ '%s is not executable' $Amadmin` >&2 \
66         && exit 1
67
68 $Amadmin $Config export "$@"\
69         | grep "^stats: " \
70         | while read LINE; do
71                 [ "$LINE" = "" ] && continue
72                 set $LINE
73                 echo $8
74         done \
75         | sort -u \
76         | while read TAPE; do
77                 [ "$TAPE" = "" ] && continue
78                 grep " $TAPE " $TapeList 2>/dev/null >/dev/null
79                 [ $? != 0 ] \
80                         && echo `_ 'Tape %s missing in %s' "$TAPE" "$TapeList"`
81         done
82
83 echo `_ 'Ready.'`
84
85 exit 0