[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Going back <n> records, using mt. (script included)



Hello,
	I've been working on a primitive backup script,
	that, using BRU backs up my root partition, and
	then other, more dynamic directories under a
	different 'file count' to a DAT tape.  At least
	that's the plan.

	Here's a basic layout of the program:
  1.  mt eof	( to 'append to a tape' )
  2.  Write "/"
  3.  Write 'dynamic' directories
  4.  go back 2 records ( I use mt bsf 2, but that
      doesn't work... )
  5.  Invoke BRU's integrity-checking for "/"
  6.  Invoke BRU's integrity-checking for 'dynamic' dirs.
  	
	After step "2", should I write a file 'mark' with
	some mt option?

	What's the correct command for going back 2 'files'?
	
	Would it be better if I use SCSI-specific
	commands like fss, bss?

	Any comments on the script itself?  I used so
	many 'variables', because the script is easier
	adapted to other machines easier that way.  Am I
	wrong?


Thank you,

Nikita.

P.s.  CC'd replies to list are appreciated.


#!/bin/bash
########################################################
# Name:		Backup                                 #
# Description:	uses BRU to backup the system.  Script #
#		splits the "/" filesystem, apart from  #
#		more 'dynamic' parts, which are backed #
#		up separately.                         #
# Author:	Nikita S. Imennov                      #
#		<nimennor@ieaccess.net>                #
# Date Started:	Fri Feb 19 14:25:23 EST 1999           #
# Last Edit:	Fri Feb 19 14:25:49 EST 1999           #
########################################################

## COMMAND-RELATED VARIABLES ##
MT="/bin/mt"
BRU="/bin/bru"
bruArgs="cvvvvBGf"

TAIL="/usr/bin/tail"
tailArgs="-20"

MAIL="/usr/bin/mail"
mailTo="root"

## SETS ##
primarySet=("/")			# Primary set, #1
excludeDirs=("/work" "/archives")	# Secondary set, #2


## LOG FILES ##
systemLog="/var/log/bruexeclog"		# System's account of events
backupLog="/tmp/.backup$$"		# Our account of what happened.


## OTHER VARIABLES ##
DEVICE="/dev/nst0"			# DON'T CHANGE IT TO A REWINDING DEV!!!
excludeFile="bruxpat.local"


### FUNCTIONS DECLARED FIRST ###

################################################################
# Function:	version()                                      #
# Arguments:	none                                           #
# Purpose:	display vesion info, obtained from CVS's tag   #
#                                                              #
################################################################
function version()
{
	version="\$Id: backup.script,v 1.9 1999/02/21 18:28:57 nimennor Exp $"
	echo "$version"
}


################################################################
# Function:	usage()                                        #
# Arguments:	none                                           #
# Purpose:	display elementary help screen                 #
#                                                              #
################################################################
function usage()
{
	version
	echo "Backup the system, using BRU" >&2
}


################################################################
# Function:	creatExclude()                                 #
# Arguments:	none                                           #
# Purpose:	create $excludeFile (default: excludeFile.local),  #
# 		that is to be used for BRU backup.             #
#                                                              #
################################################################
function creatExclude()
{
	rm -f $excludeFile			# remove any previous files

	# Create default exclude file

	cat > $excludeFile <<\EOBXP
xs	*/core			# No cores
xs	core
xs	*/core
xs	./usr/tmp/*		# All tmp directories
xs	/usr/tmp/*
xs	./tmp/*
xs	/tmp/*
xs	/mnt/*			# All mounted dirs
xs	/proc			# Ignore '/proc', just to be safe
zs	*.[Zz]			# Don't compress already compressed files
zs	*.gz
zs	*.tgz
EOBXP
	
	# Now, add a 'customised' set of directories to ignore.
	for dir in ${excludeDirs[@]}
	do
		echo "xs $dir/*" >> $excludeFile
	done

	# Export the exclude file's location, so that BRU can read it.
	BRUXPAT=$excludeFile
	export BRUXPAT
}


function backup()
{
	#### REAL CODE (tm) STARTS HERE ####

	$MT -f $DEVICE eom			# rewind to the end of media

	creatExclude				# create excludes...

	# Backup primary set, and hold off on ${excludeDirs[@]}
	$BRU -$bruArgs $DEVICE -X ${primarySet[@]}


	### APPEND THE EXCLUDED DIRECTORIES ###
	$BRU -$bruArgs $DEVICE ${excludeDirs[@]}


	### REWIND THE TAPE FOR DOUBLE-CHECK ###

	$MT -f $DEVICE bsf 2		# THAT's the trick, right here!
					# mt rewinds 2 file counts BACK!!!
					# alas, it doesn't work!!!

	$BRU -if $DEVICE		# Check tape's integrity
	ERROR1=$?
	$BRU -if $DEVICE
	ERROR2=$?

	$MT -f $DEVICE rewind		# Rewind, since we're done.

	cat > $backupLog <<\EOBM
The BRU segregated backup finished with the following results:

EOBM

	if [ $ERROR1 == 1 ] ; then
		echo "CRC Errors were discovered in backup set #1" >> $backupLog
		echo "SET #1 contains:" >> $backupLog
		for dir in ${primarySet[@]}
			do
				echo "\t$dir" >> $excludeFile
			done
	fi

	if [ $ERROR2 == 1 ] ; then
		echo "CRC Errors were discovered in backup set #2" >> $backupLog
		echo "SET #2 contains:" >> $backupLog
		for dir in ${excludeDirs[@]}
			do
				echo "\t$dir" >> $excludeFile
			done
	fi

	#
	# Tail the 'summary' from BRU's system log for completeness
	# 
	$TAIL $tailArgs $systemLog >> $backupLog
	
	#
	# Mail the summary to appropriate users
	#
	$MAIL -s "BRU: Execution report" $mailTo < $backupLog
	
	#
	# Remove any by-products
	#
	rm -f $backupLog
	rm -f $excludeFile
	
	exit 0
}

###### READ THE ARGUMENTS, DECIDE WHAT TO DO #####
while getopts "hv" opt; do
	case "$opt" in
	h)	usage; exit 0;;
	v)	version; exit 0;;
	*)	echo "No such parameter!" 1>&2 ; exit 2;;
	esac
done

echo "Started: `date`"
echo -n "Backing up..."
backup
echo "Done."


Reply to: