Home Time Machine Backups to Samba Share on ZFS
Post
Cancel

Time Machine Backups to Samba Share on ZFS

Notes from setting up a Ubuntu server with ZFS and using it as a server for Time Machine backups.

I’ve set aside one partition exclusively for Time Machine backups for the family. Even if it doesn’t get mirrored it should be more robust being on ZFS.

ZFS

Set up partition

This assumes you will use an entire existing partition.

Using gdisk, modify the partition type to be ‘Solaris Backup’ (bf03)

Verify it:

1
2
3
DISK=/dev/nvme0n1
PARTITION=6
sudo sgdisk -i $PARTITION $DISK
1
2
3
4
5
6
7
Partition GUID code: 6A8B642B-1DD2-11B2-99A6-080020736631 (Solaris backup)
Partition unique GUID: B6DFD979-3415-43C7-8311-85FC83F79271
First sector: 2156922880 (at 1.0 TiB)
Last sector: 7814037134 (at 3.6 TiB)
Partition size: 5657114255 sectors (2.6 TiB)
Attribute flags: 0000000000000000
Partition name: ''

Create the time machine pool

1
2
3
4
5
6
7
8
9
sudo zpool create \
    -o ashift=12 \
    -o autotrim=on \
    -O acltype=posixacl -O xattr=sa -O dnodesize=auto \
    -O compression=lz4 \
    -O normalization=formD \
    -O relatime=on \
    -O canmount=off -O mountpoint=/var/timemachine \
    tmpool ${DISK}p${PARTITION}
1
zpool list
1
2
3
4
NAME     SIZE  ALLOC   FREE  CKPOINT  EXPANDSZ   FRAG    CAP  DEDUP    HEALTH  ALTROOT
bpool   1.88G   456M  1.43G        -         -     0%    23%  1.00x    ONLINE  -
rpool   1016G  5.59G  1010G        -         -     0%     0%  1.00x    ONLINE  -
tmpool  2.62T   476K  2.62T        -         -     0%     0%  1.00x    ONLINE  -

Create dataset

1
sudo zfs create -o canmount=on -o mountpoint=/var/timemachine tmpool/timemachine

Set permissions:

1
2
sudo chgrp sambashare /var/timemachine
sudo chmod g+ws /var/timemachine

Samba

Install

See Samba as a file server

1
sudo apt install samba

Some references

Global config

Edit /etc/samba/smb.conf, add these bits

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
[global]
# Fruit global config
  fruit:aapl = yes
  fruit:nfs_aces = no
  fruit:copyfile = no
  fruit:model = MacSamba

# Permissions on new files and directories are inherited from parent directory
   inherit permissions = yes

# Samba will automatically "register" the presence of its server to the rest of the network using mDNS. Since we are using avahi for this we can disable mdns reg
istration.
   multicast dns register = no

# Protocol versions
  client max protocol = default
  client min protocol = SMB2_02
  server max protocol = SMB3
  server min protocol = SMB2_02

# some performance tuning (cargo cult'd from the 'net, who knows if or how much it helps)
   read raw = Yes
   write raw = Yes
   # socket options = TCP_NODELAY IPTOS_LOWDELAY SO_RCVBUF=131072 SO_SNDBUF=131072
   socket options = TCP_NODELAY
   min receivefile size = 16384
   use sendfile = true
   aio read size = 16384
   aio write size = 16384
   strict allocate = yes

Now add a share definition

1
2
3
4
5
6
7
8
9
10
11
12
[Timemachine]
    # Load in modules (order is critical!)
    vfs objects = catia fruit streams_xattr
    fruit:time machine = yes
    fruit:time machine max size = 2400G
    comment = Time Machine Backup
    path = /var/timemachine
    available = yes
    valid users = @sambashare
    browseable = yes
    guest ok = no
    writable = yes

Add users to Samba

1
2
3
for user in mike ; do
  sudo smbpasswd -a $user
end

Timemachine

Do this for each client machine

Check current settings

1
2
3
4
5
6
tmutil destinationinfo
====================================================
Name          : timemachine
Kind          : Network
URL           : smb://mike@share._smb._tcp.local./timemachine
ID            : 86A7D87E-8EDB-417A-9A5D-B6F0BFCDA5E3

ref: https://www.reddit.com/r/apple/comments/107bnh7/daily_advice_thread_january_09_2023/

Set backup destination

Set the destination (‘-a’ adds a new destination, otherwise destination is replaced):

1
2
user=mike
sudo tmutil setdestination -p smb://${user}@share.local./timemachine

This might speed up initial backup; it will be reset upon reboot

1
sudo sysctl debug.lowpri_throttle_enabled=0

Show filesystem activity:

1
sudo fs_usage -wf filesys backupd

You may have to set the backup frequency in Setting (I chose ‘Daily’)

Remote backups

If you set up Tailscale (or similar) on your Samba server and on your client machine, you can backup to the DNS name regardless of where you are:

1
sudo tmutil setdestination -p smb://${user}@share.ts.carltons.us./timemachine
This post is licensed under CC BY 4.0 by the author.
Contents