How to use any SMB share for Time Machine backups

For some stupid reason, Apple only allows Time Machine backups to SMB servers that fulfill certain requirements. Some brand name NAS machines work, others don’t. I want to to use my AVM router for backups, but the application won’t let me. Googling reveals some old solutions involving custom scripts – which should work, but here is a an IMO more elegant solution to use any SMB share for Time Machine backups, that doesn’t fail even if the network drive is disconnected:


Create Time Machine image on the SMB share

Use the disk utility to create a sparse bundle (File -> New Image -> Blank Image). These are like images, but only take up as much storage as necessary and internally consist of many smaller filed, so they are perfect for being placed on the network. Make sure the size is sufficient for your backup. Place it on the network share you want to use.

Automate mounting the SMB share and Time Machine image

Next comes the magic – we need to automate connecting to the share and mounting the Time Machine bundle in the background. For that, launch the Automator App and build this simple workflow:
Get Specified Servers (add the SMB share root) -> Connect to Servers | (ignore input) | Get Specified Finder Items (add the Time Machine File) -> Open Finder Items.
It should look something like this:

Use the play button in the top right corner to run it once. You may get asked to log in to the share, so make sure to save that login. Any subsequent executions should work without any prompt and if the share/Time Machine are already connected, there should be no issues.
Save this workflow at some location, for example your Documents folder.

Automate the workflow with launchd

Now we just have to make this workflow run automatically. Use the terminal or the finder (with hidden files being displayed) to create a new “.plist” file in /Users/<username>/Library/LaunchAgents. I named mine “us.yugen.TimeMachineAutoMounter.agent.plist”. Edit it with a text editor of your choice and just paste this:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "">
<plist version="1.0">
		<string>/usr/bin/automator /Users/andreas/Documents/Scripts/TimeMachineAutoMounter.workflow >> /Users/andreas/Documents/Scripts/TimeMachineAutoMounter.workflow.out 2>&1</string>

Adjust the paths to match the path to your .workflow file. You may also optionally remove this part if you do not want a log file, though it may help troubleshooting: /Users/andreas/Documents/Scripts/TimeMachineAutoMounter.workflow.out 2>&1
You can also change 300 to something else – this is the interval in seconds at which it will retry to connect to the share if the connection is lost – 5 minutes seems reasonable.

Next, launch the terminal and enter:
launchctl load /Users/<username>/Library/LaunchAgents/<plist file name>
And then once you see the time machine mounted in the Finder, execute:
sudo tmutil setdestination /Volumes/<name of time machine image>/
That is necessary, because the Time Machine GUI still won’t let you select the image you created for backups.

That’s it! With this, you can use any SMB share for Time Machine backups, your SMB share and time machine will be mounted automatically. If the connection is lost, it will be automatically reestablished. Whenever it is available, Time Machine will resume backing up.

Suggested links and sources

1 comment

  1. Thank you very much for this guide! Works perfectly, now I can use my Linux backup share.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.