NetInfo Recovery Techniques

—Joel Rennich,

4 June 2002

When working with NetInfo, which we are and hope to have some more articles on in the near future, it is important to know how to back up to a previous version of your database.

 First, the most brutal way of recovering from a non-functional database.

Boot into single-user mode by holding down the “s” key while starting up. Follow the handy instructions Apple gives you at the end of the startup sequence and run fsck. Then mount the system root disk as read/write with:

mount -uw /

Now you can get on with recreating your database in a very brutal way. Remove your current database with

rm -rf /var/db/netinfo/local.nidb

Now remove the file that prevents the Setup Assistant from running:

rm /var/db/.AppleSetupDone

And now reboot to get things rolling.

reboot

This will cause the Setup Assistant to launch, complete with music and bouncing blue blobs. If you remember which account you set up first when you last saw this screen, set up that account now. Otherwise, go with whatever you want for your first Administrator account. If you match it up with the original Administrator account, all of your permissions should be groovy. Otherwise, get familiar with chown and chmod and you will be able to set things right.

The above method is rather draconian and isn’t for times when you need to replace a complicated NetInfo setup, but should work perfectly well for an essentially single-user machine. However that probably rules out most Servers.

 So, what if you need more finesse?

Well, if you had thought ahead, you would have already copied your database a safe place. While the /etc/daily script will do an nidump of your local.nidb database, it is a bit of a pain—which we will cover next—to get it back into place. Instead, when you are satisfied with your database, manually make a backup copy with:

sudo cp -R /var/db/netinfo/local.nidb /var/db/netinfo/local.nibak

Needless to say, don’t be doing much else on your machine when you do this. Making any changes to the database during the copy will makes things less than ideal when you need to get back to it.

Now, when the database becomes dazed and confused, you can boot into single-user mode (like above) and—after removing the local.nidb database—issue the following command:

cp -R /var/db/netinfo/local.nibak /var/db/netinfo/local.nidb

Now reboot and enjoy life as it was before everything got messed up.

 Finally, things are bad. You never copied your database. You don’t want to have to redo all of your database.

Fear not, there is another way of doing things, but this is much more involved. Again, you need to boot into single-user mode to perform these operations. After getting a prompt, run fsck and then mount -uw /. You will need to remove what is left of your previous database:

rm -rf /var/db/netinfo/local.nidb

Then create a new blank database:

nicl -raw local.nidb -create

You will now need to create a root user entry, or else the script we run next won’t be able to start things up.

nicl -raw local.nidb -create /users 
nicl -raw local.nidb -create /users/root 
nicl -raw local.nidb -create /users/root uid 0

Now you need to load your backup into your new database. NetInfo needs to be up and running to do this, so start it up by running the Systemstarter script. This will start up a lot of other services, but is the easiest way to do this.

Systemstarter

Now load your backup into your newly minted database with

niload -r / . < /var/backups/local.nidump

Get the machine rebooted with

reboot

And get on with your life.