Storing backups on NFS is not an officially supported by Apple, but is quite easy to do.
NFS server side
The server can be any BSD or Linux. The first thing to do is to check the Unix user id on the Mac and NFS server (you can find it by typing id
in the terminal). It is best if the user id on both systems is the same (less file permissions problems…).
You can create a new user account with a specific id by:
1 |
useradd -m -u 501 mac-user-name |
(-m
creates home directory, -u
specifies user id)
/etc/exports
I will not make this post a generic NFS-howto, so I will only stick to the relevant parts of setting up NFS.
/etc/exports
file contains directories the server makes available to other clients over the network. It should have something like this:
1 |
/home/mac-user-name 192.168.1.20(async,rw,no_subtree_check,insecure) |
The IP should be the Mac’s LAN IP.
Mounting NFS share on OS X
After restarting NFS services on the server you can try mounting the share manually to see, if the settings and permissions are okay. Mount command:
1 2 |
sudo mkdir /private/nfs sudo mount -t nfs -o soft,intr,rsize=8192,wsize=8192,timeo=20,retrans=3,proto=tcp nfs_server_name:/home/mac-user-name /private/nfs/ |
If no error messages are shown, then mount succeeded and any file created in /private/nfs/
should be visible on the server.
Automounting at startup
First: get root privileges by using sudo su
, then you have to create a file called /etc/auto_nfs
with the following contents:
1 |
/private/nfs -fstype=nfs,soft,intr,rsize=8192,wsize=8192,timeo=20,retrans=3,proto=tcp,locallocks nfs_server_name:/home/mac-user-name |
Second: add this single line to /etc/auto_master
:
1 |
/- auto_nfs -nobrowse,nosuid |
Then you can test if it works:
1 2 |
umount /private/nfs automount -cv |
Great, now the NFS directory should be automatically mounted at every startup.
Creating a sparse bundle
Time Machine can only store backups on a HFS+ filesystem. To use it over NFS you have to create a virtual filesystem in the NFS directory – it is called a sparse bundle. The HFS+ sparse bundle is a group of files (8MB each), that can be mounted by OS X and used as a regular hard drive (it is similar to a .dmg
file). It is called “sparse”, because you specify the size of virtual disk at the moment of creation (you can expand it later, but you can not shrink it), but it is as large as the data within (ie. a 500GB sparse bundle with 10GB of data inside will occupy roughly 10GB of real disk space).
This command creates a sparse bundle (run as normal user):
1 |
hdiutil create -size 500g -type SPARSEBUNDLE -nospotlight -volname "TimeMachine" -fs "HFS+J" -verbose /private/nfs/timemachine-mac-user-name.sparsebundle |
The size (500g here), should be at least the size of the disk you have in the Mac. If it is larger, then Time Machine will be able to store more history. An empty sparse bundle occupies about 500 megabytes.
Automounting the sparse bundle at startup
This was the most tricky part to figure out. Some tutorials suggest using AppleScript. I did this using Automator.
Start Automator, create a new application, add a shell script component with the following code:
1 2 3 |
#!/bin/bash hdiutil attach -mountpoint /Volumes/TimeMachine /private/nfs/timemachine-mac-user-name.sparsebundle exit 0 |
You can test the app directly in Automator (button in upper right corner of the window) – a disk called TimeMachine should appear on the desktop.
After saving this app somewhere on the disk you can add it to login components (drag the app from Finder to System Preferences -> Users&Groups -> Login items).
Time Machine configuration
Final steps:
1 2 3 |
sudo tmutil setdestination /Volumes/TimeMachine sudo tmutil disablelocal sudo tmutil enable |
First line sets the destination disk – the sparse bundle mounted by Automator, second line disables local snapshots, third enables Time Machine. That’s all 🙂
Local snapshots are a kind of partial backups that are stored on the local drive, they can speed up making backups and restores if the Mac was not connected to the NFS server. Local snapshots consume some disk space.