mlocate-split - Split mlocate.db based on directory prefixes
mlocate-split [--database=DB] [--transform-path FROM=>TO]... prefix prefix2:db ...
- --database=DB
-
Database to split. The database has be in the format described by mlocate.db(5). If not specified /var/lib/mlocate.db is used.
- --transform-path "FROM=>TO"
-
Before written to its new database, paths can be be transformed. The argument left of the arrow is the left operand to perls substition operator and the right argument its replacement. The option can be given multiple times and the substitions will be applied in order.
This can be useful, if the the original database indexes paths under a differant mount point than on the client machines. Homedirectories could be mounted on /export/home/... on the file server and on /home on the clients. Only afer applying /export/home=>/home the clients would be able to find the files at the right location.
mlocate-split reads the database and creates new databases for all files under the specified directory prefixes. The prefix can contain a colon. In this case the substring before the colon is the directory prefix and the part after specifies its database file. If no file for the new database is provided, the filename is assumed to be prefix/.mlocate.db.
This script was mainly developed to help users find their files faster. Home directories are often mounted from the fileserver, so the local mlocate database doesn't contain their files. This resulted various search tools to just call find over and over gain for every new search. It would be possible to execute updatedb to also index network filesystems but this would have been strenous and pointless as the mlocate.db on the server has already been updated. With this script it's possible to just split the servers mlocate.db and save a userspecific mlocate.db in their home directory.
To use this new databases just add it to the users $LOCATE_PATH.
getent passwd | \
perl -F: -lane 'print "/export$F[5]" if $F[5] =~ m{/home/\w+/\w+}' | \
xargs /usr/local/bin/mlocate-split --transform-path '/export/home=>/homelocatedb(5), updatedb(1), locate(1)
Mario Domgoergen <mario@domgoergen.com>