Use a Raspberry Pi 4 for Time Machine (works with macOS 11 Big Sur)

Time Machine is built into the system of macOS and I’m using it since the early days of Mac OS X Leopard. If you have a Raspberry Pi (or two) lying around at your place like me, this tutorial comes in handy to create a cheap and speedy backup solution.

Preparation

Make sure your Raspberry Pi is running on the latest software.

sudo apt-get update && sudo apt-get upgrade

We’re going to first install Samba (for SMB) which is a very popular Open Source file sharing protocol which is officially supported by Time Machine for backing up data over a network. The Avahi daemon is used for Apples “Bonjour” mDNS protocol that our Raspberry Pi server is automatically discoverable within the network.

sudo apt-get install samba avahi-daemon

Storage

As the Raspberry Pi 4 ships with 2x USB 3.0 ports we can connect an external hard drive as our disk space for backing up data. Also we should get decent speeds as we also get a 1GBit/s wired connection with the Pi 4.

ls -lha /dev/disk/by-uuid
Look for the UUID and rember the mount point (e.g. /dev/sdb1) we’ll need this later

In my case the device was /dev/sdb1 and the UUID we’re looking for was the one below:

7efbdfc5–9c85–4e01–873a-204e00c9aa45

Note: exchange this UUID with yours

Create backup user

sudo adduser timemachine

It will ask to set a password for your newly created user.

sudo smbpasswd -a timemachine

Create mount point

In order to mount the USB hard drive we need to create a folder where Linux can mount our device to.

sudo mkdir /mnt/timemachine

We’ll now mount the USB drive to the previously created mount point.

sudo mount /dev/sdb1 /mnt/timemachine

Note that you’ll need to exchange /dev/sdb1 with your device (see the Step with the the UUID above which letter your device uses)

To allow our backup user to write on the device we’ll need to take over the ownership of the mount point:

sudo chown -R timemachine: /mnt/timemachine

Configuring Samba

Edit the Samba configuration file:

sudo nano /etc/samba/smb.conf

add the following to the end:

[backups]
comment = Backups
path = /mnt/timemachine
valid users = timemachine
read only = no
vfs objects = catia fruit streams_xattr
fruit:time machine = yes

This will create a network drive called “backups” which we’ll use for Time Machine.

sudo testparm -s
If all goes well you should get an output like this

Not let’s restart the service to make sure our changes are active.

sudo service smbd reload

On your Mac press “Command + K” on your desktop which will open the “Connect to Server” prompt. Type in the IP Address of your Pi followed by the /backups to connect to our Time Machine volume.

smb://192.168.1.150/backups

Now you should be connected to your Time Machine volume.

Configuring Avahi deamon

In order to let MacOS automatically detect our new Time Machine we’ll need to configure Avahi. For that edit the following file:

/etc/avahi/services/samba.service

And paste this configuration in:

<?xml version="1.0" standalone='no'?><!--*-nxml-*-->
<!DOCTYPE service-group SYSTEM "avahi-service.dtd">
<service-group>
<name replace-wildcards="yes">%h</name>
<service>
<type>_smb._tcp</type>
<port>445</port>
</service>
<service>
<type>_device-info._tcp</type>
<port>9</port>
<txt-record>model=TimeCapsule8,119</txt-record>
</service>
<service>
<type>_adisk._tcp</type>
<port>9</port>
<txt-record>dk0=adVN=backups,adVF=0x82</txt-record>
<txt-record>sys=adVF=0x100</txt-record>
</service>
</service-group>

With this we tell MacOS that in fact our Raspberry Pi is a 8th Gen Time Capsule and it will appear like one in the sidebar in Finder.

sudo service avahi-daemon restart

Automate things

We need to tell fstab that it mounts our hard drive to the Raspberry Pi.

sudo nano /etc/fstab

We need to append the UUID from above like this:

UUID=7efbdfc5–9c85–4e01–873a-204e00c9aa45 /media/tm hfsplus force,rw,user,noauto 0 0

We need to edit crontab with:

sudo crontab -e

We’ll mount the USB drive and start the needed services on a boot/reboot:

@reboot sleep 30 && mount /mnt/timemachine && sleep 30 && umount /mnt/timemachine && sleep 30 && mount /mnt/timemachine && sleep 30 && service avahi-daemon start && service smbd start

Setup Time Machine

The first step is to choose our “backups” volume. For that open the Time Machine settings and you’ll find it under “Available disks”:

Let’s choose our “backups” volume on the Raspberry Pi

Use your password to connect to the Raspberry Pi Time Machine volume:

It will ask for your earlier set password

and we’re done! Happy backuping!

Backuping to my Raspberry Pi Time Machine Server

Sascha Eggenberger. Senior User Experience Designer @unic @Drupal Contributor. Drupal Design System, Claro, Gin. #OpenSource https://sascha.is/

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store