#!/bin/sh
#	SaveNewFiles [dir] [timefile]
#
# This script searches out all the new files under the given directory, and 
# makes a shadow copy in the /save/`hostname` directory.  By "new" is meant 
# any file newer than timefile, which defaults to /save/`hostname`/.lastsave; 
# if it doesn't exist, it is created (and is the start time for future saves).  
# 
# Saving is done by making a shadow copy in the /save/`hostname` directory.  
# It is suggested that you use this script once a day, or whenever you have 
# reached a critical point and would like reassurance that your files are 
# backed up.  The /save directory will be backed up to tape periodically, 
# and files older than some limit will be deleted from /save.
#
A=/aud/Save.`hostname`
test -d /aud || mkdir /aud
#Rm $A
exec >>$A 2>&1
echo `date` '"'$0 $*'"' started.
#
DIR=$1
DTF=$2
if [ $# -lt 1 ];then DIR=/; fi
if [ $# -lt 2 ];then DTF=$DIR/.lastsave; fi
#f [ ! -f $DTF ];then cp touch $DTF; exit 0; fi
if [ ! -f $DTF ];then (cd /save;echo .lastsave|cpio -pum $DTF); fi
#
# Kludge: cpio refuses to create the first directory:
if [ ! -d /save/`hostname` ];then mkdir /save/`hostname`; fi
#
# Do it:
find $DIR -mount -newer "$DTF" -print \
	| sed -e '/\.o$/d' -e '/\.bak$/d' -e '/--$/d' \
	| cpio -pdumlkv /save/`hostname`
#
# Update the timefile:
touch $DTF
echo `date` '"'$0 $*'"' done.
