[m-dev.] for review: backupws
Zoltan Somogyi
zs at cs.mu.OZ.AU
Wed Feb 9 15:19:12 AEDT 2000
tools/backupws:
A new script to back up one or more workspaces. Mostly based on
backupdir, but with an interface that may be more convenient to
some people, and standalone (not requiring a separate backuprevisions
script).
Zoltan.
cvs diff: Diffing .
Index: backupws
===================================================================
RCS file: backupws
diff -N backupws
--- /dev/null Thu Sep 2 15:00:04 1999
+++ backupws Wed Feb 9 15:16:25 2000
@@ -0,0 +1,126 @@
+#!/bin/sh
+#
+# A script to backup one or more workspaces.
+#
+# The backup of a workspace consists of two files: a cvs diff that is
+# compatible with cvspatch, and a record of the version numbers of the files
+# that the cvs diff is based on.
+#
+# The name of the directory that contains backup files can be specified
+# via the -s option; the default is $HOME/backup. The names of the backup
+# files will start with the name of the workspace, which can be specified
+# via the -w option; the default is the last component of the workspace's
+# specified path. The rest of the name specifies the date the backup;
+# the modification dates give the date when the backup was last checked
+# and found to be up to date.
+#
+# Since it does not make sense to give the same name for more than one
+# workspace, the script accepts multiple arguments only if -w is not used.
+#
+# The script removes any backups for the specified workspaces that are
+# more than a week old, to put a bound on the backup system's disk space
+# requirement.
+
+stable="$HOME/backup"
+wsname=""
+
+usage="usage: backupws [-s stabledir] [ws1 [ws2 ...] | -w wsname ws1]"
+
+while getopts s:w: option
+do
+ case $option in
+ s) stable=$OPTARG ;;
+ w) wsname=$OPTARG ;;
+ \?) echo $usage; exit 1 ;;
+ esac
+done
+shift `expr $OPTIND - 1`
+
+if test "$wsname" != "" -a "$#" -gt 1
+then
+ echo $usage
+ exit 1
+fi
+
+if test ! -d "$stable"
+then
+ echo "$stable does not exist"
+ exit 1
+fi
+
+if test ! -w "$stable"
+then
+ echo "$stable is not writeable"
+ exit 1
+fi
+
+yesterday_date=`date --date "1 day ago" +"%Y-%m-%d"`
+date=`date +"%Y-%m-%d"`
+time="00:00:00"
+cvsdate="$yesterday_date $time"
+
+backuprevisions=/tmp/backuprevisions.$$
+trap "/bin/rm -f $backuprevisions" 0 1 2 3 15
+cat > $backuprevisions << 'END'
+#!/bin/sh
+echo $1
+cat $1
+echo
+echo
+END
+chmod a+x $backuprevisions
+
+for ws in "$@"
+do
+ if test "$wsname" = ""
+ then
+ wsname=`basename $ws`
+ fi
+
+ if test -d $ws/CVS
+ then
+ olddiff=`ls -t $stable/$wsname-*.diff.gz | head -1`
+ oldrevisions=`ls -t $stable/$wsname-*.revisions.gz | head -1`
+ diff=$stable/$wsname-$date.diff.gz
+ revisions=$stable/$wsname-$date.revisions.gz
+
+ if test "$olddiff" = ""
+ then
+ # If there is no backup, make one
+ echo "No backup for $wsname, making one"
+ (
+ cd $ws
+ cvs diff -u -N . 2> /dev/null |
+ gzip -9 > $diff
+ find . -path '*CVS*' -name Entries \
+ -exec $backuprevisions '{}' ';' |
+ gzip -9 > $revisions
+ )
+ elif test "`find $ws* -newer $olddiff`" != ""
+ then
+ # If there are changes in the directory since the
+ # previous backup, make a new backup.
+ echo "Changes in $wsname, making new backup"
+ (
+ cd $ws
+ cvs diff -u -N . 2> /dev/null |
+ gzip -9 > $diff
+ find . -path '*CVS*' -name Entries \
+ -exec $backuprevisions '{}' ';' |
+ gzip -9 > $revisions
+ )
+ else
+ # Mark the old backup as still current.
+ touch $olddiff
+ touch $oldrevisions
+ fi
+ else
+ echo "$ws is not under CVS control"
+ fi
+
+ # Delete all the backups of this workspace over a week old.
+ find . -name "$stable/$wsname-*.diff.gz" -mtime +7 -exec rm '{}' ';'
+ find . -name "$stable/$wsname-*.revision.gz" -mtime +7 -exec rm '{}' ';'
+done
+
+exit 0
--------------------------------------------------------------------------
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