Time Machine backup with rsync

I’ve been using Apple’s Time Machine for backups over the last year. Last week it started annoying me by wanting to backup the same 300GB of data a few hours after it did a full backup. Not fun. I also don’t need a full machine backup and I don’t like things doing “magic”. I want a log and I want to be sure my files are safe.

So, back to using rsync. I found this article useful.

Here is my script:

#!/bin/sh

#incremental backup to USB disk

date=`date “+%Y-%m-%dT%H:%M:%S”`

rsync -aPxWSvv \
–delete \
–delete-excluded \
–exclude-from /Users/joe/backup.excludes \
–link-dest=/Volumes/JoeBackup/Backups/Ripley/current \
/Users/joe \
/Volumes/JoeBackup/Backups/Ripley/incomplete-$date \
&& cd /Volumes/JoeBackup/Backups/Ripley \
&& mv incomplete-$date $date \
&& rm -f current \
&& ln -s $date current

backup.excludes looks like this:

joe/Music/audio
joe/Library/Caches/Firefox
joe/Library/Caches/com.apple.Safari

4 thoughts on “Time Machine backup with rsync

  1. Nice !

    Here’s mine, it does something similar:


    #!/bin/sh

    SRC=/home/alasdair/
    DEST=/media/Elements/
    RSYNC=/usr/bin/rsync
    OPTS="-avuz --stats --progress --delete --human-readable"

    if cut -d' ' -f2 /proc/mounts | grep '^/media/Elements$' >/dev/null; then
    $RSYNC $OPTS $SRC $DEST
    echo "$(date): Local mirror successful" >> /tmp/mybackup.log
    else
    echo "$(date): Local mirror failed - $DEST not mounted" >> /tmp/mybackup.log
    fi

  2. Thanks Joe, was a great help adding time slewing to my backup script. Result:


    #!/bin/bash -x

    ## Incremental backup using rsync.

    echo "Starting..."
    date

    ##############################################################################

    DATE=$(date "+%Y-%m-%dT%H:%M:%S")

    ## Dir to backup, sans exclude file:
    SRC_DIR="/home/foobar"

    ## This dir must/will have the timestamped backups as well as a
    ## special "current" symlink pointing to the latest backup:
    DST_DIR="/media/460GB/foobar/backup"

    EXCLUDE="/home/foobar/bin/exclude.txt"

    INCOMPLETE="incomplete-${DATE}"
    FINAL=${DATE}

    ##############################################################################

    echo "Backing up to dir: $DST_DIR in 5 seconds!"
    sleep 5

    rsync -avx --delete --delete-excluded --exclude-from=${EXCLUDE} \
    --link-dest=${DST_DIR}/current ${SRC_DIR} ${DST_DIR}/${INCOMPLETE} \
    && cd ${DST_DIR} \
    && mv ${INCOMPLETE} ${FINAL} \
    && rm -f current \
    && ln -s ${FINAL} current

    date
    echo "Finished."

Comments are closed.