Network Time Machine - Samba on Linux

How to create a Network Time Machine device for macOS using Samba on a Linux machine.

Introduction

As a data hoarder myself I like to keep my data very safe, and for my MacBook Air that means Time Machine, an awesome piece of software similar to Timeshift on Linux (Which I have just found out it’s maintained by the Linux Mint Team :O).

There’s always the option of using an external drive, but that requires either having it plugged in all the time (or even worse, having to remember to do so) or having to put up with that Dongle-Life™ if you don’t have a USB-C one for the latest Macs.

Another benefit of using Samba for Time Machine is not having to use an entire drive for it, using Samba gives you the flexibility of directing the service to whatever directory you want. For example, you could use this in combination with a RAID set up with mdadm.

Creating the Samba share

DISCLAIMER: Functionality greatly varies between Samba and macOS versions, if you encounter any problems make sure to check the references and the troubleshooting section!

First of all we have install, setup and configure Samba to work with Time Machine

Installing Samba

For Debian based installs run: sudo apt install samba.

For Arch based installs run: sudo pacman -S samba

For Fedora based installs run: sudo dnf install samba

Configuring Samba

I found this resource by Canonical very useful, i suggest you read points 3 and 4 if you’re new to Samba.

If you haven’t already, create a samba user with sudo smbpasswd -a username

To the samba configuration file at /etc/samba/smb.conf add the following:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
[share-name]
  valid users = your-samba-username
  comment = Time Machine
  path = your-folder
  browseable = yes
  read only = no
  spotlight = yes
  
  vfs objects = acl_xattr catia fruit streams_xattr

  fruit:time machine = yes
  fruit:nfs_aces = no
  inherit acls = yes
  fruit:model = MacSamba
  fruit:posix_rename = yes
  fruit:veto_appledouble = no
  fruit:wipe_intentionally_left_blank_rfork = yes
  fruit:delete_empty_adfiles = yes
  fruit:metadata = stream

Restart the Samba service. For systemd systems, run: sudo systemctl restart smbd

Avahi service

In order for our Mac to automatically discover our server we need to install Avahi, also referred as Bonjour on macOS.

Installing the Avahi Daemon

For Debian based installs run: sudo apt install avahi-daemon.

For Arch based installs run: sudo pacman -S avahi

For Fedora based installs run: sudo dnf install avahi

Creating the service

Create a file at /etc/avahi/services/smb.conf with the following:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
<?xml version="1.0" standalone='no'?>
<!DOCTYPE service-group SYSTEM "avahi-service.dtd">
<service-group>
  <name replace-wildcards="yes">%h</name>
  <service>
    <type>_smb._tcp</type>
    <port>445</port>
    <host-name>server.internal.domain</host-name>
  </service>
  <service>
    <type>_device-info._tcp</type>
    <port>0</port>
    <txt-record>model=MacPro7,1@ECOLOR=226,226,224</txt-record>
  </service>
  <service>
    <type>_adisk._tcp</type>
    <txt-record>sys=waMa=0,adVF=0x100</txt-record>
    <txt-record>dk0=adVN=TimeMachine,adVF=0x82</txt-record>
    <host-name>server.internal.domain</host-name>
  </service>
</service-group>

Restart the Avahi daemon. sudo systemctl restart avahi-daemon

If everything is correctly set up, our machines should be able to see eachother. We can check this by running on our Mac’s terminal: ping <serverhostname>.local

Configuring Time Machine

On your Mac, go to System Settings, Time Machine and add a new drive. There your share should appear as <HOSTNAME>.local, add it and log in with your user and password.

If once your first backup starts, the process gets stuck conneting with your server, stop and start the backup manually.

A <Mac-Hostname>.sparsebundle folder should appear in the share’s directory.

You have now successfully created a Time Machine-enabled Samba share! Thanks for reading. Make sure to check the rest of the article if you’d like :P

Troubleshooting

If after finishing the setup your Mac does not see your share on the Time Machine configuration screen follow these steps.

Check if the services are running correctly

Both sudo systemctl status smbd and sudo systemctl status avahi-daemon should say “running” (usually in green text).

An example output of the Avahi service running:

The Avahi daemon running

  • If they are disabled or inactive you can fix it running sudo systemctl enable <service> and sudo systemctl start <service>.

  • If they have stopped due to an error, check the config files are in their place and have no errors.

Check for any misspellings in the config files

Make sure your config files are OK. Lines such as fruit:nfs_aces = no can be mistaken as a misspelling for ntfs_access.

References

I’ve used, and recommend checking out these resources:

Amb <3 des de Barcelona
Built with Hugo
Theme Stack designed by Jimmy