[unix-pc.sources] a simple backup script

brant@manta.UUCP (Brant Cheikes) (01/15/88)

This almost seems too trivial to post, but here goes anyway...

There was no response to my article about backup techniques.  All I
can assume is that people w/o tape drives are (a) using the UA backup
script, or (b) using ccpio/unccpio, or (c) not backing up their
systems at all.  Method (a) takes lots of time and disks, (b) takes
twice as long but uses fewer disks, and (c) is only for those who live
life in the fast lane.

So... I put together a little shell script that permits simple, fast,
customizable backups.  It allows you to specify both entire
subdirectories as well as particular files to be SKIPPED during
backup; everything else gets backed up.  I haven't implemented file
compression (it costs too much time for my taste).

The script is used as follows: first, create a subdir for the backup
routine and related files.  This is assigned to the variable ADMDIR.
In ADMDIR you create an "omit-roots" file and a set of *-omit files.
The "omit-roots" file is a text file containing (one per line) all the
subdirectories that should be skipped during the backup process.  For
example, I usually omit dirs like /tmp, /dev, /usr/spool/news.  All
files and subdirectories below dirs listed in omit-roots will not be
backed up.

The *-omit files contain (one per line) all the *files* that should be
omitted from the backup.  For example, I created a file fnd-omit which
lists all the files in the foundation set which I haven't modified and
thus don't need to be backed up.  This is easy to do-- just get the
"Files" file from the first volume of the foundation kit disk set and
edit it to taste (for example, I want to back up /etc/passwd even
though it "comes" with the foundation kit, so I delete it from the
fnd-omit file).  Make sure all files/paths are absolute--i.e., have a
'/' in column 1.  Currently, I have fnd-omit, utl-omit (development
kit), and doc-omit (doc prep kit) files.

That's it--now just run the backup script.  It creates a list of all
files on the disk that are neither in the subdirs listed in omit-roots
nor in any of the *-omit files.  Those files are then backed up with
cpio.

Judicious use of the omit-roots and *-omit files makes it possible to
back up all your important files quite fast without using vast
quantities of disks.

So, w/o any further ado, here's the script.  It's simple, no bells and
whistles, and probably could be enhanced or improved.  But hey, it
works, and sure beats any other method I've tried.

--------------- cut here ---------------
#! /bin/ksh
#
# backup
# Brant Cheikes
# University of Pennsylvania
# Department of Computer and Information Science
# ARPA: brant@linc.cis.upenn.edu, UUCP: ...drexel!manta!brant
#
# Last Edit: 15 Jan 88

PATH=.:/bin:/usr/bin
# edit this next line!!
ADMDIR=~brant/Filecabinet/admin
BADROOTS=omit-roots
cd $ADMDIR

# create the list of all files to be backed up, eliminating all files
# in subdirs listed in $BADROOTS.
cat $BADROOTS | sed 's/\//\\\//g
s/^/\/\^/
s/$/\/d/' >/tmp/sedscr
find / -type f -print | sed -f /tmp/sedscr | sort >/tmp/allfiles

# remove all files to be omitted from allfiles and crank up cpio
cat *-omit | sort | comm -23 /tmp/allfiles - | cpio -oBcv >/dev/rfp021

rm -f /tmp/allfiles /tmp/sedscr
--------------- cut here ---------------
-- 
Brant Cheikes
University of Pennsylvania
Department of Computer and Information Science
ARPA: brant@linc.cis.upenn.edu, UUCP: ...drexel!manta!brant