4 # Time-stamp: <96/10/23 12:07:21 adrian>
5 # Copyright 1996, Adrian Filipi-Martin
9 # Summary: This script allow you to invalidate the contents of an
10 # existing backup tape within the Amanda current tape database. This
11 # is meant as a recovery mecanism for when a good backup is damaged
12 # either by faulty hardware or user error, i.e. the tape is eaten by
13 # the tape drive, or the tape has been overwritten.
15 # To remove a tape you must specify the Amanda configuration to
16 # operate upon as well as the name of the tape. e.g.
18 # amrmtape nvl NVL-006
20 # N.B. amrmtape must be run as a user that can read the tape database
21 # files and rewrite them.
23 # Usage: amrmtape [-n] [-v] [-q] [-d] <configuration> <label>
24 # -n Do nothing to original files, leave new ones in --with-tmpdir
26 # -v Verbose mode. Enabled by default.
27 # -q Quiet (opposite of -v).
28 # -d Enable debug tracing.
30 # Credits: The what-to-do algorithm was provided by Cedric Scott,
31 # cedric.scott@sse.ie.
35 exec_prefix="@exec_prefix@"
37 amlibexecdir="@amlibexecdir@"
38 . "${amlibexecdir}/amanda-sh-lib.sh"
40 ConfigDir=@CONFIG_DIR@
42 # add sbin and ucb dirs
43 PATH="$PATH:/usr/sbin:/sbin:/usr/ucb"
46 USE_VERSION_SUFFIXES="@USE_VERSION_SUFFIXES@"
47 if test "$USE_VERSION_SUFFIXES" = "yes"; then
56 [ "xyes" = "x${DebugMode}" ] && set -x
59 # Check if the configuration directory exists. Make sure that the
60 # necessary files can be found, such as amanda.conf and tapelist.
62 if [ ! -d ${ConfigDir}/${Config} ]; then
63 log `_ '%s: configuration directory %s does not exist.' "$0" "${ConfigDir}/${Config}"`
66 (cd ${ConfigDir}/${Config} >/dev/null 2>&1) || return $?
67 cd ${ConfigDir}/${Config}
68 if [ ! -r amanda.conf ]; then
69 log `_ '%s: amanda.conf not found or is not readable in %s.' "$0" "${ConfigDir}"`
73 dumpuser=`amgetconf$SUF dumpuser`
75 if [ $runuser != $dumpuser ]; then
76 log `_ '%s: must be run as user %s' "$0" "$dumpuser"`
80 # Get the location and name of the tapelist filename. If tapelist is not
81 # specified in the amanda.conf file, then use tapelist in the config
83 TapeList=`amgetconf${SUF} tapelist`
84 if [ ! "$TapeList" ]; then
85 TapeList="$ConfigDir/$Config/tapelist"
87 if [ ! -r $TapeList ]; then
88 log `_ '%s: %s not found or is not readable.' "$0" "$TapeList"`
92 # Get the location and name of the database filename.
93 InfoFile=`amgetconf${SUF} infofile`
94 if [ ! "$InfoFile" ]; then
95 log `_ '%s: unable to find name of infofile from %s.' "$0" "${ConfigDir}/${Config}/amanda.conf"`
98 VarDir=`echo "$InfoFile" | sed -e 's%^[^/]*$%.%' -e 's%/[^/]*$%%'`
100 # Check that the database directory and files really exist.
101 if [ ! -d "${VarDir}" ]; then
102 log `_ '%s: %s does not exist or is not a directory.' "$0" "${VarDir}"`
105 if [ ! -r "${InfoFile}" ] && [ ! -d "${InfoFile}" ]; then
106 log `_ '%s: %s does not exist or is not readable.' "${Program}" "${InfoFile}"`
110 if [ ! -d @AMANDA_TMPDIR@ ]; then
111 log `_ '%s: directory %s does not exist.' "$0" "@AMANDA_TMPDIR@"`
115 NewTapelist=@AMANDA_TMPDIR@/tapelist
117 awk "\$2 == \"${Tape}\" { next; } { print; }" \
118 > ${NewTapelist} < $TapeList ||
120 if [ "xno" = "x${DoNothing}" ]; then
121 lines=`wc -l < $TapeList`
122 linesafter=`wc -l < $NewTapelist`
123 if [ "$lines" -gt "$linesafter" ]; then
124 cp -p $TapeList ${TapeList}~ && (
125 if test "$lines" -gt 1; then
126 [ -s ${NewTapelist} ] &&
127 cp ${NewTapelist} $TapeList &&
130 [ -f ${NewTapelist} ] &&
131 cp ${NewTapelist} $TapeList &&
135 log `_ '%s: remove label %s.' "$0" "${Tape}"`
137 log `_ '%s: no such tape: %s.' "$0" "${Tape}"`
146 CleanCurinfo_internal() {
150 CURINFO*|"#"*|command*|last_level*|consecutive_runs*|full*|incr*)
165 if [ $# -lt 6 ] || [ $# -gt 8 ]; then
166 log `_ '%s: unexpected number of fields in "stats" entry for %s.' "${Program}" "${Host}:${Disk}"`
172 if [ "${CurrentTape}" = "${Tape}" ]; then
174 ${Verbose} "Discarding Host: ${Host}, Disk: ${Disk}, Level: ${Level}"
175 elif [ $Level -gt $DeadLevel ]; then
176 ${Verbose} "Discarding Host: ${Host}, Disk: ${Disk}, Level: ${Level}"
190 log `_ 'Error: unrecognized line of input: "%s"' "${Line}"`
197 [ "xyes" = "x${DebugMode}" ] && set -x
198 (cd ${VarDir} >/dev/null 2>&1) || return $?
200 InfoFileBase=`echo $InfoFile | sed -e 's%.*/%%g'`
202 TmpSrc=$InfoFileBase.orig.$$
203 TmpDest=$InfoFileBase.new.$$
204 rm -f ${TmpSrc} ${TmpDest}
205 amadmin${SUF} ${Config} export > ${TmpSrc} || return $?
206 log `_ '%s: preserving original database in %s (exported).' "$0" "${TmpSrc}"`
207 CleanCurinfo_internal < ${TmpSrc} > ${TmpDest} || return $?
209 if [ "xno" = "x${DoNothing}" ]; then
211 amadmin${SUF} ${Config} import < ${TmpDest} &&
226 echo `_ '%s [-n] [-v] [-q] [-d] <configuration> <label>' "${Program}"`
227 echo `_ ' -n Do nothing to original files, leave new ones in database directory.'`
228 echo `_ ' -v Verbose, list backups of hosts and disks that are being discarded.'`
229 echo `_ ' -q Quiet, opposite of -v.'`
230 echo `_ ' -d Enable debug tracing.'`
231 echo `_ 'This program allows you to invalidate the contents of an existing
232 backup tape within the Amanda current tape database. This is meant
233 as a recovery mecanism for when a good backup is damaged either by
234 faulty hardware or user error, i.e. the tape is eaten by the tape drive,
235 or the tape has been overwritten.'`
245 while shift 2>/dev/null; do
272 ( CleanTapelist && CleanCurinfo )