From - Wed Aug 21 17:20:19 1996 Path: news.unizar.es!news.rediris.es!news.belnet.be!swsbe6.switch.ch!swidir.switch.ch!01-newsfeed.univie.ac.at!Austria.EU.net!EU.net!howland.erols.net!newsfeed.internetmci.com!netnews.nwnet.net!news.u.washington.edu!lgy From: lgy@newton.phys.washington.edu (Laurence Yaffe) Newsgroups: comp.sys.sgi.admin Subject: Alternative "Backup" script avoiding 'bru' Date: 18 Aug 1996 18:21:01 GMT Organization: University of Washington Lines: 174 Message-ID: <4v7mud$c6s@nntp5.u.washington.edu> NNTP-Posting-Host: newton.phys.washington.edu X-Newsreader: NN version 6.5.0 #2 (NOV) As many previous posts have noted, the fact that some of SGI's software distributions exceed bru's pathetic 127 character pathname length limit is a continuing nuisance for users of /usr/sbin/Backup or the backup GUIs. But as Dave Olson repeatedly points out, /usr/sbin/Backup is just a script so one can "easily" rewrite it to use a different backup program. In the hope that it will benefit others, I offer below one such alternative Backup script (also available as http://www.phys.washington.edu/~lgy/Backup). It uses "cpio -H tar" to create tar-format archives, and has a command line syntax which is upwardly-compatible with SGI's Backup. It automatically excludes active swap files and /proc files. The strategy of using cpio to create tar-format archives was dictated by my chosen requirements of: 0. Avoiding bru. 1. Supporting backup verification. (Eliminates dump and default-format cpio archives.) 2. Supporting incremental backups. (Eliminates tar for backup creation, since tar always descends recursively.) 3. Supporting multiple partition backups with a single command. (Also eliminates dump.) One 'feature' of "cpio -H tar" is that it complains about files whose UID or GID are missing from /etc/passwd or /etc/group. Hence, running "find / -local \( -nouser -o -nogroup \) -print" and fixing any such file ownership problems is recommended. Comments or improvements welcome. ------------------------------------------------------------------------ Laurence G. Yaffe yaffe@phys.washington.edu Department of Physics University of Washington 1-206-543-3902 ------------------------------------------------------------------------ #!/bin/sh # # Backup - perform file system backup # # Features: # Full or incremental (level 1) backups. # Backup verification (comparison of archive with existing disk files). # Creates tar-format archives. # Updates /etc/lastbackup on successful full backups. # Command line syntax compatible with SGI's /usr/sbin/Backup. # 1024 character pathname length limit (instead of bru's limit of 127). # # System dependencies: # Archive creation requires a cpio accepting '-H tar'. (IRIX, Solaris) # Archive verification requires a tar accepting 'C' key. (IRIX only?) # # Environmental variables: # TAPE - tape device (/dev/tape default). # EXCLUSIONS - list of files to exclude from backup (space delimited). # # Laurence G. Yaffe (yaffe@phys.washington.edu) # 8/14/96 - initial version main() { prev=/etc/lastbackup # marker for full backups exclude=/tmp/excluded.$$ # exclusion tmp file tape=${TAPE:-/dev/tape} # tape device fopt='-local ! -type s -print' # find options copt='-oa' # cpio options FLAGS=" -i incremental backup -C read archive and compare with disk -V prints '.' for each file archived -v prints name of each file archived -x do not cross mount points -b tape blocksize (in 512 byte blocks) -h remote tape drive host -f tape device to use -t same as -f" USAGE="usage: Backup [] [] ...\n\nflags:$FLAGS" NOPREV="No previous full backup, exiting." while getopts CivVxb:f:h:t: opt do case $opt in C) cmpr=1 ;; # archive comparison i) incr=1 ;; # incremental backup x) xdev=1 ;; # don't cross mount points b) blks=$OPTARG ;; # blocking factor h) host=$OPTARG ;; # remote host name f|t) tape=$OPTARG ;; # tape device v|V) copt="$copt$opt" ;; # verbosity level \?) die "$USAGE" ;; esac done shift `expr $OPTIND - 1` test "$host" && tape="${host}:$tape" test "$blks" && copt="${copt} -C"`expr "$blks" \* 512` if [ "$cmpr" ] # compare with existing files then tar Cf $tape "$@" | grep '^[?>!]' else # archive files to tape test -r "$1" || die "$USAGE" if [ "$incr" ] # incremental backup then test -f $prev && fopt="-newer $prev $fopt" || die "$NOPREV" elif [ "$xdev" ] # filesystem limited backup then fopt="-mount $fopt" elif [ ."$1" = ./ ] # full backup then date > $prev.new && full=1 || exit 1 fi trap "rm -f $exclude" 0 1 2 15 # cleanup on exit exclusions > $exclude # generate exclusions eval "find $@ $fopt | egrep -vf $exclude | cpio $copt -Htar -O$tape" status=$? test "$full" -a $status -eq 0 && roll $prev && allok exit $status fi } exclusions() # generated excluded file patterns { for file in `swapfiles` $EXCLUSIONS do echo "^$file$" done echo '^/proc/' echo '^/dev/fd/' echo '^/var/adm/badlogin/' } swapfiles() # find active swap files { /etc/swap -l | while read pri file junk do test ! "$junk" -a -s $file && echo $file done } roll() { test -f $1 && mv $1 $1.old ; mv $1.new $1 } die() { echo "$*" 1>&2 ; exit 1 } allok() { echo Full backup complete -- $prev updated 1>&2 } main ${1+"$@"} ------------------------------------------------------------------------ Laurence G. Yaffe yaffe@phys.washington.edu Department of Physics University of Washington 1-206-543-3902 (fax: 1-206-543-9523)