How to fix slow Spotlight and Time Machine after upgrading to 10.7.5?

Since updating to 10.7.5 both Spotlight and Time Machine are very slow.

  • To index a normal system drive Spotlight calculates to need several days.
  • As a result Time Machine takes up to an hour or more for an incremental backup of ~100 Mib.

What solution is there for these slow Time Machine backups and Spotlight indexing?


The OS X Lion 10.7.5 Supplemental Update released October 04, 2012 includes:

Resolves an issue that may cause Time Machine backups to take a very long time to complete

and, after testing, this seems to have completely resolved the issue.

Note that for me, the first backup after installing this update still took unexpectedly long, and included many com.apple.backupd[423]: Waiting for index to be ready (100) messages, so maybe Spotlight hadn't yet properly re-indexed the drive. Now, a couple hours later, small backups complete at their usual brisk pace and all is well.


I posted this workaround in that topic. Here it is (it is not a solution, only a temporary workaround to let my backup and Spotlight work until a fix is released).

Using Terminal:

  1. I disabled Spotlight indexing:

    sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.metadata.mds.plist
    
  2. I deleted Spotlight index in all my drives (including the backup drives):

    sudo rm -rf /.Spotlight-V100/Store-V1 /.Spotlight-V100/Store-V2  /.Spotlight-V100/VolumeConfiguration.plist
    
    sudo rm -rf /TimeMachineDrive/.Spotlight-V100/Store-V1 /TimeMachineDrive/.Spotlight-V100/Store-V2  /TimeMachineDrive/.Spotlight-V100/VolumeConfiguration.plist 
    

(rm -rf /.Spotlight-V100/* did not work for me.) (This can also be done by excluding the whole drive using privacy setting of Spotlight and then reincluding it.)

  1. I deleted /var/folders content (see this topic to know why):

    sudo rm -rf /var/folders/*
    
  2. I deleted the .inProgress files from my Backups.backupdb subfolders (put to trash then empty the trash is the only way to do this).

It may be necessary to reformat your backup drive instead of only deleting .inProgress files.

  1. I rebooted and then I restarted Spotlight:

    sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.metadata.mds.plist
    
    sudo mdutil -i on -E /
    
  2. I waited until Spotlight finished indexing process

  3. I launched a new backup using TimeMachine

  4. I opened a bugreport to Apple with the title: "TimeMachine hangs when Spotlight is in use under Mac OS X 10.7" praying that many other people will do the same to make this bug a priority.

Some steps may be useless, but I took all what I learn by reading different topic about slow TM and Spotlight.


Check your console log file and look for lines like this (the real log lines will have process IDs and dates):

sandboxd: mdworker deny mach-lookup com.apple.ls.boxd
mdworker: Unable to talk to lsboxd

If you're seeing that, it is probably the source of the problem. Something Appple did with this latest release (also affects Mountain Lion 10.8.2).

I don't know what's really going on other than to say that mdworker (which scans and indexes files for Spotlight) calls LSCopyLibraryItemURLs() which eventually sends a message to lsboxd. The Sandbox policy doesn't allow that, so the worker is killed.

So maybe the policy file is wrong, or maybe mdworker shouldn't be making that call. I don't know. However, fixing the policy file is relatively easy. POTENTIALLY DANGEROUS, but easy.

Edit these files as root:

/usr/share/sandbox/mdworker.sb
/usr/share/sandbox/mdworker-bundle.sb

Inside the files you'll find the line:

(allow mach-lookup (global-name "com.apple.ocspd"))

Right below it, add the line:

(allow mach-lookup (global-name "com.apple.ls.boxd"))

That's it!

If you want extra comfort, maybe reboot. Maybe erase your spotlight index and start over:

sudo mdutil -E /

In fact, I still see mdworker: Unable to talk to lsboxd in my log files but at least now the indexing will finish and Time Machine moves quickly again.


You can completely fix all the mdworker related sandbox errors in Console (including the cannot talk to lsboxd) by editing the system.sb profile rather than the mdworker ones. The system.sb file is used by all Apple system processes that run under the sandbox, including mdworker. If you modify this file (which is located in /System/Library/Sandbox/Profiles) to include:

(allow mach-lookup (global-name "com.apple.ls.boxd"))

(allow mach-lookup (local-name "com.apple.ls.boxd"))

This will stop all the lsbox related mdworker issues.