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 libexecdir=@libexecdir@
39 ConfigDir=@CONFIG_DIR@
41 PATH=$sbindir:$libexecdir:/usr/bin:/bin:/usr/sbin:/sbin:/usr/ucb
44 USE_VERSION_SUFFIXES="@USE_VERSION_SUFFIXES@"
45 if test "$USE_VERSION_SUFFIXES" = "yes"; then
54 [ "xyes" = "x${DebugMode}" ] && set -x
57 # Check if the configuration directory exists. Make sure that the
58 # necessary files can be found, such as amanda.conf and tapelist.
60 if [ ! -d ${ConfigDir}/${Config} ]; then
61 log "${Program}: configuration directory ${ConfigDir}/${Config} does not exist."
64 (cd ${ConfigDir}/${Config} >/dev/null 2>&1) || return $?
65 cd ${ConfigDir}/${Config}
66 if [ ! -r amanda.conf ]; then
67 log "${Program}: amanda.conf not found or is not readable in ${ConfigDir}."
71 dumpuser=`amgetconf$SUF dumpuser`
73 if [ $runuser != $dumpuser ]; then
74 log "${Program}: must be run as user $dumpuser"
78 # Get the location and name of the tapelist filename. If tapelist is not
79 # specified in the amanda.conf file, then use tapelist in the config
81 TapeList=`amgetconf${SUF} tapelist`
82 if [ ! "$TapeList" ]; then
83 TapeList="$ConfigDir/$Config/tapelist"
85 if [ ! -r $TapeList ]; then
86 log "${Program}: $TapeList not found or is not readable."
90 # Get the location and name of the database filename.
91 InfoFile=`amgetconf${SUF} infofile`
92 if [ ! "$InfoFile" ]; then
93 log "${Program}: unable to find name of infofile from ${ConfigDir}/${Config}/amanda.conf."
96 VarDir=`echo "$InfoFile" | sed -e 's%^[^/]*$%.%' -e 's%/[^/]*$%%'`
98 # Check that the database directory and files really exist.
99 if [ ! -d "${VarDir}" ]; then
100 log "${Program}: ${VarDir} does not exist or is not a directory."
103 for dbext in @DB_EXT@; do
104 if [ ! -r ${InfoFile}${dbext} ] && [ ! -d ${InfoFile}${dbext} ]; then
105 log "${Program}: ${InfoFile}${dbext} does not exist or is not readable."
110 if [ ! -d @AMANDA_TMPDIR@ ]; then
111 log "${Program}: directory @AMANDA_TMPDIR@ does not exist."
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 "${Program}: remove label ${Tape}."
137 log "${Program}: no such tape: ${Tape}."
147 [ "xyes" = "x${DebugMode}" ] && set -x
148 (cd ${VarDir} >/dev/null 2>&1) || return $?
150 InfoFileBase=`echo $InfoFile | sed -e 's%.*/%%g'`
152 TmpSrc=$InfoFileBase.orig.$$
153 TmpDest=$InfoFileBase.new.$$
154 rm -f ${TmpSrc} ${TmpDest}
155 amadmin${SUF} ${Config} export > ${TmpSrc} || return $?
156 log "${Program}: preserving original database in ${TmpSrc} (exported)."
157 exec < ${TmpSrc} > ${TmpDest} || return $?
161 CURINFO*|"#"*|command*|last_level*|consecutive_runs*|full*|incr*)
176 if [ $# -lt 6 ] || [ $# -gt 8 ]; then
177 log "${Program}: unexpected number of fields in 'stats' entry for ${Host}:${Disk}."
183 if [ "${CurrentTape}" = "${Tape}" ]; then
185 ${Verbose} "Discarding Host: ${Host}, Disk: ${Disk}, Level: ${Level}"
186 elif [ $Level -gt $DeadLevel ]; then
187 ${Verbose} "Discarding Host: ${Host}, Disk: ${Disk}, Level: ${Level}"
201 log "Error: unrecognized line of input: \"${Line}\""
205 exec < /dev/tty > /dev/tty
207 if [ "xno" = "x${DoNothing}" ]; then
209 amadmin${SUF} ${Config} import < ${TmpDest} &&
224 echo "${Program} [-n] [-v] [-q] [-d] <configuration> <label>"
225 echo " -n Do nothing to original files, leave new ones in database directory."
226 echo " -v Verbose, list backups of hosts and disks that are being discarded."
227 echo " -q Quiet, opposite of -v."
228 echo " -d Enable debug tracing."
229 echo "This program allows you to invalidate the contents of an existing"
230 echo "backup tape within the Amanda current tape database. This is meant as"
231 echo "a recovery mecanism for when a good backup is damaged either by faulty"
232 echo "hardware or user error, i.e. the tape is eaten by the tape drive, or"
233 echo "the tape has been overwritten."
243 while shift 2>/dev/null; do
270 ( CleanTapelist && CleanCurinfo )