How to use any SMB share for Time Machine backups

For some 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:

Instructions

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 disk images, but only take up as much storage as necessary and internally consist of many smaller files. With these properties they are ideal for network storage. 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" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>Label</key>
	<string>us.yugen.timemachineautomounter</string>
	<key>ProgramArguments</key>
	<array>
		<string>sh</string>
		<string>-c</string>
		<string>/usr/bin/automator /Users/andreas/Documents/Scripts/TimeMachineAutoMounter.workflow >> /Users/andreas/Documents/Scripts/TimeMachineAutoMounter.workflow.out 2>&1</string>
	</array>
	<key>RunAtLoad</key>
	<true/>
	<key>StartInterval</key>
	<integer>300</integer>
</dict>
</plist>

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 it loses connection – 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 your machine loses connection, it will reestablish it automatically. Whenever it is available, Time Machine will resume backing up.

Suggested links and sources

https://blog.macsales.com/43946-tech-101-how-to-schedule-time-machine-backups/
https://www.imore.com/how-use-time-machine-backup-your-mac-windows-shared-folder


Posted

in

, , , ,

by

Tags:

Comments

4 responses to “How to use any SMB share for Time Machine backups”

  1. Sam Hardeman Avatar
    Sam Hardeman

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

  2. anton Avatar
    anton

    Thanks for the details.

    I applied to my MAC. The sparsebundle drive does not show up as an option to mount with timemachine. Only the SMB drive shows up. I can mount the SMB drive. Timemachine creates a sparsebundle by itself, but then it fails with the message backup disk could not be created.

    1. anton Avatar
      anton

      Figured out I had not changed the automator script totally. It works great.

      1. Andreas Hartmann Avatar

        Thanks for the update, glad this is still working!

Leave a Reply

Your email address will not be published. Required fields are marked *

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