If you’ve used a Mac you know about the OSX Backup system called Time Machine.

According to an Apple support statement:

“Time Machine is a backup utility, not an archival utility, it is not intended as offline storage. Time Machine captures the most recent state of your data on your disk. As snapshots age, they are prioritized progressively lower compared to your more recent ones.”

This whole process is usually done by connecting an external disk to your Mac and assigning it to Time Machine and then the Mac will create regular snapshots of your files and data within Apps such as Apple Mail which can be referred back to and restored at a later date if you delete data or files by mistake.

It struck me a few weeks ago that Apple sells hardware to provide Time Machine services over a home network and short google later it turns out this is done using the Apple Filing Protocol (AFP).

A little more digging showed that using a Docker container I could host my own Time Machine Server on my network.

Before the how, the what..

I’ve got Docker running on CentOS7 on a pretty underpowered Gigabrix box for this particular service. 4Gb Ram, and a mounted external USB3 disk with 4TB of storage.

Now the how..

I’ve created a bash script for setting up CentOS7 with the Docker image, its pretty simple and other than a few lines can be quickly adapted to run on Ubuntu or most other Linux Distros which can run docker.

Also from a storage point of view when doing this the more storage the better, you also don’t want to store the data inside the Docker Container, with this in mind I found it easier to map the data folder out of the docker image onto external storage, it fits my backup system well as i mirror the contents of the 4Tb USB disk to a cloud server 3 times a day.

The script for setting up Docker is as follows:

#!/bin/bash #The Docker command, i’m restarting the docker container always unless explicitly stopped and /mnt/exthdd is my USB Drive mapped in CentOS. #Using image from Docker Hub odarriba/timemachine docker run -h timemachine — name timemachine — restart=unless-stopped -d -v //mnt/exthdd/timemachine:/timemachine -it -p 548:548 -p 636:636 odarriba/timemachine #Setup the firewall on CentOS7 to allow the required ports through to the Docker image.

firewall-cmd — add-port=548/tcp — permanent

firewall-cmd — zone=public — permanent — add-port=548/udp

firewall-cmd — zone=public — permanent — add-port=5353/tcp

firewall-cmd — zone=public — permanent — add-port=5353/udp

firewall-cmd — zone=public — permanent — add-port=49152/tcp

firewall-cmd — zone=public — permanent — add-port=49152/udp

firewall-cmd — zone=public — permanent — add-port=52883/tcp

firewall-cmd — zone=public — permanent — add-port=52883/udp

firewall-cmd — add-port=636/tcp — permanent

firewall-cmd — reload

firewall-cmd — list-all #Enter the USERNAME and PASSWORD used to access the SHARENAME #USERNAME, PASSWORD and SHARENAME are to che changed by you. #If you look at the Docker line above we have mapped /mnt/exthdd to /timemachine in the Docker container, so the path below must contain /timemachine docker exec timemachine add-account USERNAME PASSWORD SHARENAME /timemachine/macbookpro #This section will setup the underlying AFP service on CentOS cat >> /etc/avahi/services/afpd.service << EOF

<?xml version=”1.0" standalone=’no’?>

<!DOCTYPE service-group SYSTEM “avahi-service.dtd”>

<service-group>

<name replace-wildcards=”yes”>%h</name>

<service>

<type>_afpovertcp._tcp</type>

<port>548</port>

</service>

<service>

<type>_device-info._tcp</type>

<port>0</port>

<txt-record>model=Xserve</txt-record>

</service>

</service-group>

EOF #Suggest just copy and replace the existing host entry change /etc/nsswitch.conf to

hosts: files mdns4_minimal dns mdns mdns4 #restart the listening service systemctl enable avahi-daemon

systemctl restart avahi-daemon

NOTE: If you cut and paste the above, I think the formatting might be off, check for dashes and maybe used triple tickbacks

With this running the server is setup with everything is needs, if you have issues it will probably be around the rights on the externally mounted share or firewall rules.

The next stage is to get Time Machine working, and i’ll assum you’ve got some basic Mac skills here.

Open Finder, Go to Shared

Connect to your server with the username and password you provided the script above.

However if the server doesn’t show in shared, all is not lost

Open Finder Press CMD-K Type afp://your-server Where your-server can be your server’s name or IP address (e.g., afp://my-server or afp://192.168.0.5). Login to your server with the username and password you provided the script above.

Now we all mounted we can Open Time machine and add the Server

Go to System Preferences

Open Time Machine settings.

Open Add or Remove Backup Disk…

Your Time machine server should be listed as an available disk

Select your new volume.

Let Time Machine do its magic.

I did note and it’s probably more to do with my network, over Wifi the first backup can take a while depending on the size of the disk.

Note: Several people on Reddit have commentated that AFP is being phased out for SMB. while this is the case, the docker images i’ve used are REALLY slow. Having reached out to Apple Support the AFP will continue to work for Time Machine into Mojave. So as the SAMBA project gets its head around the specific goalposts Apple keep changing. AFP is at least consistent and does work on Sierra, High Sierra and the Mojave Beta.

Sources: