v15i023: Tools to help find files on backup tapes

Rich Salz rsalz at uunet.uu.net
Wed Jun 1 06:06:04 AEST 1988


Submitted-by: Clyde Hoover <ut-sally!ut-emx!clyde>
Posting-number: Volume 15, Issue 23
Archive-name: whichtape

[  For BSD-based backup and restore.  --r$  ]

Storetape and whichtape are tools I cobbled together a couple of years
ago to facilitiate backup restores.   Rather than have to mount a bunch
of incremental tapes to find out which one a particular file was on,
these shell scripts impliment a simple data base which contains the table
of contents of each backup tape.

#	This is a shell archive.
#	Remove everything above and including the cut line.
#	Then run the rest of the file through sh.
-----cut here-----cut here-----cut here-----cut here-----
#!/bin/sh
# shar:	Shell Archiver
#	Run the following text with /bin/sh to create:
#	README
#	storetape.8
#	storetape.sh
#	whichtape.8
#	whichtape.sh
cat << \SHAR_EOF > README
Storetape & whichtape README

Storetape and whichtape are tools I cobbled together a couple of years
ago to facilitiate backup restores.   Rather than have to mount a bunch
of incremental tapes to find out which one a particular file was on,
these shell scripts impliment a simple data base which contains the table
of contents of each backup tape.

The data base is created by storetape and access by whichtape.
The data files are compressed to save disk space and since they should
not be accessed very often, so the compression/decompression time to
disk space tradeoff is reasonable.

For incremental dumps, a 'restore t' was done on each backup tape right
after the dump was done.  This table of contents is fed to storetape.
This also verifies that the tape just written can be read, at least up
to the directory information.

For level 0 dumps which span several tape reels, this method is impractical.
Instead 'ncheck -i' is used to generate a list of file names.
Any program or method which generates a list of names in a file tree
would provide proper input for storetape.

These scripts leave their database in the current directory.
Customization of that is left to the installer.

	Clyde Hoover
	Computation Center
	The University of Texas at Austin
	Austin, Texas 78712
	(512) 471-3241
	clyde at emx.utexas.edu
	uunet!ut-sally!ut-emx!clyde
SHAR_EOF
cat << \SHAR_EOF > storetape.8
.\" @(#)storetape.8	1.1 10/13/86 (cc.utexas.edu)
.TH STORETAPE 8
.SH NAME
storetape \- remember contents of backup tape
.SH SYNOPSIS
.B storetape
\fB-d\fP filesystem \fB-t\fP tape-name \fB-l\fP dump-level [ \fB-f\fP file ]
.SH DESCRIPTION
.I Storetape
takes as input a list of files from either
.IR restore (8)
or
.IR ncheck (8)
and enters it in a tape backup data base.
This data base is accessed by
.IR whichtape (8).
.PP
The options are:
.TP 15 10
-d filesystem
Indicates the file system that this is the list of.
.TP 15 10
-t tape-name
Is the name of the backup tape.
.TP 15 10
-l dump-level
Is the dump level of the tape.
.TP 15 10
-f file
Is the input file.
If none is specified, then the standard input is used.
.PP
The information from the 
.B -d
and
.B -l
arguments are used to construct the name of the data base files.
There is one set of data base files per file system per dump level.
.SH FILES
FilesystemLevel.C - tape data base control file
.br
FilesystemLevel.D - tape data base data file
.SH "SEE ALSO"
whichtape(8), ncheck(8), restore(8)
SHAR_EOF
cat << \SHAR_EOF > storetape.sh
#! /bin/sh
#
#	storetape - store backup tape list in backups data base
#
#	Usage: storetape -t tape_name -l dump_level -d file_system
#		[-f input_file]
#	If input_file is not given, then standard input is read.
#	Input must be a list of file names.
#
Usage="Usage: $0 [-f file] -t tape_name -l dump_flags -d file_system"
if [ $# -lt 6 ]; then
	echo $Usage
	exit 1
fi

Compressor=compress		# CONFIG
FileSystem=""
TapeName=""
DumpFlags=""
InputFile=""

#
#	Parse arguments
#
argx=""
for a do
	case $a in
	-d* || -t* || -l* || -f*)
		argx=$a
		;;
	-*)
		echo Unknown argument $a
		exit 1
		;;
	*)
		case "$argx" in
		-d) 	FileSystem=$a ;;
		-t)	TapeName=$a ;;
		-l)	DumpFlags=$a ;;
		-f)	InputFile=$a ;;
		*)	echo $Usage; exit 1 ;;
		esac
		argx=""
	esac
done

#
# Generate backup data base filename
#
fslabel=`echo $FileSystem | tr -d /`			# Remove slashes
dbname=$fslabel.$DumpFlags				# Generate name

#
# Generate control file 
#
cat > $dbname.C <<!
$dbname
$FileSystem
$TapeName
$DumpFlags
`date`
!
#
# Compact input data into data base
#
(if [ -n "$InputFile" ]; then
	cat $InputFile 
else
	cat
fi) | $Compressor -c  > $dbname.D 2>/dev/null
chmod 0644 $dbname.?
exit 0
#
# End
#
SHAR_EOF
cat << \SHAR_EOF > whichtape.8
.\" @(#)whichtape.8	1.1 10/13/86 (cc.utexas.edu)
.TH WHICHTAPE 8
.SH NAME
whichtape \- locate file(s) on backup tapes
.SH SYNOPSIS
.B /etc/whichtape
file-name ... [ file-name ]
.SH DESCRIPTION
.I Whichtape
scans the backup tape directory created by
.I storetape
and finds which backup tape(s)
.I file-name
are on.
Filenames are relative paths, so
.I /u0/cc/foobar
are stored as
.IR ./cc/foobar .
.I File-name
can be any match pattern acceptable to
.IR egrep (1).
Metacharacters must be quoted.
.SH FILES
FilesystemLevel.C - tape data base control file
.br
FilesystemLevel.D - tape data base data file
.SH "SEE ALSO"
storetape(8), egrep(1)
SHAR_EOF
cat << \SHAR_EOF > whichtape.sh
#! /bin/sh
#
#	whichtape - locate file(s) in backup data base
#
#	Usage: whichtape path-name
#
if [ $# -lt 1 ]; then
	echo "Usage: $0 path-name ... path-name"
	exit 1
fi
Uncompress=zcat			# CONFIG
sed=/tmp/lookdb$$		# Sed script file

trap "rm -f $sed.?; exit 1" 2 3

#
#	Sed script to crack the control files
#
cat >$sed.A <<"!"
1s/.*/stem=&/
2s/.*/filesys=&/
3s/.*/tapename="&"/
4s/.*/dumplevel="&"/
5s/.*/tdate="&"/
!

#
#	Step through control files
#
for bf in *.C; do
	stem=""
	eval `sed -f $sed.A $bf`	# Get data from control file
	if [ "$stem" = "" ]; then
		echo Format error in control file $bf !!
		continue
	fi
	cat > $sed.B <<!		# Sed script to post-process grep output
s@^@($tapename)	@
s@\$@	$tdate@
!
	#
	# Step through file arguments
	#
	for file do
		trap "break" 2		# Intr to next file
		if [ ! -r $stem.D ]; then
			echo Data file $stem.D missing!
		else
			$Uncompress $stem.D | egrep $file | sed -f $sed.B
		fi
	done
	trap "rm -f $sed.?; exit 1" 2 3		# Restore global intr behavior
done
# Cleanup
rm -f $sed.?
exit 0
#
# End
#
SHAR_EOF
#	End of shell archive
exit 0
-- 
Shouter-To-Dead-Parrots @ Univ. of Texas Computation Center; Austin, Texas  
	clyde at ngp.utexas.edu; ...!ut-sally!ut-ngp!clyde
"It's a sort of a threat, you see.  I've never been very good at them
myself, but I've told they can be very effective."

-- 
Please send comp.sources.unix-related mail to rsalz at uunet.uu.net.



More information about the Comp.sources.unix mailing list