Menu
Written by Eric Miller
Published on Dec 12, 2017
Topic: Tutorial
Published on Dec 12, 2017
Topic: Tutorial
The machine makes the direction of time collapse into the past, so the longer you follow the machine’s spin, the further back in time you will go. To reset the movement to normal, simply move.
Running a time machine server has historically been a pain. Which sucks, because it’s actually apretty good backup system. For the uninitiated, Time Machine is the built-in backup system on macOS.It keeps incremental backups, which means you can restore your machine to an hour ago, a week ago,a month ago, a year ago, and various increments in between. However, running one tends to suck,because there have historically been two options for doing it. Either sinking $300 on an Applerouter (they’re nice enough routers, but not something I want personally) that’s capable of it, orbuying macOS server and getting a spare mac to just be a server for backups. This is silly, becausemacOS doesn’t make for a good server. Luckily, with the new macOS, they made the time machine serverfunctionality part of the OS, rather than part of their server app.
Somehow, it’s taken me embarassingly long to finally figure out how to set up a Time Machine serveron my FreeBSD machine. Though details proved hard to find, I eventually dug up some guides on howto do it on Linux, and adapted it for my setup. This guide will walk you through how to do it onFreeBSD, and if you’re on Linux, you can probably figure it out between this and finding otherguides.
- Time travel may soon be possible, according to an astrophysicist who believes he’s worked out a way to build a time machine. Professor Ron Mallett from the University of Connecticut in the US.
- How to Build a Time Machine (Vortex Distortion Space and Time Dilating Device): Well lets put it this way, ive always had this thing about traveling through time, and having a time machine. So i set about making one, i decided that instead of being a vessel to travel in, i would rather have something portable. Many hours think.
0. Notes
You don’t want to run this over an insecure network. This is designed for running inside of homeor business networks, not being open on the internet or available to anyone on a guest network.
1. Netatalk
First, we need to install
netatalk3
. Netatalk
is an open-source server for running AFP (AppleFiling Protocol) file shares over your network. AFP is generally considered an inferior protocol,but it’s the only thing Time Machine supports, so we’re stuck with it (unless you want this to getcomplicated and unreliable). Do this with pkg install netatalk3
.2. Prepping your File System
This is basically an optional step. I wanted to limit the total size of all my backups to 1TB, andhave a partition on my file system specifically for Time Machine. I’m using ZFS for my data share,so the command I ran was
zfs create -o quota=1T storage/timemachine
. You’ll also need to set upZFS to auto-mount this new partition.You can do this (or not do this) however you want, but you’ll need to have a location ready tohold Time Machine’s files. Mine is
/storage/timemachine
. You’ll also want to make sure thatthe user accounts (on the machine) can access the underlying filesystem. Use chown
, chgrp
, andchmod
How to play games on roblox studio. as appropriate.3. Netatalk Settings
Next, you’ll need to edit netatalk’s settings, which are found on FreeBSD in
/usr/local/etc/afp.conf
. You’ll want at least two sections - a “Global” section, and a “TimeMachine” section. Here’s a quick look at mine, before I go through it piece by piece. A fullreference document can be foundhere.[Global] defines the settings that apply to all your following shares. If you ever choose toset up another AFP share, it’ll be useful to have these as a shorthand.
- Hostname defines what hostname you advertise on your local network. You’ll want this to reflecta real domain or IP address that can be used to connect to your server.
- Hosts allow says what hosts are allowed to connect to your server. This is a basic securitymeasure that limits what IP addresses can connect to your share. The range I have here(
192.168.1.0/24
) is standard CIDR notation saying that all IP addresses from192.168.1.0
to192.168.1.255
are allowed to connect.192.168.1.0/24
is the typical subnet for consumer routers.192.168.0.0/24
is also common (ish). - AFP listen tells it which network interfaces (and port) to listen on and advertise. I only haveone outward-facing network interface, which is the IP address of my server. Running
ifconfig | grep inet
should give you a short list of options. - Zeroconf tells the server to advertise on the local network that it is an AFP server. You’llwant to enable this to get time machine to work properly. If you’re using avahi, you may notneed this as long as you configure an avahi service for
_afpovertcp._tcp
. - [Time Machine] tells netatalk that the following settings are specific to just the share we’reusing for Time Machine. In the brackets, put whatever you want the display name of your TimeMachine share to be.
- path is the path to the place on the file system you want to use for time machine.
- time machine tells the server that this share is for time machine, and enables support for it.
- valid users tells it what users (as defined through PAM) are allowed to access/modify the share.
- This isn’t in my config, but you may consider another line like
vol size limit = 1000000
,where the value given is in Megabytes. I don’t need this because I have my own area carved outon the file system level, but it is generally recommended for Time Machine backups. - Look at the reference document.There may be other options you want (and more details) there.
4. Service
Next, you’ll want to enable the service by adding the line
netatalk_enable='YES'
to/etc/rc.conf
. Then, just run service netatalk start
to get it running.5. Start Using It
On your mac, open System Preferences and go to the Time Machine pane. Click “Select Backup Disk”.The share you just created should pop up as an option. Select it. I also recommend selecting the“Encrypt backups” checkbox, especially if the underlying file system is not encrypted (maybe evenif it is, just to be safe). Click “Use Disk”. It will prompt you for a login - use the login foryour server that you should have in “valid users”. Normally, this is the same as your general loginfor the server. Make sure to set up any files or directories you want to exclude. Large binaryfiles (like virtual machines) and temporary files (like ~/Downloads) are great candidates here.
I just got a MacBook Pro running macOS Catalina for work, and I wanted to set up Time Machine backups for it to the Synology NAS in my basement so that if the laptop dies or is lost and I need to replace it, I won’t have to redo all of the customizations it took me hours to set up. (I’m separately backing up my data files using Backblaze, but Backblaze doesn’t back up system files and applications.)
I followed Synology’s instructions for using my NAS as a Time Machine backup target, but I couldn’t get the first, full backup to complete successfully after doing that. When Time Machine started to back up, it would say “Looking for backup disk” and then say “Preparing backup” and then stop one or two minutes later with no error message. Below, I explain what I investigating this problem, and how I ultimately solved it.
This article is probably applicable to other Macs (not just MacBook Pro) and other NAS servers (not just Synology).
How backing up to a network drive works
All of these steps need to complete for the first, full Time Machine backup to a network share to succeed:
- Mount the share. If you run the “mount” command in a Terminal window or open Disk Utility you will see it mounted.
- Create a “sparse bundle” on the network share to hold the backup. Basically, this is a disk image stored on the network share that can be mounted as a separate filesystem. Initially the sparse bundle is created with a random name (I think), but after it’s successfully created it’s renamed to contain the host name of the computer being backed up.
- Unmount the network share and mount the sparse bundle directly.
- Write all the backup data to the mounted sparse bundle.
- Unmount the sparse bundle.
What was going wrong
TL;DR It’s the WiFi, dammit.
I kept running the backup. It kept failing part of the way through step 2, i.e., creating the sparse bundle. I know this because I was watching the file share in which the sparse bundle is stored, and each time the backup ran it deleted and recreated the sparse bundle from scratch, and each time it exited prematurely the sparse bundle was a different size.
How much does adobe premiere cc cost. Eventually Time Machine did manage to successfully create and rename the sparse bundle, but then after that it once again stopped prematurely a couple of minutes into writing the backup data. Each time I restarted the backup it would write a little more data and then stop prematurely.
To diagnose this further, I ran a
ping
command in a Terminal window while the backup was running, pinging the NAS. Here’s what I saw immediately before the backup failed:One of two things was happening: either the NAS was briefly becoming inaccessible to my Mac in the middle of the backup, or my Mac was briefly losing network connectivity in the middle of the backup. To determine which of these was the case, I ran the backup again, but this time rather than pinging the NAS during the backup, I pinged another machine on the network. I saw the same brief interruption, which proved that it was the Mac, not the NAS, that’s losing network connectivity briefly during the backup.
This is not surprising, since if you spend some time Googling, you will discover that there are a lot of complaints online about Macs intermittently dropping their WiFi connections briefly. No one really has a good explanation for why this happens or how to fix it. It appears that this is just a widespread problem in Mac WiFi support that Apple hasn’t prioritized fixing.
Unfortunately, the AFP over TCP network filesystem protocol code in the Mac kernel is apparently extremely sensitive to brief interruptions in network connectivity and incapable of recovering from brief network connections. Therefore, every time this WiFi blip happens, Time Machine gets back a filesystem error from the kernel and aborts the backup.
How I fixed it
At a high level, here’s what I did to fix this:
- Mount the network file share with a “hard mount” so that brief network interruptions won’t cause Time Machine to freak out.
- Create a sparse bundle manually on the mounted network file share rather than letting Time Machine do it.
- Mount the sparse bundle.
- Tell Time Machine to use the sparse bundle as its backup location.
- Set up a launch agent task to mount the network file share and sparse bundle automatically every time I log in.
Hard-mounting the network file share
The key here is the
-k
argument to mount_afp
, which is what specifies a hard mount.Creating the sparse bundle
- Open Disk Utility.
- Select File | New Image | Blank Image…
- Open the folder
~/Mountpoints/TimeMachineBackups
or wherever you mounted the network file share. - Enter the name you want to save the bundle as in the “Save as” and “Name” fields.
- Change the “Image Format” field to “sparse bundle disk image”.
- Change the “Size” field to the size of your hard disk.
- Click “Save”.
Mount the sparse bundle
Disk Utility will mount the sparse bundle automatically after you create it. Click the eject button in Disk Utility to eject it, and then do something like this:
If the mounted filesystem shows up on your Desktop and you don’t want it there, you can make it disappear like this:
Tell Time Machine where to back up
You may need to grant Terminal full disk access to run this command. If so, you’ll see an error message in your Terminal telling you that with instructions for how to do it. I recommend turning off full disk access for terminal after it’s done!
Finally, open Time Machine preferences, enable “Back Up Automatically”, enable “SHow Time Machine in menu bar”, click on Time Machine in the menu bar, select “Back Up Now”, and watch the preferences window to make sure everything is working.
Mounting everything automatically using a launch agent
I created this script as
~/scripts/mount_time_machine_backup.sh
(I’ve obscured some sensitive details here):I made the script mode 0700 so I wasn’t exposing my network file share password to the world.
Widsmob montage 1 11 – create mosaic photos. Then I put this in
~/Library/LaunchAgents/comp.jik.TimeMachineMounts.plist
:Then
launchctl load ~/Library/LaunchAgents/comp.jik.TimeMachineMounts.plist
, and we’re done!Warnings
My MacBook has crashed at least twice in less than a week since I set this up as described above. Judging from the stack trace that displays after reboot, it looks to me like it’s crashing inside network filesystem code. In addition, each time it has crashed, Time Machine has popped up a message telling me my backup was corrupt and needed to be recreated from scratch. So while the process described above works, it cannot be said to work perfectly, apparently, because of a kernel bug in macOS.
Credits
The following pages written by other people were helpful to me in figuring out much of this, though none of them put all the pieces together quite like I have here:
How To Create A Time Machine
- Creating a sparse bundle, and telling Time Machine to use it using
tmutil setdestination
: https://kb.lsa.umich.edu/public/index.php/Backing_up_with_Time_Machine_to_network_storage_using_a_sparse_bundle - Running a script on login: https://stackoverflow.com/questions/6442364/running-script-upon-login-mac/13372744#13372744
- Mounting a sparse bundle from the command line: https://apple.stackexchange.com/a/23523
- Preventing a mounted filesystem from showing up on the Desktop: https://www.idownloadblog.com/2016/12/02/how-to-hide-mounted-volumes-from-desktop-finder/