NetInfo Backup

Today's Best Tech Deals

Picked by Macworld's Editors

Top Deals On Great Products

Picked by Techconnect's Editors

Because making changes to your NetInfo database can have such drastic consequences, you never want to make changes without first making a backup of the database itself. In Mac OS X 10.2 and earlier, NetInfo Manager supposedly allowed you to make a backup of your database from within the application (Management: Save Backup). However, many users found this method to be problematic; sometimes it worked, sometimes it didn't. To make matters worse, sometimes you got an error message, sometimes you didn't -- and even if you got a message, the error didn't necessarily correspond with whether or not the procedure was successful! It would have been great if Apple had fixed this bug in the OS X 10.3 version of NetInfo Manager, but they took a different approach -- they simply got rid of the command altogether.

So... you basically have to fend for yourself when it comes to backing up your NetInfo database (although, as I explain below, OS X will automatically create a backup, if you let it). The steps here show you how to back up your NetInfo database, and a couple ways to restore it, if necessary. I also show you how to "rebuild" it from scratch as a last resort.

Backing Up the NetInfo Database

The easiest, and most reliable, way to back up your NetInfo database is using Terminal:

First, launch Terminal (/Applications/Utilities/Terminal). At the prompt, type the following (all on one line, preserving all spaces as indicated; case is important in Terminal, so make sure you copy case correctly):

cd /private/var/db/netinfo

Press returnm then type

sudo cp -R local.nidb local.nidb.backup

Press return.

When you are prompted for a password, type your account password (you must be an admin user, of course).

The cp command copies the existing database, local.nidb, to a new file in the same directory called local.nidb.backup ; since the database is actually a directory of files, the –R option tells cp to copy the directory and all files within it. The sudo command -- which asked for your password -- provides you with the temporary root access needed to be able to write a new file to that directory.

Now you've got a backup copy of your NetInfo database. It's a good idea to use this procedure each time you make changes to NetInfo. In fact, if you're not the type to back up your computer regularly, it's also not a bad idea to back up your database after adding, deleting, or modifying user accounts using System Preferences, since such changes are actually editing the NetInfo database. If you're especially cautious, you can name the backup files differently each time you make changes to the database ( local.nidb.backup1, local.nidb.backup2, and so on) so that you have a backup of each generation of changes. (If you don't back up to a new, differently named, copy each time, make sure you delete the previous backup copy first; you can do so using the following command in Terminal: sudo rm -R /var/db/netinfo/local.nidb.backup.)

Restoring Your NetInfo Database from a Backup

Method #1: Using Your Own Backup

If you spend a lot of time working with NetInfo, there's a chance that at some point you'll make a mistake, or the database will become corrupt, or, for lack of a better explanation, your NetInfo database will just get screwed up. When this happens, you might see funny things like home folders not being where they should be, or you may find that you can't even boot the computer -- you never see the login screen. At this point, you'll be glad you made that backup, because the first step you should take in fixing things is to restore your NetInfo database from a reliable copy.

To do this, you need to boot into what is known as single-user mode . Single-user mode is a limited way of working directly with the file system of your Mac OS X computer without actually logging in as a user. What you see in single-user mode looks a lot like what you'd see in a Terminal window -- text on a black screen. The benefit of single-user mode is that in most cases you can use it even if you can't boot up or log in to OS X. (Even if you can log in, you should still use single-user mode to restore your NetInfo database, since the current database is in use when you're logged in and cannot be replaced).

1. Reboot or start up your Mac; immediately press and hold command-S. You'll see a bunch of text scroll by, until you see the following:

Singleuser boot -- fsck not done
Root device is mounted read-only
If you want to make modifications to files,
run ‘/sbin/fsck -y' first and then ‘/sbin/mount -uw /'

(The last line may instead be localhost:/ root#)

2. If you're having problems, the first thing you should always do when booting into single-user mode is run fsck , OS X's built-in disk utility, to make sure your drive is healthy. Type the following at the prompt:

/sbin/fsck –y

Press return. If you get an error that the file system was modified, run the command again; keep running it until you get a message that everything is OK. Note that if you get a message that the "Volume is journaled," you should instead use the command

/sbin/fsck –yf

3. In order to access files on your boot volume, you need to mount the disk. Type the following command (note the space between uw and /):

/sbin/mount –uw /

4. Use the mv command to rename the "bad" database from local.nidb to local.nidb.bad :

cd /var/db/netinfo

Press return, and type

mv local.nidb local.nidb.bad

5. Use the mv command again to rename the backup database local.nidb (all one line):

mv local.nidb.backup local.nidb

Note that if you're restoring from another backup with a different name, you should replace local.nidb.backup with the actual name of your backup database in the command above.

6. Restart your computer by typing reboot . This command tells the computer to finish any disk writes that are in progress, and then restarts the machine.

When you reboot, OS X will use the newly restored NetInfo database.

Method #2: Using the "Daily" Backup in OS X 10.3 and later

Although it's always good to make your own backup of the NetInfo database (as described above), the truth is that OS X may make a daily backup of the database for you. I say may because it only does this if you leave your Mac on and "awake" all night. In Chapter 14, in the section called "Running Routines," I discuss Mac OS X's scheduled maintenance scripts. The daily script backs up your current NetInfo database every morning at 3:15. In OS X 10.2 and earlier, this backup wasn't very useful to most users because of its format. However, in OS X 10.3 and later, the format is much easier to work with; here's how you use it to restore your NetInfo database from the latest "daily" backup. (Again, remember that this backup is made by the daily script; the backup copy from which you are restoring will only be as recent as the last time you left your Mac on all night.)

1. In Terminal, follow steps 1 through 4 in the previous exercise (starting up in single-user mode, using the fsck and mount commands, and renaming the "bad" database via the cd and mv commands).

2. Use the nicl (NetInfo command line utility) command to create a new NetInfo database:

nicl -raw local.nidb –create

3. Use the niload command (which loads data into your NetInfo database) to move data from the backup created by the daily script into the new database:

niload -d -r / -t localhost/local < /var/backups/local.nidump

4. Restart your computer by typing reboot . This command tells the computer to finish any disk writes that are in progress, and then restarts the machine.

When you reboot, OS X will use the newly restored NetInfo database.

The Last Resort: Rebuilding the NetInfo Database

I hope you never have to use this tip, because if you do, it means something has gone horribly wrong with your NetInfo database. However, the truth is that, well, it can happen. Sometimes the NetInfo database gets corrupted so badly that your Mac won't even start, and you either didn't make a backup, or your backup itself is damaged. In this scenario, your only hope is to wipe out the existing NetInfo database and tell Mac OS X that you want to start from scratch. However, you need to perform just the right set of actions to get the new NetInfo database to work with your previous set of user accounts. Here's how:

1. As in the instructions for restoring your database, start up in single-user mode (command-S at startup).

2. At the localhost# prompt, use fsck to ensure that your drives are in good shape. Type /sbin/fsck –y (or use /sbin/fsck -yf if you get the "journaled" error).

If you receive a message that your file system was modified, run fsck again, as many times as is necessary to get the message that your disk is OK.

3. To mount the boot disk so that you can access the files on it, type the following (note the space between uw and /):

/sbin/mount –uw /

Press return.

4. Type the following commands:

cd /var/db/netinfo
mv local.nidb local.nidb.deleted
rm /private/var/db/.AppleSetupDone

The first command changes the name of the corrupt NetInfo database to local.nidb.deleted (so that OS X won't use it when you reboot). You could have deleted it completely using a different command in Terminal, but by renaming it you'll still have a copy in case it turns out the problem wasn't a corrupted NetInfo database. The second command deletes a file the operating system uses to keep track of whether or not you ran the initial account setup process. Once you delete that file, Mac OS X thinks that you need to set up your computer (and, therefore, your initial account) again, and will launch the Setup Assistant the next time you boot into OS X.

5. When your computer reboots, the setup assistant will ask you to set up a "first" user account. Be sure to provide the exact same short username you used for your original admin account (the one you generally use that has administrator privileges). This will cause Mac OS X to match your "new" account up with your existing user folder and all corresponding permissions. Once the computer has finished starting up and you are logged into your account, you will also need to go into the Accounts pane of System Preferences (or the Users pane if you're using Mac OS X 10.2) and re-create any other users you previously created. Again, be sure to use the exact same short usernames the original accounts used.


This is an excerpt from Mac OS X Power Tools, First and Second Editions (Sybex, 2003 and 2004) . (

More info (and more advanced info) on recovering and replacing the NetInfo database can be found at and

Reproduced from Mac OS X Power Tools by permission of Sybex Inc. ISBN 0-7821-4192-7 copyright 2003, Sybex Inc. All rights reserved. For further information, please contact or 800/227-2346.

1 2 Page 1
Page 1 of 2
Shop Tech Products at Amazon