Thanks to a mix of this article and the dperson/samba Docker container, it is actually pretty straight forward to set up a time machine server.
As usual, you can skip the post and just look at the code - maxisme/docker-time-machine.
Samba Setup
First of all, you need to write a Samba config (docs here).
samba.conf
[timemachine]
comment = Time Machine
path = /mnt/data/time-machine
browseable = yes
writeable = yes
create mask = 0600
directory mask = 0700
spotlight = yes
vfs objects = catia fruit streams_xattr
fruit:aapl = yes
fruit:time machine = yes
After that, you can create the Samba Docker container using docker-compose.
docker-compose.yml
version: '3.3'
services:
samba:
container_name: samba
restart: always
ports:
- '139:139'
- '445:445'
volumes:
- './samba.conf:/samba.conf'
- '${MNT:?err}:/mnt/time-machine/'
command: "-p -I /samba.conf -u \"${USER:?err};${PASS:?err}\" -s \"samba;/mnt/time-machine/;yes;no;no;$USER\""
image: dperson/samba
I like to put environment variables in my docker-compose files so that I can hide the values when publishing to GitHub. Feel free to hardcode the ${...}
values and then you can simply run $ docker-compose up -d
and skip to the next section.
If you choose to keep the environment variables you can then create two more files.
The first .env
file to put your variables; MNT
which is used to point to where the time machine backups should be stored on your machine running Docker. And USER
and PASS
for the credentials of the Samba server.
.env
MNT=
USER=
PASS=
For the second file, you can write a simple shell file to run the docker-compose with the exported .env
variables:
run.sh
#!/bin/bash
export $(grep -v '^#' .env | xargs)
docker-compose up -d
Then simply run it - $ bash run.sh
Time Machine Setup
Now on your Mac go to Finder and press cmd + k
:
here you should enter the address of your time machine server like smb://192.168.0.108
where 192.168.0.108
is the address of the machine used to run the samba docker container.
Any problems here please check the usual:
$ docker logs samba
- Firewall - Do you have UFW enabled? Allow ports
139
and445
.
After pressing connect it will then ask for the username and password set in the .env
And which volume you want to mount
You will then have the time machine volume mounted on your Mac.
Now visit System Preferences > Time Machine
and select the timemachine
disk.
Congrats, you now have time machine set up! 🎉
Also to speed up the time machine a bit you can run on your mac:
$ sudo sysctl debug.lowpri_throttle_enabled=0