cd374aa97d668971f6cab4e213043a583def7098
[debian/amanda] / server-src / amcheckdb.sh.in
1 #! /bin/sh
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
36 #
37 # Check if the configuration directory exists.  Make sure that the
38 # necessary files can be found, such as amanda.conf and tapelist.
39 #
40 if [ ! -d ${ConfigDir}/${Config} ]; then
41         log "${Program}: configuration directory ${ConfigDir}/${Config} does not exist."
42         exit 1
43 fi
44 (cd ${ConfigDir}/${Config} >/dev/null 2>&1) || exit $?
45 cd ${ConfigDir}/${Config}
46 if [ ! -r amanda.conf ]; then
47         log "${Program}: amanda.conf not found or is not readable in ${ConfigDir}."
48         exit 1
49 fi
50
51 # Get the location and name of the tapelist filename.  If tapelist is not
52 # specified in the amanda.conf file, then use tapelist in the config
53 # directory.
54 TapeList=`amgetconf${SUF} tapelist`
55 if [ ! "$TapeList" ]; then
56         TapeList="$ConfigDir/$Config/tapelist"
57 fi
58 if [ ! -r $TapeList ]; then
59         log "${Program}: $TapeList not found or is not readable."
60         exit 1
61 fi
62
63 Amadmin=$sbindir/amadmin$SUF
64
65 [ ! -x $Amadmin ] \
66         && echo "$Amadmin not found or not executable" >&2 \
67         && exit 1
68
69 $Amadmin $Config export \
70         | grep "^stats: " \
71         | while read LINE; do
72                 [ "$LINE" = "" ] && continue
73                 set $LINE
74                 echo $8
75         done \
76         | sort -u \
77         | while read TAPE; do
78                 [ "$TAPE" = "" ] && continue
79                 grep " $TAPE " $TapeList 2>/dev/null >/dev/null
80                 [ $? != 0 ] \
81                         && echo "Tape $TAPE missing in $TapeList"
82         done
83
84 echo "Ready."
85
86 exit 0