70a0a7f5ad289a25d28d6a967c03055bef20faf6
[debian/amanda] / server-src / amdump.sh~HEAD
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 amlibexecdir="@amlibexecdir@"
37 . "${amlibexecdir}/amanda-sh-lib.sh"
38
39 confdir=@CONFIG_DIR@
40
41 # add sbin and ucb dirs
42 PATH="$PATH:/usr/sbin:/sbin:/usr/ucb"
43 export PATH
44
45 USE_VERSION_SUFFIXES="@USE_VERSION_SUFFIXES@"
46 if test "$USE_VERSION_SUFFIXES" = "yes"; then
47         SUF="-@VERSION@"
48 else
49         SUF=
50 fi
51
52 if [ $# -lt 1 ]
53 then
54 <<<<<<< HEAD:server-src/amdump.sh.in
55         echo "Usage: amdump config [host [disk...]...]" 1>&2
56 =======
57         echo `_ 'Usage: %s config [host [disk...]...]' "$0"`  1>&2
58 >>>>>>> upstream:server-src/amdump.sh
59         exit 1
60 fi
61
62 exit_status=0;
63
64 conf=$1
65 if [ ! -d $confdir/$conf ]; then
66 <<<<<<< HEAD:server-src/amdump.sh.in
67     echo "amdump$SUF: could not find directory $confdir/$conf" 1>&2
68 =======
69     echo `_ '%s: could not find directory %s' "amdump$SUF" "$confdir/$conf"` 1>&2
70 >>>>>>> upstream:server-src/amdump.sh
71     exit 1
72 fi
73 shift
74
75 cd $confdir/$conf || exit 1
76
77 logdir=`amgetconf$SUF $conf logdir "$@"`
78 [ $? -ne 0 ]  && exit 1
79 errfile=$logdir/amdump
80 tapecycle=`amgetconf$SUF $conf tapecycle "$@"`
81 [ $? -ne 0 ]  && exit 1
82 dumpuser=`amgetconf$SUF $conf dumpuser "$@"`
83 [ $? -ne 0 ]  && exit 1
84
85 runuser=`{ whoami ; } 2>/dev/null`
86 if [ $? -ne 0 ]; then
87         idinfo=`{ id ; } 2>/dev/null`
88         if [ $? -ne 0 ]; then
89                 runuser=${LOGNAME:-"??unknown??"}
90         else
91                 runuser=`echo $idinfo | sed -e 's/).*//' -e 's/^.*(//'`
92         fi
93 fi
94
95 <<<<<<< HEAD:server-src/amdump.sh.in
96 #if [ $runuser != $dumpuser ]; then
97 #       echo "amdump: must be run as user $dumpuser, not $runuser" 1>&2
98 #       exit 1
99 #fi
100
101 if test -f hold; then
102         echo "amdump: waiting for hold file to be removed" 1>&2
103 =======
104 if [ $runuser != $dumpuser ]; then
105         echo `_ '%s: must be run as user %s, not %s' "$0" "$dumpuser" "$runuser"` 1>&2
106         exit 1
107 fi
108
109 if test -f hold; then
110         echo `_ '%s: waiting for hold file to be removed' "$0"` 1>&2
111 >>>>>>> upstream:server-src/amdump.sh
112         while test -f hold; do
113                 sleep 60
114         done
115 fi
116
117 if test -f $errfile || test -f $logdir/log; then
118 <<<<<<< HEAD:server-src/amdump.sh.in
119         echo "amdump: amdump or amflush is already running, or you must run amcleanup" 1>&2
120 =======
121         echo `_ '%s: amdump or amflush is already running, or you must run amcleanup' "$0"` 1>&2
122 >>>>>>> upstream:server-src/amdump.sh
123         exit 1
124 fi
125
126 umask 077
127
128 exit_code=0
129 # Plan and drive the dumps.
130 #exec </dev/null >$errfile 2>&1
131 touch $errfile
132 exit_code=$?
133 [ $exit_code -ne 0 ] && exit_status=$exit_code
134 exec </dev/null 2>>$errfile 1>&2
135 exit_code=$?
136 [ $exit_code -ne 0 ] && exit_status=$exit_code
137 <<<<<<< HEAD:server-src/amdump.sh.in
138 echo "amdump: start at `date`"
139 echo "amdump: datestamp `date +%Y%m%d`"
140 echo "amdump: starttime `date +%Y%m%d%H%M%S`"
141 $libexecdir/planner$SUF $conf "$@" | $libexecdir/driver$SUF $conf "$@"
142 exit_code=$?
143 [ $exit_code -ne 0 ] && exit_status=$exit_code
144 echo "amdump: end at `date`"
145 =======
146
147 gdate=`date +'%a %b %e %H:%M:%S %Z %YAAAAA%Y%m%dBBBBB%Y%m%d%H%M%SCCCCC%Y-%m-%d %H:%M:%S %Z'`
148
149 #date=%a %b %e %H:%M:%S %Z %Y
150 date=`echo $gdate |sed -e "s/AAAAA.*$//"`
151
152 #date_datestamp="%Y%m%d"
153 date_datestamp=`echo $gdate |sed -e "s/^.*AAAAA//;s/BBBBB.*$//"`
154
155 #date_starttime="%Y%m%d%H%M%S"
156 date_starttime=`echo $gdate |sed -e "s/^.*BBBBB//;s/CCCCC.*$//"`
157
158 #date_locale_independent=%Y-%m-%d %H:%M:%S %Z
159 date_locale_independent=`echo $gdate |sed -e "s/^.*CCCCC//"`
160
161 printf '%s: start at %s\n' "amdump" "$date"
162 printf '%s: datestamp %s\n' "amdump" "$date_datestamp"
163 printf '%s: starttime %s\n' "amdump" "$date_starttime"
164 printf '%s: starttime-locale-independent %s\n' "amdump" "$date_locale_independent"
165
166 $amlibexecdir/planner$SUF $conf --starttime $date_starttime "$@" | $amlibexecdir/driver$SUF $conf "$@"
167 exit_code=$?
168 [ $exit_code -ne 0 ] && exit_status=$exit_code
169 printf '%s: end at %s\n' "amdump" "`date`"
170 >>>>>>> upstream:server-src/amdump.sh
171
172 # Send out a report on the dumps.
173 $sbindir/amreport$SUF $conf "$@"
174 exit_code=$?
175 [ $exit_code -ne 0 ] && exit_status=$exit_code
176
177 # Roll the log file to its datestamped name.
178 <<<<<<< HEAD:server-src/amdump.sh.in
179 $libexecdir/amlogroll$SUF $conf "$@"
180 =======
181 $amlibexecdir/amlogroll$SUF $conf "$@"
182 >>>>>>> upstream:server-src/amdump.sh
183 exit_code=$?
184 [ $exit_code -ne 0 ] && exit_status=$exit_code
185
186 # Trim the log file to those for dumps that still exist.
187 <<<<<<< HEAD:server-src/amdump.sh.in
188 $libexecdir/amtrmlog$SUF $conf "$@"
189 =======
190 $amlibexecdir/amtrmlog$SUF $conf "$@"
191 >>>>>>> upstream:server-src/amdump.sh
192 exit_code=$?
193 [ $exit_code -ne 0 ] && exit_status=$exit_code
194
195 # Trim the index file to those for dumps that still exist.
196 <<<<<<< HEAD:server-src/amdump.sh.in
197 $libexecdir/amtrmidx$SUF $conf "$@"
198 =======
199 $amlibexecdir/amtrmidx$SUF $conf "$@"
200 >>>>>>> upstream:server-src/amdump.sh
201 exit_code=$?
202 [ $exit_code -ne 0 ] && exit_status=$exit_code
203
204 # Keep a debug log through the tapecycle plus a couple of days.
205 maxdays=`expr $tapecycle + 2`
206 days=1
207 # First, find out the last existing errfile,
208 # to avoid ``infinite'' loops if tapecycle is infinite
209 while [ $days -lt $maxdays ] && [ -f $errfile.$days ]; do
210         days=`expr $days + 1`
211 done
212 # Now, renumber the existing log files
213 while [ $days -ge 2 ]; do
214         ndays=`expr $days - 1`
215         mv $errfile.$ndays $errfile.$days
216         exit_code=$?
217         echo $exit_code
218         [ $exit_code -ne 0 ] && exit_status=$exit_code
219         days=$ndays
220 done
221 mv $errfile $errfile.1
222 exit_code=$?
223 [ $exit_code -ne 0 ] && exit_status=$exit_code
224
225 exit $exit_status