#!/bin/bash # please read! # this script only backs up your $HOME directory! # make sure you read and edit the default ~/.backup_exclude and # ~/.backup_include files # #THIS SCRIPT IS CASE-SENSITIVE # #this script will back up everything to a mounted volume called 'backup' #You need to create a disk image called 'backup' and mount it, or otherwise #mount a writeable 'backup' volume. If you don't know how to do this, RTFM #for Disk Utility #Information: #this script will back up your home directory to a /Volumes/backup directory #this script will also look at a recent backup and only back up newer files #if desired. It will do true "differential" backups in tihs way. To do so: # 1) create a full backup. It does not have to be made with this script, but # that helps. # 2) burn the backup to DVD. # 3) mount the DVD. # 4) enter the DVD name when the script asks. #You can override some defaults below. BACKUPDIR=$HOME/ BACKUPDEVICE="#will set later; probably /Volumes/backup/" BACKUPIMAGE=$HOME/Desktop/backup.sparseimage BACKUPVOLUME=backup BACKUPSIZE=600 EXCLUDEFILE=$HOME/.backup_exclude INCLUDEFILE=$HOME/.backup_include LOGFILE=~/tmp/backup.log OPTS="-vvau" echo "Dry run? (Y/n)" read ans [ "$ans" = "n" ] && ans=N [ "$ans" != "N" ] && OPTS=${OPTS}n echo "compress? (y/N)" read ans [ "$ans" = "y" ] && ans=Y [ "$ans" = "Y" ] && OPTS=${OPTS}z echo "compare old backup? (differential backup)" echo "some possible locations:" ls -1 /Volumes/ echo "enter destination or leave blank" read OLDBACKUP [ $OLDBACKUP ] && {\ [ -e /Volumes/$OLDBACKUP ] && { \ echo "did you mean /Volumes/$OLDBACKUP (Y/n)?" echo "If this is a mounted disk, assume Y" read ans [ "$ans" = "n" ] && ans=N [ "$ans" != "N" ] && OLDBACKUP=/Volumes/$OLDBACKUP }; [ -e $OLDBACKUP ] && COMPAREDEST="--compare-dest=$OLDBACKUP" || {\ echo "$OLDBACKUP:no such file or directory"; exit 1; }; }; [ -f $EXCLUDEFILE ] && EXCLUDE="--exclude-from=$EXCLUDEFILE" [ -f $INCLUDEFILE ] && INCLUDE="--include-from=$INCLUDEFILE" [ -d ~/tmp ] || mkdir ~/tmp #look for backup [ -f $BACKUPIMAGE ] || { echo "backup image does not exist. creating ${BACKUPIMAGE}" hdiutil create -megabytes $BACKUPSIZE -fs HFS+ -volname $BACKUPVOLUME \ ${BACKUPIMAGE} } echo "attaching device $BACKUPVOLUME" DEVVOL=`hdiutil attach ${BACKUPIMAGE} | grep $BACKUPVOLUME | \ awk '{ print $1 " " $3 }' ` DEV=`echo $DEVVOL| awk '{ print $1 }'` BACKUPDEVICE=`echo $DEVVOL | awk '{ print $2 }'` echo "starting backup; logging on $LOGFILE" rsync $OPTS $COMPAREDEST $INCLUDE $EXCLUDE $BACKUPDIR $BACKUPDEVICE >$LOGFILE echo "detaching device $BACKUPVOLUME" hdiutil detach $DEV echo "DONE; LOGFILE IS $HOME/tmp/backup.log" echo "logfile will be overwritten next time a backup is made" echo "burn to disc?(y/N)" read ans [ "$ans" = "y" ] && ans=Y [ "$ans" = "Y" ] && { TMPFILE=/tmp/backup.`jot -r 1 25555` hdiutil burn -list >$TMPFILE BURNDEV="" [ `wc -l $TMPFILE | awk '{ print $1 }'` -gt 2 ] && { echo "chose a device to burn to (by number on left)" grep -vn IOService $TMPFILE read ans BURNDEVID=`echo "$ans + 1" | bc` BURNDEV="-device \"`sed -n ${BURNDEVID}p $TMPFILE | awk '{print $1}'`\"" } echo "Burning. Ctrl-C to cancel. Warning: cancelled burns may ruin the \ media" echo "We do not verify here to save time. \ make sure you verify your disk yourself" hdiutil burn $BURNDEV $BACKUPIMAGE rm $TMPFILE } echo "Done! thanks."