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