Making a Linux Samba Server the Destination for OS X Time Machine Backups

It’s possible to use network shares on a Linux Samba server as the destination for OS X Time Machine backups.

I found lots of examples of doing this on the ‘net. I tried to collect and simplify what I found there the best I could. I made these notes to remind myself of what I did. This was done on a Fedora 36 server.

Install Samba

$ sudo dnf install samba samba-client
$ sudo setsebool -P samba_domain_controller on      #  See the top of /etc/samba/smb.conf.example for details
$ sudo setsebool -P samba_enable_home_dirs on
$ sudo systemctl enable --now smb
$ sudo firewall-cmd --add-service samba --permanent
$ sudo firewall-cmd --reload

Enable the Bonjour protocol

OS X systems use the Bonjour protocol to announce their services on the network. Time Machine uses this capability to discover network shares that it can use as backup destinations. Linux Samba servers can use the Avahi service to publish information about their services to OS X systems using the Bonjour protocol.

Install Avahi on the Linux server:

$ sudo dnf install avahi

Configure Avahi to announce Samba services by creating the /etc/avahi/services/samba.service file containing the following:

<?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>
  </service>
</service-group>

Start the avahi-daemon service:

$ sudo systemctl enable --now avahi-daemon
$ sudo firewall-cmd --add-port 5353/tcp --permanent
$ sudo firewall-cmd --reload

Create the directory for the share

See the discussion of space requirements below.

$ sudo mkdir -m 777 /path/share
$ sudo chcon -R -t samba_share_t /path/share

Change the Samba server configuration

Edit /etc/samba/smb.conf and add these lines to the [global] section of the file:

vfs objects = catia fruit streams_xattr
fruit:metadata = stream
fruit:veto_appledouble = no
fruit:wipe_intentionally_left_blank_rfork = yes

See man vfs_fruit for additional details.

Add a new share definition to the /etc/samba/smb.conf file. The name of the share (the text in brackets) can be anything you like (no spaces though), as can the comment.

[timemachine]
        comment = OS X Time Machine Backups
        path = /path/share
        read only = no
        fruit:time machine = yes

Add Samba users

Each system that will access the Samba share needs an ID on the Linux server to manage file permissions. That ID then also needs to be defined in the Samba user DB along with a Samba password. These IDs do not need to log on to the Linux server itself, so there’s no need to give them system passwords. (If you want these users to be able to change their own Samba passwords, then they will need system passwords so that they can log on to the Linux system and use the smbpasswd command to do so.)

$ sudo useradd userid1
$ sudo smbpasswd -a userid1

Pre-existing system user IDs may be used without any issue, just run the smbpasswd command to give them a Samba server password.

Restart Samba server

$ sudo systemctl restart smb

Configuring Time Machine

Time Machine can now be configured to use this share as its backup destination. Set a custom disk space quota in the configuration dialog (see Space Requirements below.) The avahi-daemon (Bonjour) service on the Linux server will make the Samba disk share visible in the Time Machine destination list.

Space Requirements

Multiple OS X systems can be backed up into a single network share. Time Machine will create a unique directory on the share for each system. In this case, given that Time Machine is designed to gradually consume all available space on the destination device by default, it is best to set a custom quota size in the Time Machine configuration on each system. This setting is an option when you define the Time Machine destination on the system. Apple recommends that Time Machine be given double the space of the disk being backed up, e.g., a system with 1TB of disk space should have a Time Machine quota of 2TB.

If the server administrator needs to have complete control of each system’s Time Machine disk space usage, individual disk partitions/filesystems of the appropriate size could be created on the disk(s) in the Samba server and these could be shared individually with each system as unique Samba shares. (Add valid users = userid to each network share definition in /etc/samba/smb.conf.) No disk space quota would need to be set in each system’s Time Machine configuration. Time Machine will gradually consume all of the available space on its individual network share as it builds its backup archive. Once the disk is full it will automatically prune old backups to make room for new ones.

dlk

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.