#! /bin/sh # backup homedir # author: anders.lindback [at] dnsz.se # heavily based on sh-backup-lohout.hook that comes with iHook. # ### # # 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 ### set PATH=/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin; export PATH archiveday="Tuesday" homedir="/Users/entity" backupdir="/Volumes/aegir/backup" snapdate="$backupdir/.snap-date" snapdir="current-snapshot" archivedir=`date "+archive-%Y-%m-%d"` # Messages to stdout appear in the iHook window echo "Preparing to backup $homedir..." # ...except messages beginning with a % sign. # This starts an indeterminate progress bar (barberpole): echo "%10" echo "%BEGINPOLE" HALTREBOOT=`grep shutdown: /var/log/system.log | tail -1 | awk '{print $6}'` if [ "x$HALTREBOOT" = "xreboot" ]; then echo "system rebooting, no backup.." sleep 1 exit 0 fi if [ ! -d "$backupdir" ]; then echo "Backup drive not attached, goodbye.." sleep 1 exit 0 fi # Tell the user we're creating the directory if [ -f $snapdate ]; then SDATE=`cat $snapdate` echo "Last backup: $SDATE" sleep 1 fi # start a determinate progress bar, while indicating # we've created the new backup dir echo "%30" # update the message in the iHook window echo "Backing up $homedir..." echo "%BEGINPOLE" echo "%OPENDRAWER" rsync --stats -aE "${homedir}/" "$backupdir/$snapdir" 1>&2 if [ $? -ne 0 ]; then echo "Backup of $homedir failed." echo "%BEEP" sleep 1 echo "%BEEP" sleep 1 echo "%BEEP" exit 2 fi sleep 2 echo "%60" # we're done, fill the progress bar and remove it from the screen today=`date "+%A"` if [ "x$today" = "x$archiveday" ]; then echo "Since it\'s $archiveday, creating archive point..." echo "%65" echo "%CANCEL ENABLE" if [ -d $backupdir/$archivedir ]; then echo "Archive point for today already exists.." sleep 1 else cp -R $backupdir/$snapdir $backupdir/$archivedir fi else echo "%80" fi # update the message in the iHook window date > $snapdate echo "Backup complete." echo "%100" echo "%BEEP" echo "%BEEP" # wait a second, then exit sleep 1 exit