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
#/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;
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.