Imported Upstream version 2.5.2p1
[debian/amanda] / server-src / amdump.sh.in
1 #!@SHELL@
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 # amdump: Manage running one night's Amanda dump run.
31 #
32
33 prefix=@prefix@
34 exec_prefix=@exec_prefix@
35 sbindir=@sbindir@
36 libexecdir=@libexecdir@
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 [ $# -lt 1 ]
51 then
52         echo "Usage: amdump config [host [disk...]...]" 1>&2
53         exit 1
54 fi
55
56 exit_status=0;
57
58 conf=$1
59 if [ ! -d $confdir/$conf ]; then
60     echo "amdump$SUF: could not find directory $confdir/$conf" 1>&2
61     exit 1
62 fi
63 shift
64
65 cd $confdir/$conf || exit 1
66
67 logdir=`amgetconf$SUF $conf logdir "$@"`
68 [ $? -ne 0 ]  && exit 1
69 errfile=$logdir/amdump
70 tapecycle=`amgetconf$SUF $conf tapecycle "$@"`
71 [ $? -ne 0 ]  && exit 1
72 dumpuser=`amgetconf$SUF $conf dumpuser "$@"`
73 [ $? -ne 0 ]  && exit 1
74
75 runuser=`{ whoami ; } 2>/dev/null`
76 if [ $? -ne 0 ]; then
77         idinfo=`{ id ; } 2>/dev/null`
78         if [ $? -ne 0 ]; then
79                 runuser=${LOGNAME:-"??unknown??"}
80         else
81                 runuser=`echo $idinfo | sed -e 's/).*//' -e 's/^.*(//'`
82         fi
83 fi
84
85 #if [ $runuser != $dumpuser ]; then
86 #       echo "amdump: must be run as user $dumpuser, not $runuser" 1>&2
87 #       exit 1
88 #fi
89
90 if test -f hold; then
91         echo "amdump: waiting for hold file to be removed" 1>&2
92         while test -f hold; do
93                 sleep 60
94         done
95 fi
96
97 if test -f $errfile || test -f $logdir/log; then
98         echo "amdump: amdump or amflush is already running, or you must run amcleanup" 1>&2
99         exit 1
100 fi
101
102 umask 077
103
104 exit_code=0
105 # Plan and drive the dumps.
106 #exec </dev/null >$errfile 2>&1
107 touch $errfile
108 exit_code=$?
109 [ $exit_code -ne 0 ] && exit_status=$exit_code
110 exec </dev/null 2>>$errfile 1>&2
111 exit_code=$?
112 [ $exit_code -ne 0 ] && exit_status=$exit_code
113 echo "amdump: start at `date`"
114 echo "amdump: datestamp `date +%Y%m%d`"
115 echo "amdump: starttime `date +%Y%m%d%H%M%S`"
116 $libexecdir/planner$SUF $conf "$@" | $libexecdir/driver$SUF $conf "$@"
117 exit_code=$?
118 [ $exit_code -ne 0 ] && exit_status=$exit_code
119 echo "amdump: end at `date`"
120
121 # Send out a report on the dumps.
122 $sbindir/amreport$SUF $conf "$@"
123 exit_code=$?
124 [ $exit_code -ne 0 ] && exit_status=$exit_code
125
126 # Roll the log file to its datestamped name.
127 $libexecdir/amlogroll$SUF $conf "$@"
128 exit_code=$?
129 [ $exit_code -ne 0 ] && exit_status=$exit_code
130
131 # Trim the log file to those for dumps that still exist.
132 $libexecdir/amtrmlog$SUF $conf "$@"
133 exit_code=$?
134 [ $exit_code -ne 0 ] && exit_status=$exit_code
135
136 # Trim the index file to those for dumps that still exist.
137 $libexecdir/amtrmidx$SUF $conf "$@"
138 exit_code=$?
139 [ $exit_code -ne 0 ] && exit_status=$exit_code
140
141 # Keep a debug log through the tapecycle plus a couple of days.
142 maxdays=`expr $tapecycle + 2`
143 days=1
144 # First, find out the last existing errfile,
145 # to avoid ``infinite'' loops if tapecycle is infinite
146 while [ $days -lt $maxdays ] && [ -f $errfile.$days ]; do
147         days=`expr $days + 1`
148 done
149 # Now, renumber the existing log files
150 while [ $days -ge 2 ]; do
151         ndays=`expr $days - 1`
152         mv $errfile.$ndays $errfile.$days
153         exit_code=$?
154         echo $exit_code
155         [ $exit_code -ne 0 ] && exit_status=$exit_code
156         days=$ndays
157 done
158 mv $errfile $errfile.1
159 exit_code=$?
160 [ $exit_code -ne 0 ] && exit_status=$exit_code
161
162 exit $exit_status