Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Back up OS X to a Windows machine on the network UNIX
I know there are plenty of back up/synchronization packages for the Mac, and I know Time Machine is awesome. But as I have a Linux/FreeBSD background, I wanted to do it my way. And none of the software I tried was able to do it my way :-). So the command line seemed to be a good solution.

My office Windows machine has plenty of disk space on it, and it is rarely used. It was an ideal system (with not so ideal a file system) to do backups on. The solution I came up with requires:
  • A shared folder on the PC, mounted on the Mac.
  • The Unix app rdiff-backup, available via MacPorts.
  • Notifications are sent using growlnotify, part of the Growl notification system.
The final step was to write a custom shell script to back up my Mac to the mounted Windows shared folder; here's what that looks like:
# my backup script in /Users/mkljun/

SourceIP=`ifconfig | sed -n '/en0/,/media/p' | grep -v inet6 | grep inet | awk '{print $2}'`

## delete a log file if bigger than 50M                                                                                                     
# check if the file exists otherwise create it                                                                                              
if [ ! -f $LOGFILE ]; then `touch $LOGFILE`; fi
LOGSIZE=`ls -l $LOGFILE | awk '{print $5}'`
echo "Size of $LOGFILE = $LOGSIZE bytes."  >> $LOGFILE 2>&1
if [ $LOGSIZE -gt 50000000 ]; then rm $LOGFILE; fi

echo "************************************************************" >> $LOGFILE 2>&1
date >> $LOGFILE 2>&1
echo "************************************************************" >> $LOGFILE 2>&1
echo "Pinging destination machine $DestinationIP:" >> $LOGFILE 2>&1
# ping destination (backup) ip address; output redirected to a log file
ping -c 1 $DestinationIP >> $LOGFILE 2>&1
# check if ping successful
if [ $? != 0 ]
    # if ping command not successful, print notification (echo should be in one line!!)
    echo "-t 'Backup failed' -m 'Your IP is $SourceIP. Backup PC $DestinationIP could not be reached'" | xargs /usr/local/bin/growlnotify
    echo "Pinging failed" >> $LOGFILE 2>&1
    # mount samba drive (it should be one line)
    osascript -e "try" -e "mount volume \"$SambaDrive\"" -e "end try" > /dev/null 2<&1
    # check if mount was successful
    if [ $? == 0 ]; then
      # this echo should be in one line with a pipe
      echo "-t 'Backup' -m 'Your IP is $SourceIP. Starting backing up now'" | xargs /usr/local/bin/growlnotify
      echo "Backing up" >> $LOGFILE 2>&1
      rdiff-backup $SourceDir $DestinationDir >> $LOGFILE 2>&1
      # if rdiff-backup 
      if [ $? == 0 ]; then
        echo "-t 'Backup' -m 'Backup completed successfully'" | xargs /usr/local/bin/growlnotify
        echo "Backup completed successfully" >> $LOGFILE 2>&1
        echo "-t 'Backup failed' -m 'Something was wrong'" | xargs /usr/local/bin/growlnotify
        echo "Backup failed" >> $LOGFILE 2>&1
      # delete all backups older than 2 weeks
      rdiff-backup --remove-older-than 2W $DestinationDir >> $LOGFILE 2>&1
You can read the entire tutorial on my blog, and download the latest version of the script.

[robg adds: I've copied the script as it currently exists here, just in case the blog entry ever goes away. However, check the linked blog entry first for a newer version, and to read the details on how it works.]
  • Currently 2.48 / 5
  You rated: 3 / 5 (21 votes cast)

Back up OS X to a Windows machine on the network | 2 comments | Create New Account
Click here to return to the 'Back up OS X to a Windows machine on the network' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Back up OS X to a Windows machine on the network
Authored by: OlaMontan on Nov 23, '09 01:11:45AM

I just wonder what's wrong with the build in command rsync:

mkdir /Volumes/backup
/sbin/mount -t smbfs //<user>:<pass>@<server>/<folder> /Volumes/backup || exit
rsync -avz --delete Documents /Volumes/backup/<folder>/
/sbin/umount /Volumes/backup

[ Reply to This | # ]
Back up OS X to a Windows machine on the network
Authored by: Helge33 on Nov 23, '09 01:14:08AM

I would guess that rdiff-backup has the same problems as rsync as it does not consider all extended attributes of the OSX filesystem?

The only *real and complete* Mac backup strategy appears to be Superduper which simply works with a Mac disk image.

Cheers, Helge

[ Reply to This | # ]