#! /bin/sh ### # # Backup the contents of a folder # ### ### # Copyright (c) 2002 Regents of The University of Michigan. # All Rights Reserved. # # Permission to use, copy, modify, and distribute this software and # its documentation for any purpose and without fee is hereby granted, # provided that the above copyright notice appears in all copies and # that both that copyright notice and this permission notice appear # in supporting documentation, and that the name of The University # of Michigan not be used in advertising or publicity pertaining to # distribution of the software without specific, written prior # permission. This software is supplied as is without expressed or # implied warranties of any kind. # # Research Systems Unix Group # The University of Michigan # c/o Wesley Craig # 4251 Plymouth Road B1F2, #2600 # Ann Arbor, MI 48105-2785 ### PATH=/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin; export PATH projectdir="/Users/user/src/CurrentProject" backupdir="/Volumes/Storage/backups" newbackupdir=`date | awk '{ print $3 "-" $2 "-" $6 "-" $4 "-backup" }'` # Messages to stdout appear in the iHook window echo Preparing to backup $projectdir... # ...except messages beginning with a % sign. # This starts an indeterminate progress bar (barberpole): echo %BEGINPOLE if [ ! -d "$backupdir" ]; then mkdir "$backupdir" if [ $? -ne 0 ]; then # messages to stderr appear in the drawer. # This message, an error, is redirected to stderr # so it will appear in the drawer. echo Create $backupdir failed 1>&2 exit 2 fi fi # Tell the user we're creating the directory echo Creating $backupdir/$newbackupdir... mkdir "$backupdir/$newbackupdir" if [ $? -ne 0 ]; then # again, redirect error messages to stderr, and to the drawer. echo Create $backupdir/$newbackupdir failed. 1>&2 fi # start a determinate progress bar, while indicating # we've created the new backup dir echo %20 # just for fun, change the background of the iHook window echo %BACKGROUND /Library/Images/mountains.png echo Clearing $projectdir temporary space... rm -rf "$projectdir/tmp" echo %40 # update the message in the iHook window echo Backing up $projectdir... ditto -rsrcFork "$projectdir" "$backupdir/$newbackupdir" if [ $? -ne 0 ]; then echo Backup of $projectdir failed. exit 2 fi # we're done, fill the progress bar and remove it from the screen echo %100 # update the message in the iHook window echo Backup complete. # wait a second, then exit sleep 1 exit