#!/bin/sh # How to use rsync to approximate 'timemachine'. # WE do not support hard links on directories, so we can't be quite as # efficient as Apple's TimeMachine. # Note: use quotes throughout as filenames may (do) include spaces. # Note: drive (ON OS X) should be mounted with uids enabled.. # sudo /usr/sbin/vsdbutil -a /Volumes/${VOLUME_NAME} # Note: entries can also be put in /etc/fstab to affect mounting # but in OS X 10.5 or later one should use 'vifs'. # adjust to fit your environent. # This is setup to run on OS-X 10.4 (before timemachine). # It has also run on FreeBSD. # ROOT_VOLUME="Macintosh HD" APPDIR="Backups.backupdb" ORIGINALBASE="/" EXCLUDEFILE="/Volumes/MyBook2-1T/exclude-from-backup" BACKUPBASE="/Volumes/MyBook2-1T" BACKUPDIR="${BACKUPBASE}/${APPDIR}" BACKUPHOSTDIR="${BACKUPDIR}/`hostname -s`" BACKUPFILENAME=`date +"%Y-%m-%d-%H%M%S"` LATESTLINK="${BACKUPHOSTDIR}/Latest" BACKUPNAME="${BACKUPHOSTDIR}/${BACKUPFILENAME}" TEMPNAME="${BACKUPNAME}.inprogress" CREATENAME="${TEMPNAME}/${ROOT_VOLUME}" if [ -d "${BACKUPNAME}" ] then echo "ERROR: Backup ${BACKUPNAME} already exists. Exiting." exit 1 fi mkdir -p "${CREATENAME}" if [ -e "${LATESTLINK}" ] then rsync -xaHPR "--exclude-from=${EXCLUDEFILE}" "--link-dest=../../Latest/${ROOT_VOLUME}/" "${ORIGINALBASE}" "${CREATENAME}" else rsync -xaHPR "--exclude-from=${EXCLUDEFILE}" "${ORIGINALBASE}" "${CREATENAME}" fi if [ $? = 0 ] then touch "${TEMPNAME}/.com.apple.TMCheckpoint" mv "${TEMPNAME}" "${BACKUPNAME}" rm "${LATESTLINK}" ln -sf "${BACKUPFILENAME}" "${LATESTLINK}" else echo " Backup to ${BACKUPNAME} FAILED" mv "${TEMPNAME}" "${BACKUPNAME}.FAILED" exit 1 fi