Time Machine via NFS on Mavericks

Here is my way of using nfs as time machine backup.
Avoid NFSv4 on Mavericks, it’s terribly unstable. NFSv3 is as fast as Netatalk in my environment.

1. Configure NFS server. The exports should at least have these options below.

rw,no_subtree_check,insecure,no_root_squash

2. Mounting NFS share from Mac by automount.

Create a file containing mount options. Make sure to use vers=3,resvport and locallocks, at least.

Format: “name of the mount directory you want to see in Finder” “nfs options” “nfs device directory”
e.g. vi /etc/auto_nfs
Backup -fstype=nfs,vers=3,rw,soft,intr,rsize=32768,wsize=32768,noatime,timeo=1200,
retrans=10,proto=tcp,resvport,locallocks,noacl 192.168.1.1:/srv/nfs/Mac

Edit /etc/auto_master, write mount point and filename of the text file created above.

Format: “mount point” “name of the text file you created above”
e.g. vi /etc/auto_master
/Users/Shared/NFS auto_nfs
Invoking automount.

sudo automount -vc

3. Create a disk image for time machine. Change the size to your liking, it won’t take actual space in the disk. Command below create sparsebundle image under current directory. Any volname, and sparsebundle filename is acceptable.

e.g
hdiutil create -size 500g -type SPARSEBUNDLE -nospotlight -volname "TimeMachine" -fs "Case-sensitive Journaled HFS+" -verbose ~/timemachine.sparsebundle

4. Move the disk image to NFS directory you mounted, and remove the local sparsebundle disk image

e.g.
rsync -avE timemachine.sparsebundle /Users/Shared/NFS/Backup/TimeMachine/
rm -rf timemachine.sparsebundle

5. Setting NFS share as time machine destination
Mount the remote sparsebundle image.
e.g.
hdiutil attach -verbose /Users/Shared/NFS/Backup/TimeMachine/timemachine.sparsebundle
Set the image as destination of time machine backup.
e.g.
sudo tmutil setdestination /Volumes/TimeMachine

6. Set sparsebundle image to be attached automatically. Probably, this step is unnecessary.
Open System Preference, Select Accounts, Select your Account, Click on Login components tab, and drag the sparsebudle image on NFS and drop it to the list.

7. Start the first backup from the GUI. I recommend using TimeMachineEditor to schedule backup if you think it’s just plain stupid to take hourly backups of home-use
laptop like me.

Disable another annoying feature of Time Machine by the command below.
sudo tmutil disablelocal

8. How to use TimeMachine in Recovery Mode
I am not sure what happens when NFS share is mounted on the MacintoshHD volume.(OS intallation partition),
so in here, I mount it on the recovery partition.

Creating mnt directory in recovery hd for mounting
i. defaults write com.apple.DiskUtility DUDebugMenuEnabled 1
ii. select show every partition in debug tab in disk utility, and mount it.
iii. mkdir /Volumes/Recovery¥ HD/System/mnt
iv. unmount the disk
v. defaults write com.apple.DiskUtility DUDebugMenuEnabled 0<

Boot into recovery mode, and mount the NFS. You might want to write a simple bash script containing these commands and place it on recovery disk for convenience.
e.g.
mount -t nfs -o vers=3,rw,soft,intr,rsize=32768,wsize=32768,noatime,timeo=1200,retrans=10,
proto=tcp,resvport,locallocks,noacl 192.168.1.1:/srv/nfs/NFS /Volumes/Image¥ Volume/System/mnt

Mount the sparsebundle image.
e.g.
hdiutil attach -verbose /Volumes/Image¥ Volume/System/mnt/TimeMachine/timemachine.sparsebundle

That’s all!
You should see your disk in TimeMachine GUI.
Don’t close the lid during recovery, otherwise it pauses.
Please leave a comment if you have any better option.

Advertisements
Previous Post
Leave a comment

32 Comments

  1. Render

     /  January 24, 2014

    Thanks man, this saved a lot of time! It works also on Mountain Lion 10.8.5.
    I would not disable ACL’s in /etc/auto_nfs if you have them on the NFS-server.
    And now i can pack up work and have a beer 😉

    Reply
    • Thank you for leaving a comment.
      I am glad to be your help!
      Yeah, ACL should not be disabled if your machine can be in unsecure environment.
      My machine is staying at home all the time and behind NAT and some ip filters,
      so I disabled it.

      Reply
  2. Dan Pritts

     /  April 30, 2014

    you’ve been a few months now. Have you run into the notorious corrupt backup issue that seems to happen all the time with netatalk?

    Reply
    • Thanks for commenting.
      I am using network file system aka NFS, not netatalk.
      So far I haven’t had any problems. I’ve restored the system and also some files a few times with no problem whatsoever.

      Reply
    • I experience corruption for netatalk for a long time (occurred once a month or so). Since switching to NFS, no problems in more than six months, and backups are also much faster.

      Reply
  3. Fred

     /  May 24, 2014

    Thanks for the write up!

    At the end of the line to add to auto_nfs, you use “192.168.1.1:/srv/nfs/Mac”. What finally worked for me was “nfs://192.168.1.1/blah/blah” (blah/blah = nfs volume name and location)

    Reply
    • Thank you for providing another info, Fred.
      I approved your other comments anyway in case some other people find them useful in some way.
      Maybe I should try what happens if I add nfs:// in the front. It might be a more standard way to put it.

      Reply
  4. Fred

     /  May 24, 2014

    OK, I got it working and it’s actually backing up as I type. However I’m new to OS X / Time Machine, and would like to better understand what would happen in a recovery. I can see file restores working easily, but how would a system restore work. It seems like a Mac booting in some sort of restore mode (or worst-case, all new hardware) might not know how to access the NFS drive? Could you help me understand if that’s an issue (and if it is, what data/instructions I should have at the ready) or why it’s not a concern? Hope that’s not a stupid question.

    Thanks again for saving a lot of people the cost of a dedicated drive.

    Reply
  5. Fred

     /  May 24, 2014

    D’OH! – I just saw that you explained exactly that at the end of the instructions. Don’t know how I missed that. Feel free to NOT approve this and my previous comment.

    Reply
  6. Mircea

     /  May 25, 2014

    Hi, thanks for posting this tutorial. I’ve been using netatalk until now and have been having lots of “corrupt backup” problems. How’s your system going until now? Any issue or still running strong? I’m considering switching to NFS, but it’s a “big investment” (would need to transfer almost 1TB of backups). Any info would be greatly appreciated. Thanks!

    Reply
    • I’m doing weekly backup with no problem so far. I did system recovery only a few times, and retrieved files from TM only occasionally, though.

      If switching to NFS is a big bother, I think you should find out the cause of currupt backups before doing so.
      I doubt there is a bug with netatalk if you are keeping the software up-to-date, since it is unlikely that all versions of
      netatalk have currupt backup problems.

      I heard time machine does not check data integrity. So if your machines, or networking are unstable, probably switching to NFS won’t help.
      1TB is really big, If I were you, I would get a gigabit ethernet switch, if I have not already got one.

      Reply
  7. Dan Pritts

     /  June 10, 2014

    Copy & paste of the commands in this blog entry won’t work. WordPress (presumably) has ever-so-helpfully put in “smart quotes”, which the unix shell most definitely does not like.

    Reply
  8. Tim

     /  July 12, 2014

    Hi Smekkley, Thanks for the clear and informative instructions, i certainly feel like they should work. For me though, when i mount my sparsebundle and tmutil setdestination it the TimeMachine still fails to find it. It is listed as a “Backup Disk” but not as “Available”.

    I wonder if you or any other readers have had this problem and can point out what i have done wrong.

    Regards,

    Reply
  9. Tim

     /  July 13, 2014

    Re. My previous Comment:
    I found that although the TimeMachine GUI would not initiate a backup on the mounted sparsebundle the commandline tools worked.
    tmutil backup -d

    I am mounting my sparse bundle from a samba share so i chose to do the first backup via USB3. It was ~55Gb and took about 6 hours. All consequent backups have been done over the network and have been ~10min.

    Thanks for the primer Smekkley.

    Reply
    • Thank you for leaving comments. I’m glad you found the solution.

      Does TimeMachineEditor work? I’m curious.
      If not, probably you need to use launchd to schedule periodic backup.

      Reply
      • Tim

         /  July 15, 2014

        Hi Smekkley, is TimeMachineEditor the GUI ? If so then no. The mounted sparsebundle always look unavailable from this view.
        I turned off local backups and scheduled the “tmutil backup” via a ~/Library/LaunchAgents plist file.

    • I meant the TimeMachineEditor, the third party application.
      Anyway, if you are successful running periodic backup, I’m happy.
      Thank you for sharing valuable infomation.

      Reply
  10. I get the following error at step 3. – any ideas?

    $ hdiutil create -size 500g -type SPARSEBUNDLE -nospotlight -volname “TimeMachine” -fs “Case-sensitive Journaled HFS+” -verbose ~/timemachine.sparsebundle
    hdiutil: create: Only one image can be created at a time.
    hdiutil: create: returning 0
    Usage: hdiutil create [options]
    hdiutil create -help

    Reply
  11. woolfiegravatar

     /  October 25, 2014

    Meant to add…. this is the command that worked:
    sudo hdiutil create -size 500g -type SPARSEBUNDLE -nospotlight -volname “Backup of my computer” -fs “Case-sensitive Journaled HFS+” -verbose ~/Desktop/”Backup-Name.sparsebundle”

    Reply
  12. Florent

     /  January 16, 2015

    hi and thank’s u for explains. But i’m very grrrrrrrrr, because in step 4, error.

    see this :

    sh-3.2# rsync -avE timemachine.sparsebundle /Users/Shared/NFS/Backup/TimeMachine/
    building file list … done
    rsync: mkdir “/Users/Shared/NFS/Backup/TimeMachine” failed: No such file or directory (2)
    rsync error: error in file IO (code 11) at /SourceCache/rsync/rsync-45/rsync/main.c(544) [receiver=2.6.9]
    rsync: connection unexpectedly closed (8 bytes received so far) [sender]
    rsync error: error in rsync protocol data stream (code 12) at /SourceCache/rsync/rsync-45/rsync/io.c(453) [sender=2.6.9]

    Have you an idea ?

    thank’s a lot for your answer.

    Florent.

    Reply
  13. Florent

     /  January 16, 2015

    oh sorry, error with case, thank’s a lot for all.

    Reply
  14. Hello, I’ve been holding to upgrade to Yosemite, but recent Office requires me to do so. I have two question:

    First, If I use this technique by using our office NFS, then what happened when I took my Mac (Air) outside of the office, where it can’t connect?

    Second, If I upgrade to Yosemite in the future, by wiping all the data after doing time machine backup on NFS, is it possible to fully restore to my current state (Downgrade to Mavericks, with everything preserved / before wiped state) ??

    Thank you.

    Reply
    • hi.

      when your mac is unreachable to nfs server, it simply fails to do incremental backups.
      it might try to preserve failed backups locally and fills up its disk.

      this guide is intended for mavaricks, so i don’t know whether this method works on yosemite. I believe it is possible. It is unlikely that apple bothers to disable the feature.

      i don’t recommend making backups to nfs server over which you don’t have a complete control. There might be permissoin problems and other unexpected problems.
      Network should be as stable as possible as well. timemachine uses as much bandwidth as it can, and it will affect other users on the same network if the capacity is not too big.
      You might as well buy raspberry pi and external hdd and build a nfs server.

      Reply
  15. For just a random note, this one is really helpful and great. 😉

    Reply
  16. What type of filesystem for Time Machine are you holding on the NFS server?? As I understand it, HFS+ rw with journaling is not compatible with current Linux kernel support for HFS+.. they say it can only be mounted rw with journaling disabled.. So I assume you are using HFS+ with journaling disabled?? Or are you also able to use other filesystem for this purpose (FAT32/NTFS/extX)?

    Reply
    • Hello, thank you for leaving a comment.

      I used btrfs and ext4 for NFS, and it worked fine.
      From my understanding, sparse bundle disk images can be created on any filesystem.
      It is the sparse bundle imaged that is formatted as Journaled HFS+, not the filesystem it resides in.
      So from the viewpoint of the TimeMachine client, it is backing up to HFS+ filesystem on NFS or whatever network filesystem being used, and the client is not aware of the filesystem used for the network filesystem.

      Reply
  17. I have a problem with El Capitan. When I boot from Recovery HD and try to attach image (to restore system from TM backup) hdiutil says that there are no mountable filesystems (error 112). However when I boot to my system, I can open this image there.

    Reply
  18. Black Magik

     /  June 24, 2016

    Hi,I have a problem to perform the recovery using a Key with the Apple Recovery Assitant; I’ve do all the operations shown above but when i try to mount the NFS the system says: mount_nfs can’t mount … Permission denied
    I’ve searched and i’ve found that there is in El Capitan a file-system protection system, called System Integrity Protection that can be disabled using csrutil disable but it doesn’t function on the Recovery Assistant because i’ve always the same error…

    Reply
  1. Installing OS X on native hardware via VMware – /* BeejBlog */

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: