From: thad@public.BTR.COM (Thaddeus P. Floryan)
Newsgroups: comp.sys.sun.admin
Subject: Re: Friendly dump script for Sparc?
Keywords: dump backup
Date: 12 Apr 92 05:28:06 GMT
Organization: BTR Public Access UNIX, Mountain View CA

In article <1992Apr10.150943.21448@ux1.cso.uiuc.edu> drw41888@uxa.cso.uiuc.edu (?) writes:
>Can anyone out there direct me toward a somewhat user-"friendly" script
>to do directory and/or file system dumps to a tape drive?
>
>I'm running on a SparcStationSLC with a 1/4" Falcon Systems tape drive, 
>which uses Sony QD-600A tapes. (12500 ftpi). (at least, this is what
>the administration has been giving me.)  I'm able to run the dump that
>is on the Sun right now with no problems, but figure that there has to be
>someoone out there who has created a script which will prompt you for
>necessary information. (ie:filesystem/directory, back-up device, etc.)


You may find the enclosed useful as a starting point for both full and
incremental backups.  Note I use dump for "full" backups and cpio for my
incrementals.

I use these same scripts both on my work and home systems.

The FULL-BACKUP script permits use of either /dev/rst8 or /dev/rst9 (though
the script shown is from my home system); on some of the office systems, I
use QIC-150 drives simply because of the media cost to backup 1+GB systems.

The INCR-BACKUP script assumes a 60MB QIC-24 drive.  Note that its output
is extremely verbose since I intended it for use in batch with email sent
to root upon completion; its verbosity makes it easy to scan by me, and its
output could even be replayed.

Note that the INCR-BACKUP also uses two "custom" programs: foldest and fnewest.
Those simply return the mtime oldest/newest file name of all the files given
as command line arguments and we're just quick hacks of another program I
posted ages ago.

Both scripts are easy to reconfigure/adapt for your needs.  Enjoy!

Thad Floryan [ thad@btr.com (OR) {decwrl, mips, fernwood}!btr!thad ]

---- Cut Here and feed the following to sh ----
#!/bin/sh
# This is a shell archive (produced by shar 3.49)
# To extract the files from this archive, save it to a file, remove
# everything above the "!/bin/sh" line above, and type "sh file_name".
#
# made 04/12/1992 05:28 UTC by thad@cosmic
# Source directory /tmp
#
# existing files will NOT be overwritten unless -c is specified
#
# This shar contains:
# length  mode       name
# ------ ---------- ------------------------------------------
#   3246 -rwxr----- FULL-BACKUP
#   2231 -rwxr----- INCR-BACKUP
#    910 -rw-r----- fnewest.c
#    918 -rw-r----- foldest.c
#
if touch 2>&1 | fgrep 'amc' > /dev/null
 then TOUCH=touch
 else TOUCH=true
fi
# ============= FULL-BACKUP ==============
if test -f 'FULL-BACKUP' -a X"$1" != X"-c"; then
	echo 'x - skipping FULL-BACKUP (File already exists)'
else
echo 'x - extracting FULL-BACKUP (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'FULL-BACKUP' &&
X#! /bin/sh -
X#
X#	FULL-BACKUP
X#
X#	script for a dump ``full'' backup of a selected filesystem.
X#
X#	designed to be started as an online job by root per:
X#
X#		# FULL-BACKUP key
X#
X#	where ``key'' is one of:
X#
X#		root	for filesystem /	/dev/sd0a
X#		usr	for filesystem /usr	/dev/sd0g
X#		home	for filesystem /home	/dev/sd2a
X#		h1	for filesystem /h1	/dev/sd4a
X#		h2	for filesystem /h2	/dev/sd6a
X#
X#	The script will instruct dump to save its table-of-contents archive 
X#	in a file named "key_YYMMDD" in the $ARCHDIR file directory when the
X#	dump is completed.
X#
X#	Note that the choice of program for $ECHO is deliberate for the
X#	features; if you change it and/or you haven't installed the System V
X#	software option, caveat emptor.
X#
X#	Originally written by Thad Floryan, 11-Feb-1991
X#
Xumask 027
XECHO=/usr/5bin/echo
XTOUCH=/usr/5bin/touch
X#
XARCHDIR=/usr/tapeadmin
X#
X#
XDATEDATE=`date`
XYYMMDD=`date +%y%m%d`
XMMDDHHMMYY=`date +%m%d%H%M%y`
X#
Xcase $1 in 
X	root)	BASE_NAME="root_"
X		FILESYSTEM="/dev/sd0a"
X		TAPETYPE="DC600A"
X		;;
X	usr)	BASE_NAME="usr_"
X		FILESYSTEM="/dev/sd0g"
X		TAPETYPE="DC600A"
X		;;
X	home)	BASE_NAME="home_"
X		FILESYSTEM="/dev/sd2a"
X		TAPETYPE="DC600A"
X		;;
X	h1)	BASE_NAME="h1_"
X		FILESYSTEM="/dev/sd4a"
X		TAPETYPE="DC600A"
X		;;
X	h2)	BASE_NAME="h2_"
X		FILESYSTEM="/dev/sd6a"
X		TAPETYPE="DC600A"
X		;;
X	*)	$ECHO "Error, usage is: FULL-BACKUP {root, usr, home, h1, h2}"
X		exit 1
X		;;
Xesac
X
Xcase $TAPETYPE in
X	DC600A)	## DC600A/QD600A tape (for 60MB per tape):
X		##
X		TDTYPE="QIC-24"
X		TAPEDEV=/dev/rst8
X		TAPEDEN=1000
X		TAPETRK=9
X		TAPELEN=600
X		;;
X	DC6150)	## DC6150/QD6150 tape (for 150MB per tape):
X		##
X		TDTYPE="QIC-150"
X		TAPEDEV=/dev/rst9
X		TAPEDEN=1250
X		TAPETRK=18
X		TAPELEN=600
X		;;
X	DC6250)	## QIC-150 drives using DC6250 tape (for 250MB per tape):
X		##
X		TDTYPE="QIC-150"
X		TAPEDEV=/dev/rst9
X		TAPEDEN=1250
X		TAPETRK=18
X		TAPELEN=1020
Xesac
X
XARC_NAME=$ARCHDIR/$BASE_NAME$YYMMDD
X
Xif [ -f $ARC_NAME ]
Xthen
X	$ECHO "\007\007\007\007\007\007\n"
X	$ECHO "**** WARNING **** WARNING **** WARNING **** WARNING ****\n****"
X	$ECHO "**** A full-backup on '$1' has already been run today.\n****"
X	$ECHO "**** WARNING **** WARNING **** WARNING **** WARNING ****"
X	$ECHO "\nContinue [y,n]? \c"
X	read ANSWER
X	if [ $ANSWER != "y" ]
X	then
X		$ECHO "Confirming user abort"
X		exit 1
X	fi
Xfi
X
X$ECHO "\nBacking up $1 on $FILESYSTEM, archive log to $ARC_NAME\n"
Xdf
X$ECHO "\nInsert first $TAPETYPE tape in the $TDTYPE drive"
X$ECHO "\nContinue [y,n]? \c"
Xread ANSWER
Xif [ $ANSWER != "y" ]
Xthen
X	$ECHO "Confirming user abort"
X	exit 1
Xfi
X
X# dump options and argument mapping:
X#
X#	0			for level 0 backup
X#	c			for cartridge tape
X#	u			update /etc/dumpdates
X#	s	$TAPELEN	cartridge tape size in feet
X#	t	$TAPETRK	number of tracks on tape
X#	d	$TAPEDEN	tape density in BPI
X#	a	$ARC_NAME	archive file for restore and reference
X#	f	$TAPEDEV	dump device
X#		$FILESYSTEM	filesystem being dumped
X#
X
X$ECHO "\ndump 0custdaf $TAPELEN $TAPETRK $TAPEDEN $ARC_NAME $TAPEDEV $FILESYSTEM\n"
X
Xdump 0custdaf $TAPELEN $TAPETRK $TAPEDEN $ARC_NAME $TAPEDEV $FILESYSTEM
X
X$ECHO $DATEDATE > $ARCHDIR/last.full.$1
Xchmod o+r $ARCHDIR/last.full.$1
X$ECHO "\n$TOUCH -m $MMDDHHMMYY $ARCHDIR/last.full.$1"
X$TOUCH -m $MMDDHHMMYY $ARCHDIR/last.full.$1
X
X$ECHO "\nFull backup of $1 completed"
X
Xexit 0
SHAR_EOF
$TOUCH -am 0411222892 'FULL-BACKUP' &&
chmod 0740 FULL-BACKUP ||
echo 'restore of FULL-BACKUP failed'
Wc_c="`wc -c < 'FULL-BACKUP'`"
test 3246 -eq "$Wc_c" ||
	echo 'FULL-BACKUP: original size 3246, current size' "$Wc_c"
fi
# ============= INCR-BACKUP ==============
if test -f 'INCR-BACKUP' -a X"$1" != X"-c"; then
	echo 'x - skipping INCR-BACKUP (File already exists)'
else
echo 'x - extracting INCR-BACKUP (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'INCR-BACKUP' &&
X#! /bin/sh -
X#
X#	INCR-BACKUP
X#
X#	script for a cpio ``incremental'' backup of entire system since:
X#
X#	newest ( $TAPEDIR/last.incr , oldest ( $TAPEDIR/last.full.* ) )
X#
X#	designed to be started as a batch job by root per:
X#
X#		sun# cd /usr/tapeadmin
X#		sun# batch -sm INCR-BACKUP
X#
X#	Originally written by Thad Floryan, 11-Feb-1991
X#
Xumask 027
X#
XECHO=/usr/5bin/echo
XNEWEST=/usr/local/bin/fnewest
XOLDEST=/usr/local/bin/foldest
XTOUCH=/usr/5bin/touch
X#
XTAPEDEV=/dev/rst8
XTAPEDIR=/usr/tapeadmin
XTENSION="mt -f $TAPEDEV retension"
X#
XDIROPTS="-icBtv"
XWRTOPTS="-ocBa"
X#
X#################### end of configurable parameters ####################
X#
XDATEDATE=`date`
XMMDDHHMMYY=`date +%m%d%H%M%y`
XYYMMDDHHMM=`date +%y%m%d%H%M`
X#
XOLDEST_FULL=`$OLDEST $TAPEDIR/last.full.*`
XREF_DATE=`$NEWEST $OLDEST_FULL $TAPEDIR/last.incr`
X#
X$ECHO "#####\n##### BACKUP STARTED $DATEDATE\n#####"
X#
X$ECHO "##### BACKING UP INCREMENTALLY SINCE "`cat $REF_DATE`"\n#####"
X#
X$ECHO $TENSION
X#
X$TENSION
X#
X$ECHO "#####\n##### TAPE RETENSIONED "`date`"\n#####"
X#
X$ECHO "cd /"
X#
Xcd /
X#
X$ECHO "find . -newer $REF_DATE -depth -print > $TAPEDIR/incr$YYMMDDHHMM"
X#
Xfind . -newer $REF_DATE -depth -print > $TAPEDIR/incr$YYMMDDHHMM
X#
X$ECHO "#####\n##### BACKUP LIST CREATED "`date`"\n#####"
X#
X$ECHO "cat $TAPEDIR/incr$YYMMDDHHMM | cpio $WRTOPTS > $TAPEDEV"
X#
Xcat $TAPEDIR/incr$YYMMDDHHMM | cpio $WRTOPTS > $TAPEDEV
X#
X$ECHO "#####\n##### TAPE WRITTEN "`date`"\n#####"
X#
X$ECHO "$ECHO \`uname -a\` \"Incremental Backup Log $DATEDATE\\n\"> $TAPEDIR/ilog$YYMMDDHHMM"
X#
X$ECHO `uname -a` "Incremental Backup Log $DATEDATE\n"> $TAPEDIR/ilog$YYMMDDHHMM
X#
X$ECHO "cpio $DIROPTS < $TAPEDEV >> $TAPEDIR/ilog$YYMMDDHHMM"
X#
Xcpio $DIROPTS < $TAPEDEV >> $TAPEDIR/ilog$YYMMDDHHMM
X#
X$ECHO "#####\n##### BACKUP LOG WRITTEN "`date`"\n#####"
X#
X$ECHO "$DATEDATE" > $TAPEDIR/last.incr
X#
X$ECHO "$ECHO \"$DATEDATE\" > $TAPEDIR/last.incr"
X#
Xchmod o+r $TAPEDIR/last.incr
X#
X$ECHO "chmod o+r $TAPEDIR/last.incr"
X#
X$TOUCH -m $MMDDHHMMYY $TAPEDIR/last.incr
X#
X$ECHO "$TOUCH -m $MMDDHHMMYY $TAPEDIR/last.incr"
X#
X$ECHO "#####\n##### $TAPEDIR/last.incr updated to $DATEDATE\n#####"
X#
X$ECHO "rm $TAPEDIR/incr$YYMMDDHHMM"
X#
Xrm $TAPEDIR/incr$YYMMDDHHMM
X#
X$ECHO "#####\n##### BACKUP COMPLETED "`date`"\n#####"
X#
Xexit 0
SHAR_EOF
$TOUCH -am 0411222892 'INCR-BACKUP' &&
chmod 0740 INCR-BACKUP ||
echo 'restore of INCR-BACKUP failed'
Wc_c="`wc -c < 'INCR-BACKUP'`"
test 2231 -eq "$Wc_c" ||
	echo 'INCR-BACKUP: original size 2231, current size' "$Wc_c"
fi
# ============= fnewest.c ==============
if test -f 'fnewest.c' -a X"$1" != X"-c"; then
	echo 'x - skipping fnewest.c (File already exists)'
else
echo 'x - extracting fnewest.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'fnewest.c' &&
X/* fnewest - outputs name of newest file given on command line
X *
X * usage:
X *
X *	$ fnewest file1 file2 ... filen
X *
X * Thad Floryan
X */
X
X#include <sys/types.h>
X#include <sys/stat.h>
X#include <stdio.h>
X#include <string.h>
X#include <time.h>
X
Xextern int		stat();
Xextern void		printf();
Xextern void		perror();
X
Xextern int errno;
X
Xstruct stat	buf;
X
Xchar *version	= "fnewest (1.0) Thad Floryan";
X
Xmain(argc,argv)
Xint argc;
Xchar *argv[];
X{
X    int current;
X    long newest_mtime = 0;
X    int newest_index = 0;
X
X    if (argc == 1) {
X	printf("usage:  %s  file1 file2 ... filen\n", argv[0]);
X	exit(0);
X    }
X
X    for (current = 1; current < argc; current++) {
X	if (stat(argv[current], &buf) == 0) {
X	    if(buf.st_mtime >= newest_mtime) {
X		newest_mtime = buf.st_mtime;
X		newest_index = current;
X	    }
X	}
X    }
X
X    if (newest_index > 0) {
X	printf("%s\n", argv[newest_index]);
X    } else {
X	printf("ERROR\n");
X    }
X}
SHAR_EOF
$TOUCH -am 0411222892 'fnewest.c' &&
chmod 0640 fnewest.c ||
echo 'restore of fnewest.c failed'
Wc_c="`wc -c < 'fnewest.c'`"
test 910 -eq "$Wc_c" ||
	echo 'fnewest.c: original size 910, current size' "$Wc_c"
fi
# ============= foldest.c ==============
if test -f 'foldest.c' -a X"$1" != X"-c"; then
	echo 'x - skipping foldest.c (File already exists)'
else
echo 'x - extracting foldest.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'foldest.c' &&
X/* foldest - outputs name of oldest file given on command line
X *
X * usage:
X *
X *	$ foldest file1 file2 ... filen
X *
X * Thad Floryan
X */
X
X#include <sys/types.h>
X#include <sys/stat.h>
X#include <stdio.h>
X#include <string.h>
X#include <time.h>
X
Xextern int		stat();
Xextern void		printf();
Xextern void		perror();
X
Xextern int errno;
X
Xstruct stat	buf;
X
Xchar *version	= "foldest (1.0) Thad Floryan";
X
Xmain(argc,argv)
Xint argc;
Xchar *argv[];
X{
X    int current;
X    long oldest_mtime = 0x7fffffff;
X    int oldest_index = 0;
X
X    if (argc == 1) {
X	printf("usage:  %s  file1 file2 ... filen\n", argv[0]);
X	exit(0);
X    }
X
X    for (current = 1; current < argc; current++) {
X	if (stat(argv[current], &buf) == 0) {
X	    if(buf.st_mtime < oldest_mtime) {
X		oldest_mtime = buf.st_mtime;
X		oldest_index = current;
X	    }
X	}
X    }
X
X    if (oldest_index > 0) {
X	printf("%s\n", argv[oldest_index]);
X    } else {
X	printf("ERROR\n");
X    }
X}
SHAR_EOF
$TOUCH -am 0411222892 'foldest.c' &&
chmod 0640 foldest.c ||
echo 'restore of foldest.c failed'
Wc_c="`wc -c < 'foldest.c'`"
test 918 -eq "$Wc_c" ||
	echo 'foldest.c: original size 918, current size' "$Wc_c"
fi
exit 0