[m-dev.] backup script

Tyson Dowd trd at cs.mu.OZ.AU
Fri Dec 3 16:04:43 AEDT 1999


Here is an improved version of Pete's script (I call it "backupdir").
It's improved because:
	- if no files have been changed in the workspace, no backup is
	  made.  Instead we just update the modification date of the diff
	  file.

	- we record the contents of CVS/Entries from each directory so
	  that the exact revision of the workspace can be recovered
	  (note that presently no script exists to use this
	  information).

#!/bin/sh

set -x
   
# Given a list of dirs, for each subdir in those dirs which is a CVS
# archive it produces a diff file that is compatible with cvspatch.
# Note that the diff file is a diff against the previous days compiler
# at midnight.

yesterday_date=`date --date "1 day ago" +"%Y-%m-%d"`
date=`date +"%Y-%m-%d"`
time="00:00:00"
   
cvsdate="$yesterday_date $time"
   
pwd=`pwd`

for dir in $@
do
    for subdir in `ls $dir`
    do
        if [ -d $dir/$subdir/CVS ]
        then
	    olddiff=`ls -t $pwd/$subdir-*.diff.gz | head -1`
	    oldrevisions=`ls -t $pwd/$subdir-*.revisions.gz | head -1`
	    diff=$pwd/$subdir-$date.diff.gz
	    revisions=$pwd/$subdir-$date.revisions.gz

	    # If there is no backup, make one
	    if [ z"$olddiff" == z  ] ; then 
		(cd $dir/$subdir; cvs diff . 2>&1 |
		    gzip -9 > $diff)
		(cd $dir/$subdir; find . -path '*CVS*' -name Entries \
		 	-exec backuprevisions '{}' ';' | gzip -9 > $revisions)
	    # If there are changes in the directory since the backup,
	    # make a new backup.
	    elif [ x`find $dir/$subdir/* -newer $olddiff` != x ] ; then
		(cd $dir/$subdir; cvs -f diff . 2>&1 |
		    gzip -9 > $diff)
		(cd $dir/$subdir; find . -path '*CVS*' -name Entries \
		 	-exec backuprevisions '{}' ';' | gzip -9 > $revisions)
	    else
	    	touch $olddiff 
	    	touch $oldrevisions 
	    fi
        fi
    done
done

# delete all the backups over 7 days old
find . -name "*.diff.gz" -mtime +7 -exec rm '{}' ';'
find . -name "*.revision.gz" -mtime +7 -exec rm '{}' ';'


You also need a script called backuprevisions:

#!/bin/sh

echo $1
cat $1
echo
echo


-- 
       Tyson Dowd           # 
                            #  Surreal humour isn't eveyone's cup of fur.
     trd at cs.mu.oz.au        # 
http://www.cs.mu.oz.au/~trd #
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list