Using Raspberry Pi as a Time Capsule to backup a Mac


Time Machine is the built-in backup feature of OS X. It keeps a copy of all your files, and remembers how your system looked on any given day so you can revisit your Mac as it appeared in the past. Apple sells a device called a Time Capsule, but rather than buy one of these I opted for a diy approach using my Raspberry Pi and so far it seems to be working well.

My setup consists of:
  • Raspberry Pi Model B running Raspbian connected via network cable to a router
  • MacBook Pro running OS X Yosemite v10.10.1 connected via Wifi to a router
  • External 2TB drive (with separate power) attached via USB to the Raspberry Pi
It was relatively easy to setup following the instructions at http://www.raspberrypi.org/forums/viewtopic.php?f=36&t=47029 . I am reiterating the instructions here just in case the page disappears (with a couple of additions I needed):
1. Start with a clean installation of Raspbian, configured for your network

2. Power down your Pi, connect your storage drive, and boot your Pi back up.

3. Since my Pi only has 2 USB ports, I wasn't able to have a Keyboard, Mouse and USB drive connected without using a USB hub. Since I didn't want to use a USB hub I installed a VNC server on the Pi and a VNC client application on the Mac using instructions from http://www.raspberrypi.org/documentation/remote-access/vnc/ which can be summarised as follows.
$ sudo apt-get install tightvncserver
$ tightvncserver
$ vncserver :0 -geometry 1920x1080 -depth 24

4. Install netatalk and gparted
$ sudo apt-get update
$ sudo apt-get upgrade
$ sudo apt-get install netatalk gparted

5. Start up the graphical desktop on your Pi using startx, and run gparted (it's under "preferences" in your start menu). Select your storage drive (not your SD card), delete any existing partitions, and create a new single partition of type ext4. Then exit gparted.

6. Set your Pi to connect to your storage drive when you boot, and create a place in your Pi's filesystem for it to go
a) create the directory with appropriate permissions
$ sudo mkdir /mnt/TimeMachine
$ sudo chmod 777 /mnt/TimeMachine
b) setup auto boot
$ sudo echo "/dev/sda1 /mnt/TimeMachine ext4 defaults 0 2" >> /etc/fstab
This command came up with a Permission denied error so I instead manually updated the /etc/fstab file using nano with the entry in quotes (/dev/sda1 /mnt/TimeMachine ext4 defaults 0 2) added at the end.
$ sudo nano /etc/fstab
c) mount the drive
$ sudo mount /dev/sda1

7. Configure netatalk to share the directory
a) setup netatalk
$ sudo echo "/mnt/TimeMachine \"Time Machine\" options:tm" >> /etc/netatalk/AppleVolumes.default
This command came up with a Permission denied error so I instead manually updated the /etc/netatalk/AppleVolumes.default file using nano with /mnt/TimeMachine "Time Machine" options:tm added at the end (Note: the \'s have been removed from the echo command).
$ sudo nano /etc/netatalk/AppleVolumes.default
b) restart netatalk
$ sudo service netatalk restart

8. On your Mac open your Time Machine preferences, click Select Disk, and choose Time Machine on raspberrypi. I found initially that I couldn't find the Time Machine share so I went to Finder and connected to the Raspberry Pi at afp://pi_ip_address

9. The backup should commence after a couple of minutes.

Raspberry Pi is a trademark of the Raspberry Pi Foundation
Apple, Mac, MacBook, MacBook Pro, OS X, Time Capsule and Time Machine are trademarks of Apple Inc.

Comments

  1. This set of instructions worked well except that it was necessary for me to establish a suitable owner for the Volume. I used
    sudo chown pi:pi /mnt/TimeMachine
    to set the user. Then I could successfully choose the volume on the Time Machine preferences on the Macintosh

    ReplyDelete
    Replies
    1. Excellent. I'll glad the instructions were useful. That's good additional information too re ownership; I suspect if I had done that myself I wouldn't have had to work around the Permission denied errors I was getting. :-)

      Delete
  2. After over two weeks of trying everyday to get my mac to connect to my Pi's external hard drive I finally got it thanks to your blog post! So happy I came across your page!

    ReplyDelete
  3. Dont you get any sparsebundle errors after a week or 2 or passing a 500mb of backup size?

    ReplyDelete
    Replies
    1. I have not noticed any sparsebundle errors and my backup size is larger than 500MB. From a quick Google search this does seem to be a common error with Time Capsule in general (and not specific to this rpi setup); https://discussions.apple.com/thread/5852321 discusses some options for resolution.

      Delete
  4. This is the only guide that worked! Thank you!

    ReplyDelete
  5. Hi! I was wondering which filesystem should i use for my rpi2 NAS + time machine setup. I mainly work with OS X computers and linux based computers. Is ext4 better or just HFS+? (I also want to be able to plug the hard drive right into my macbook for faster backup and restore). THANK YOU!

    ReplyDelete
    Replies
    1. I debated HFS+ vs ext4 and I went with ext4 since it is Linux native (as is the rpi), I suspected this might work a bit better and be easier to setup, and I wasn't planning to connect the drive without the rpi in the middle.

      I do however like the idea of having the option to plug the hard drive directly into the mac and my understanding is I can't do this with my ext4 device (I haven't tried mind you). I'd be tempted to try HFS+ if I was starting over.

      Delete
    2. Thanks for the reply! I tried HFS+ but keep getting problems here and there, so I switched to ext4 for my Time Machine partition. Now it's going well, except it's a bit slow over the wifi.(maximum speed of 4MB/s). Do you by any chance know how to spin down the hard drive when idle for a while? Cause I don't know how long my external hard drive is gonna last if I spin it all day long

      Delete
    3. My external hard drive isn't continually spinning all day (or at least I don't think it is). It was spinning for a quite a while doing the initial backup and then every once in a while it does a rebuild.

      In terms of spinning it down for a while, it looks like "hdparm -y" might help. Check out http://superuser.com/questions/651880/force-spin-down-of-external-hard-drive-on-linux-raspberry-pi

      Delete
  6. This is the 4th of 4 on the 'Net, and the only one that worked. Shorter, yet more detailed than the others and more up-to-date as well. My Mac now backs up to my WD connected to my pi across the network. Many thanks!

    ReplyDelete
  7. Worked great, once I read comment about adding chown and restarting netatalk.. thanks!

    ReplyDelete

Post a Comment

Popular posts from this blog

IT & Enterprise Architecture Conference 2015 - Day 2

Considerations when responding to an RFI or RFP (a view from the receiving end)