Tips


Recovering NetInfo Domains from Backup

Mac OS X keeps a lot of its configuration information (e.g. users & groups) in a NetInfo database. This is very handy for sharing configs across a local network. However, this can be a headache if something goes wrong with the database. The database can be backed up -- in fact, if you leave your computer on overnight, it'll get backed up automatically every night. Unfortunately, the backup is in a different format (nidump's "raw" format – which is completely different from nicl -raw) than the live database, and Apple hasn't provided a simple way to recover the backup on a hosed system.

Nevertheless, it can be done. Here's the procedure:
  1. Boot the computer into single-user mode by holding down Command-S as it begins to boot. It'll spew some information about the boot sequence, then drop you into a command line. At this point, the system is only partly started -- most important for our purposes, NetInfo hasn't been started yet. But also a lot of other things haven't been done that'll need to be taken care of by hand, like getting the boot disk checked and mounted for write access.
  2. Use the command "fsck -y" to check the integrity of the boot disk's file structure. If it makes any repairs (it'll print "***** FILE SYSTEM WAS MODIFIED *****"), run it again. Keep running it until it stops finding problems.
  3. Use the command "mount -uw /" to remount the boot disk with write access enabled.
  4. "ls -l /var/backups" – this prints a list of everything in the backups directory. It should respond with something like:total 40

    -rw-r--r-- 1 root wheel 19001 Aug 4 03:15 local.nidump

    The date on the file (in this case "Aug 4 03:15") indicates when the backup was made. If it's not from a time when the computer was working right, or if the response doesn't list a file named "local.nidump" (e.g. if it simply gives you the localhost# prompt without printing anything first), you don't have an appropriate backup, and these instructions won't work for your situation. Sorry.
  5. "cd /var/db/netinfo" – this gets us to the directory where the live NetInfo databases are kept.
  6. "mv local.nidb local.nibad" – inactivate the damaged database by giving it an invalid name.
  7. "nicl -raw local.nidb -create" – build a nice clean (empty) replacement database in its place.
  8. "nicl -raw local.nidb -create /users/root uid 0" – for one of the later steps, we need the root user to exist in NetInfo, so create it now.
  9. "SystemStarter" – start up more of the system, including the NetInfo and lookupd infrastructure.
  10. "niload -r / . Notes: be careful to use "<", not ">". ">" will erase your backup file. Also, be patient; it can take a minute to rebuild the entire database. But if it takes more than 10 minutes or so, something probably went wrong, and you may need to start over.
  11. "reboot" – restart the system, this time in a more normal fashion.
  12. If all goes well, you can now delete the damaged NetInfo database, /var/db/netinfo/local.nibad (or whatever you renamed it to). If not, or if you don't trust the rebuilt database, hang onto it; you can always switch back to it if necessary.

«Go Back