Apple's TimeMachine now works with Samba SMB2. Apple also is moving to depreciate AFP which was the previously underpinned TimeMachine. Since Yosemite OSX 10.10 it is possible to use samba which in my view is easier and simpler to set up. Read on...
This post assumes that samba is already installed and working with users set up.
1. Create A Sparse Image
First we create a sparse image, which is a resizable type of virtual disk. There are a few reasons for this:
- Time Machine will only write to HFS drives, and this virtual drive is one.
- Unlike other virtual drives, a sparse image only grows when you add information to it – so it will only take up space on your networked drive as needed.
- You can set a maximum size for your sparse image, effectively capping how much of your network drive’s space Time Machine will ever take up.
Open the Terminal, then switch to the Desktop folder:
Now create the sparse image. Here’s a command to start with:
hdiutil create -size 500g -type SPARSEBUNDLE -fs "HFS+J" TimeMachine.sparsebundle
This will create a 500 GB image named “TimeMachine” – change the size to suit your needs (roughly twice the size of your Mac’s storage space is recommended). Thanks to Stephen Morley for the command.
2. Copy Sparsebundle To The Network and Mount It
In Finder open the network folder you’d like to use for your backup. Drag the sparse image you just created to this folder.
Once everything has copied you can then delete the remaining image on your desktop. Now, double-click the copy of the image on your network share – this will mount it. If everything worked, you should see the new TimeMachine drive in your Finder’s sidebar and on your desktop (depending on your settings).
3. Set Time Machine To Backup To Your Mounted Drive
Now for the magic step: telling Time Machine to use your virtual drive for backups. Open the Terminal and enter this command:
sudo tmutil setdestination /Volumes/TimeMachine
If you named your image something besides “TimeMachine”, you’ll obviously need to use that name instead.
Let’s see if it worked! Head to System Preferences, then open the Time Machine settings. You should see your virtual drive as the default backup destination.
Congratulations! Go ahead and run your initial backup, if you want – it’s going to take a while. I recommend you plug your Mac directly into your router with an ethernet cable, instead of using WiFi, and use a program like Caffeine to keep your Mac awake until the initial backup is done.
4. Tell Your Mac To Mount Your Bundle At Boot
So long as your image is mounted, Time Machine will keep backing up. Restart your Mac, however, and you’ll need open the image again before your backups can start. If you’d rather not go through the effort, Sean Patterson has a quick AppleScript you can create to mount the drive for you.
mount volume "smb://
do shell script "hdiutil attach -mountpoint /Volumes/TimeMachineMounted /Volumes/TimeMachine/TimeMachine.sparsebundle"
Note it really helps if your mount point is a different name to the sparsebundle name i.e. TimeMachineMounted vs. sparsebundle TimeMachine.sparsebundle. If they are the same name you will likely experience issues trying to mount the sparsebundle.
Paste Sean’s script into Script Editor (find it in Applications), then change the names to refer to your network share and sparsebundle. Test the result and save it as an Application if it works.
In Users and Groups, you can add the script you just made to your Startup Items – it will run when you log in.
The One Hangup: Can’t Use OS X Recovery
The above process gives you a working Time Machine backup, with one caveat: you cannot use this backup to restore using OS X Recovery. That feature lets you roll back your entire Mac history to a given time, which is useful after a system crash or when you’re replacing a hard drive.
In the case of a total drive failure, you’ll need to reinstall OS X entirely, then mount the Time Machine drive using the steps above. Once that’s done, you can restore your files using the Migration Assistant.
Credit to this guide goes to Justin Pot and the original article here, to which I have made some tweaks: http://www.makeuseof.com/tag/turn-nas-windows-share-time-machine-backup/