Use Ubuntu network share for Apple TimeMachine backups?

I want to backup my Mac to a network drive mounted on my Ubuntu computer. How do I set this up?


NOTE: this is now out of date. See linked question re: TimeMachine in High Sierra

This is actually really straightforward. My solution below works for a single user, but can likely be easily adapted for multiple users.

On the Ubuntu machine:

  1. Make sure the directory to be shared is mounted and owned by your user (e.g., your backup hard drive is mounted at /mnt/backups in /etc/fstab, and you've created a subdirectory called myMac in this backup folder). Because this is a network share it actually doesn't matter what format the disk uses - it could be ext4, btrfs, etc.

  2. Install netatalk (open source AFP):

    sudo apt-get install netatalk
    
  3. Configure the Apple share by editing location at the bottom of the /etc/netatalk/AppleVolumes.default file (comment out the line with the home directory and add the actual mount location; add your username):

    #~/                "Home Directory"
    /mnt/backups/myMac "TimeMachine"    allow:username options:tm,usedots,upriv
    

    (I'm not sure that options:usedots,upriv needs to be explicitly set but it works for me.)

  4. Restart the netatalk service:

    sudo service netatalk restart
    
  5. Make sure ports 548/tcp and 5353/udp are open in your firewall.

On the Mac machine:

  1. Open the terminal and enter:

    defaults write com.apple.systempreferences TMShowUnsupportedNetworkVolumes 1
    
  2. Reboot the computer.

  3. Mount the network share location by selecting the network share from the leftmost pane in a Finder window, or by selecting "Connect to server" from the Finder app's "Go" menu (or press +K) and enter the machine name or IP address of your Ubuntu machine:

    afp://123.456.789.123
    

    Use your Ubuntu user credentials to authenticate when prompted.

  4. Go to Time Machine preferences (accessible from "System preferences") and select "Change location", selecting to encrypt backups, and begin the backup setup process.

    • This will automatically create the sparsebundle file necessary for backups.
  5. After setup is complete, wait ~90 seconds for backup to automatically begin, and even longer for it to complete ☺