5fc55cbfc93618b21d6c10bd1ad89ec33823cbb7
[debian/amanda] / server-src / amcleanup.sh.in
1 #!/bin/sh
2 #
3 # Amanda, The Advanced Maryland Automatic Network Disk Archiver
4 # Copyright (c) 1991-1998 University of Maryland at College Park
5 # All Rights Reserved.
6 #
7 # Permission to use, copy, modify, distribute, and sell this software and its
8 # documentation for any purpose is hereby granted without fee, provided that
9 # the above copyright notice appear in all copies and that both that
10 # copyright notice and this permission notice appear in supporting
11 # documentation, and that the name of U.M. not be used in advertising or
12 # publicity pertaining to distribution of the software without specific,
13 # written prior permission.  U.M. makes no representations about the
14 # suitability of this software for any purpose.  It is provided "as is"
15 # without express or implied warranty.
16 #
17 # U.M. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
18 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL U.M.
19 # BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
20 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
21 # OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
22 # CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
23 #
24 # Author: James da Silva, Systems Design and Analysis Group
25 #                          Computer Science Department
26 #                          University of Maryland at College Park
27 #
28
29 #
30 # amcleanup.sh - clean up and generate a report after a crash.
31
32 # try to hit all the possibilities here
33 prefix=@prefix@
34 exec_prefix=@exec_prefix@
35 libexecdir=@libexecdir@
36 sbindir=@sbindir@
37
38 confdir=@CONFIG_DIR@
39
40 PATH=$sbindir:$libexecdir:/usr/bin:/bin:/usr/sbin:/sbin:/usr/ucb
41 export PATH
42
43 USE_VERSION_SUFFIXES="@USE_VERSION_SUFFIXES@"
44 if test "$USE_VERSION_SUFFIXES" = yes; then
45         SUF=-@VERSION@
46 else
47         SUF=
48 fi
49
50 if [ $# -ne 1 ]
51 then
52         echo "Usage: amcleanup conf"
53         exit 1
54 fi
55
56 conf=$1
57 if [ ! -d $confdir/$conf ]; then
58         echo "amcleanup: could not cd into $confdir/$conf"
59         exit 1
60 fi
61
62 cd $confdir/$conf
63
64 logdir=`amgetconf$SUF logdir`
65 [ $? -ne 0 ]  && exit 1
66 logfile=$logdir/log
67 errfile=$logdir/amdump
68 erramflush=$logdir/amflush
69 tapecycle=`amgetconf$SUF tapecycle`
70
71 if [ -f $logfile ]; then
72         lognotfound=0
73
74         echo "amcleanup: processing outstanding log file."
75         exec </dev/null >/dev/null 2>&1
76         amreport$SUF $conf
77
78         # Roll the log file to its datestamped name.
79         amlogroll$SUF $conf
80
81         # Trim the index file to those for dumps that still exist.
82         amtrmidx$SUF $conf
83
84 else
85         echo "amcleanup: no unprocessed logfile to clean up."
86
87         lognotfound=1
88 fi
89
90 if [ -f $errfile ]; then
91     # if log was found, this will have been directed to /dev/null,
92     # which is fine.
93     echo "amcleanup: $errfile exists, renaming it."
94
95     # Keep debug log through the tapecycle plus a couple days
96     maxdays=`expr $tapecycle + 2`
97
98     days=1
99     # First, find out the last existing errfile,
100     # to avoid ``infinite'' loops if tapecycle is infinite
101     while [ $days -lt $maxdays ] && [ -f $errfile.$days ]; do
102         days=`expr $days + 1`
103     done
104     # Now, renumber the existing log files
105     while [ $days -ge 2 ]; do
106         ndays=`expr $days - 1`
107         mv $errfile.$ndays $errfile.$days
108         days=$ndays
109     done
110     mv $errfile $errfile.1
111 fi
112
113 if [ -f $erramflush ]; then
114     # if log was found, this will have been directed to /dev/null,
115     # which is fine.
116     echo "amcleanup: $erramflush exists, renaming it."
117
118     # Keep debug log through the tapecycle plus a couple days
119     maxdays=`expr $tapecycle + 2`
120
121     days=1
122     # First, find out the last existing erramflush,
123     # to avoid ``infinite'' loops if tapecycle is infinite
124     while [ $days -lt $maxdays ] && [ -f $erramflush.$days ]; do
125         days=`expr $days + 1`
126     done
127     # Now, renumber the existing log files
128     while [ $days -ge 2 ]; do
129         ndays=`expr $days - 1`
130         mv $erramflush.$ndays $erramflush.$days
131         days=$ndays
132     done
133     mv $erramflush $erramflush.1
134 fi
135
136 $libexecdir/amcleanupdisk $conf
137
138 exit $lognotfound