Mac OS X Spotlight Indexing
This page provides various information for running Spotlight (MDS) commands using the Terminal.
Spotlight is an indexing search system and is part of Mac OS X. By default spotlight is enabled on Mac OS X 10.4 and later.
The load on a backup server with spotlight enabled may be considerable. This is particularly ture if your backup server is backing up multiple servers / clients. If Spotlight is enabled on your backup directories then your backup server will index all files which are being backed up and stored within your backup set(s).
If your backup server(s) is struggling to keep up with indexing additonal files which are generated as part of each snapshot, you may wish to consider disabling spotlight on your server(s) backup volume(s) in an effort to improve backup performance. The downside of disabling Spotlight on backup volumes is that you will not be able to use spotlight to search for information within your backup sets using the commands listed below.
Finally, you may wish to consider disabling Spotlight on your source drive while you are perfuming a backup. this may be achieved by adding a pre and post hook action into your backup configuration.
Spotlight Search Commands
The commands below should assist you if you are trying to use spotlight to find a file using the CLI on a Mac OS X system.
- Please note that the following commands will only work if spotlight is enabled on the volumes you wish to search.
- Also note that spotlight may not search all areas of disk.
Spotlight search
mdfind searchterm
Spotlight search within a specific directory
mdfind -onlyin /path/to/your/search/directory searchterm
Spotlight meta data search
mdfind "kMDItemAuthor == '*authername*'"
List available meta data fields on your system
mdls filename
Spotlight Volume Commands
The commands listed below will allow you to use the CLI on a Mac OS X system to alter configuration of Spotlight indexing for individual volumes.
Spotlight indexing status for a volume
mdutil -s /Volumes/volumename
Disable spotlight indexing for a volume
mdutil -i off /Volumes/volumename
Enable spotlight indexing for a volume
mdutil -i on /Volumes/volumename
Remove spotlight index for a volume
mdutil -E /Volumes/volumename
Check spotlight status for a all mount points within “/Volumes/“
for v in /Volumes/* ; do mdutil -s "${v}" ; done
Disable Spotlight System Wide
If you wish to completly disable spotlight on a system wide basis then edit the file below :
/etc/hostconfig
Within the hostconfig file change
"SPOTLIGHT=-YES-"
to
"SPOTLIGHT=-NO-"
Finally, you will need to reboot your system.
Disable Spotlight for one Directory
There are various ways to disable spotlight indexing in certain directories. One easy approach is to use the .noindex
extension for your directory name. As an example, if you want to disable spotlight indexing for your backup directory, then you could add call your backup directory something like the example path below :
/Volumes/backup_drive_1/backup.noindex
There are also other approaches to achieve the same thing. However, this approach is very simple.