[m-dev.] diff: add backup script to tools

Tyson Dowd trd at cs.mu.OZ.AU
Mon Dec 6 17:40:53 AEDT 1999


Hi,

Here's that backup script again.  There are a few new changes,
mainly
	- we no longer put stderr into the diff file
	  cvspatch doesn't need it anymore, and it just makes the diffs
	  bigger.  In particular I don't like the way it makes zero
	  sized diffs appear possibly significant.  
	- use -u -N flags for diff
	- fix a bug with handling more than changed file (incorrect
	  quoting).

As other people want to use it, I'll add it to the tools directory.

===================================================================


Estimated hours taken: 2

backupdir:
	Script based on petdr's backup script.
	Will backup any CVS modules in the given directory.
	A compressed diff and a record of the version numbers of all
	files is created.

	The compressed diff can be applied using cvspatch.  A similar
	tool will need to be developed for using the version numbers.

	If the module is unchanged since the previous backup, no diff
	will be made (lightening the load on the CVS repository).

backuprevisions:
	Auxililary script, outputs the CVS/Entries file with the
	filename at the start.   This needs to be in your path when
	running backupdir.


Index: backupdir
===================================================================
RCS file: backupdir
diff -N backupdir
--- /dev/null	Thu Mar  4 04:20:11 1999
+++ backupdir	Mon Dec  6 17:14:33 1999
@@ -0,0 +1,53 @@
+#!/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.
+
+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 
+	    	echo "No backup for $dir/$subdir, making one"
+		(cd $dir/$subdir; cvs diff -u -N . 2> /dev/null |
+		    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
+	    	echo "Changes in $dir/$subdir, making new backup"
+		(cd $dir/$subdir; cvs -f diff -u -N . 2> /dev/null |
+		    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 '{}' ';'
+
Index: backuprevisions
===================================================================
RCS file: backuprevisions
diff -N backuprevisions
--- /dev/null	Thu Mar  4 04:20:11 1999
+++ backuprevisions	Mon Dec  6 17:19:05 1999
@@ -0,0 +1,7 @@
+#!/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