Mac OS X: Recovering NetInfo Domains from Backup
Mac OS X keeps a lot of its configuration information (e.g. users & groups)
in a NetInfo database.
Good News: This is very handy for sharing configs across a local network.
Bad News: can be a headache if something goes wrong with the database.
Good News: the database can be backed up -- in fact, if you leave your computer
on overnight, it'll get backed up automatically every night.
Bad News: 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 (as far as I can find, anyway) provided a simple way to recover
the backup on a hosed system.
Good News: it can be done. Here's the procedure I worked out (this should work on
any version of Mac OS X Server between 10.1 and 10.3.x. I Think it'll also work in
10.4, but I haven't fully tested it):
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.
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.
If it refuses to check because the filesystem is journaled, that's fine; just go on.
Use the command "mount -uw /" to remount the boot disk with write
access enabled.
"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.
"cd /var/db/netinfo" this gets us to the directory where the
live NetInfo databases are kept.
"mv local.nidb local.nibad" inactivate the damaged database
by giving it an invalid name.
"nicl -raw local.nidb -create" build a nice clean (empty)
replacement database in its place.
"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.
"ifconfig lo0 127.0.0.1 up" bring up just enough of networking
to let us use a local netinfo server.
In 10.1-10.3: "netinfod -s local" start a local netinfo
server, serving the new (blank) database we just built.
In 10.4: "netinfod -s local &" start a local netinfo
server. The difference between this and the 10.1-3 version is that it
doesn't "daemonize" itself (i.e. go into the background so you can continue)
-- you have to add an ampersand to the end of the command to force it to
run in the background. If you leave the ampersand off, the computer will
appear to hang; don't panic, just type ^z (that is, hold down control and
type z), then use the command "bg" to retroactively background
the netinfod program.
"netinfod -s local" start a local netinfo server, serving
the new (blank) database we just built.
"niload -r / . </var/backups/local.nidump" load the
contents of the backup into the new (live) database.
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.
"reboot" restart the system, this time in a more normal fashion.
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.
[Added 11/22/02:]
Apple has now published a knowledgebase
article on recovering NetInfo, giving a somewhat more complicated procedure.
|