[Tutorial] Time Machine backup system with DietPi

Hi all;

Since I use a Macbook I use Time Machine for my regular backups, but backup is a time and CPU consuming process so I prefer doing it overnight at home. For remote backups Apple has a marvelous Time Capsule system, but it is expensive and it can be reproduced by a simple DietPi server.

First make a regular installation of a DietPi server, then install neccessary tools;

apt-get install netatalk

In a regular DietPi install we don’t have a normal user, we have to create a new user so that we can use it to login to our time machine server. There are some workarounds, but this is far simpler.

mkdir /home
useradd -s /bin/bash -m -d /home/sarmisak sarmisak
passwd sarmisak

Now we have to tell where time machine should keep our time machine folders. I would recommend using an external disk with an external power supply since it does not rely on the power of the RPi USB, I use a WD Essentials 2 TB disk for this job. After you plugin your disk, at the command prompt using blkid list your available disks;

root@timemachine ~ # blkid
/dev/mmcblk0p1: SEC_TYPE="msdos" LABEL="boot" UUID="CB99-4C7E" TYPE="vfat" 
/dev/mmcblk0p2: UUID="1263ae8d-aaf3-41b6-9ac0-03e7fecb5d6a" TYPE="ext4" 
/dev/sda1: UUID="2a96a3dd-2c08-4cfe-90ee-fbfeabf779ec" TYPE="ext4"

/dev/sda1 is what we are looking for, so let’s add it to our /etc/fstab file, copy your UUID from this output and in your /etc/fstab remove these lines;

#External Drives---------------------------------------------------
# - Try and use only ext4 for USB drives
# - Faster performance than NTFS, espically on RPi v1
/dev/sda1       /mnt/usb_1      ext4    defaults,noatime  0       0
/dev/sda1       /mnt/usb_1      ntfs-3g    defaults       0       0

with;

#/dev/sda1 // Should be on one line
UUID="2a96a3dd-2c08-4cfe-90ee-fbfeabf779ec"   /mnt/timemachine   ext4   defaults,noatime   0   0

You will have to change your UUID when your disk changes, try not to change it and if you must change your disk you must change the UUID in here, too. I try to use UUIDs instead of /dev/sdaX, because if you plugin more than one disk the locations might change and you can overwrite on other files by fault.

Now, let’s create the mount point and give privileges to our user;

mkdir /mnt/timemachine
chown -R sarmisak:sarmisak /mnt/timemachine

Edit /etc/netatalk/AppleVolumes.default and add this line at the end of the file;

/mnt/timemachine/           "Time Machine"  options:tm

Let’s mount the disk and restart the netatalk server;

mount -a
service netatalk restart

In your Finder window press Command + K combination, a “Connect to Server” window should appear, in the address line write afp:// and your DietPi IP address;

afp://192.168.xxx.yyy

It should ask you your username and password, fill in the neccessary fields and connect. You should be able to read and write in your Time Machine folder. Now, let’s add this disk to your Time Machine on your Mac. Click Time Machine in your System Preferences. Turn it on and click “Add or Remove Backup Disk…” button. You should be able to see your Time Machine server as “Time Machine” in the list, click and fill in the user information again. If you leave your Macbook connected to a power source, it should backup your computer to this Time Machine system automatically whenever you get connected at your home network.

Hi sarmisak,

Many thanks for posting this guide. I will give it a spin on my RPi when i can.

I’ve also changed this post to a sticky.

Thank you for the great tutorial. Can i use Netatalk together with Pi-Hole? Or are there problems here?

Cool howto

Easy way to create user that autocreated directory in /home is

# adduser user

Quick howto on creating a sudoer user as well
https://www.digitalocean.com/community/tutorials/how-to-create-a-sudo-user-on-ubuntu-quickstart

Sorry for the silly question, is this tutorial still working after 5 years?
I’ve tried but I almost bricked my system :cry: I’m a newbie and seems like I’m having troubles with netatalk

If someone is willing to help me I’ll post some details

Following. Would love to make this happen. TIA!

Tried this - https://saschaeggi.medium.com/use-a-raspberry-pi-4-for-time-machine-works-with-big-sur-1e66a9650789
with no luck :thinking:

Worked nicely for me after installing samba-vfs-modules. Thanks for posting. Maybe check /var/log/samba if that wasn’t it.

1 Like

Here some more background/info at the feature request on GitHub: https://github.com/MichaIng/DietPi/issues/4507

Happy new year all together :slight_smile:.

This simple Samba based writeup is working fine for me: https://manjaro.site/how-to-configure-time-machine-to-backup-to-samba-shared-folder/

Hey everybody - I changed user as I couldn’t access the previous one.

So, I’m willing to solve this issue but no skills - somebody willing to help me sort this out?

At this point, for some reason I can access the dietpi folder but not the pimachine folder (the one that I’ll be using for this Time Machine thing)

Where to start?

Edit: typos

You could start sharing some more information on your system.

How do you access the system?
Which user you are using?
Which file system you are trying to access?
How does file system permission looks like for that folder you are trying to access?

After installing the samba-vfs-modules, I’ve went through the last steps of the tutorial and now Time Machine is working fine.
And the problem reported above was because I was trying the access without using the Time Machine user.
So, everything works now :partying_face:

But I have a final question - what is considered to be a normal write speed?
My Raspberry is cabled to the router through a Gigabit switch and my Mac (Air M1 2020) is connecting to the router on the 5G network.

I think I’m getting around ~10Mb/s (80gb to go and 6h estimated to finish)

speed hight depends on used SBC, SD card, attached USB or SSD.

Raspberry Pi 4 with a 4TB WESTERN DIGITAL Elements (2.5’’ - 4 TB - USB 3.0) non SSD.

what is the performance if you do a Benchmark test?

  1. dietpi-config
  2. 10 : Tools
  3. Benchmarks
  4. Custom Filesystem
  5. select your HDD
  6. set 100 and OK

what is the result? Does the drive has an own PSU? Or is it connected to USB port only?

@fcupdt2022: This description could be a good option for an own blog post in our DietPi blog (DietPi Blog – …discover interesting topics).
Would you be able to write the text and supply additional screenshots? Then we could generate together a blog post, I could takeover the manual work of entering your post contents.

│ - Test size = 100 MiB │
│ - WRITE = 78 MiB/s │
│ - READ = 112 MiB/s

It’s USB powered. I have a spare SSD and in the next days I plan to check if it is worth using it for the Time Machine backups

Do you mean for the writing speed or setting up the Time Machine thing?