Performing Directory Maintenance
Active Directory is like any other database when it comes to needing attention. Sometimes it gets filled with gaps and needs compacting. Sometimes it gets messy and needs reindexing. Sometimes it gets corrupted and needs repair. And sometimes it gets completely zonked and needs restoration. The tool for doing most of this work is the NT Directory Service Utility, Ntdsutil.For some of its work, Ntdsutil uses a set of canned instructions from another utility, ESENTUTL, the grandchild of the ESEUTIL database utility designed for Exchange. ESENTUTL has a number of switches for setting and controlling restoration and integrity checks. Ntdsutil presents these options in a menu. The two most commonly used options are as follows:
- Compacting and reindexing Active Directory
- Repairing the Active Directory database
Compacting the Active Directory Database
If you are an experienced Exchange 5.5 administrator, you know how fragile the old ESE database can be. The new-and-improved ESE engine in Active Directory does not require much attention. Every 12 hours, a garbage collection process runs that removes objects that have been tombstoned longer than 60 days. The garbage collector then defrags and compacts the database. There is no need to perform an offline defrag or a reindex.If you perform an offline defrag using Ntdsutil, the utility compacts the database by copying the contents to a new copy of Ntds.dit in a temporary directory of your naming. You then either copy the new file over the old file or point the system at the new directory. The log files are no longer valid and can be ignored.The only time you should need to do an offline defrag is when you want to recover disk space using Ntds.dit. The online defrag packs the database but does not release the disk space. To do an offline defrag, follow Procedure 10.10.Procedure 10.10 Performing an Offline Defragmentation of Active Directory
- Boot the domain controller to DS Repair mode and run Ntdsutil.
- At the Ntdsutil: prompt, enter files. This opens the file maintenance prompt.
- Enter compact to <directory> where <directory> is the name of the temporary directory to store the compacted Ntds.dit. An example of the result follows:
file maintenance: compact to c:\ntdstemp
Opening database [Current].
Creating dir: c:\ntdstemp
Using Temporary Path: C:Executing Command: C:\WindowsWindows\system32\esentutl.exe /d
"e:\Windows\NTDS\ntds.dit" /8
/o /l"e:\Windows\NTDS" /s"e:\WindowsWindows\NTDS" /t"c:\temp\ntds.dit" /!10240 /p
Initiating DEFRAGMENTATION mode...
Database: e:\WindowsWindows\NTDS\ntds.dit
Log files: e:\Windows\NTDS
System files: e:\Windows\NTDS
Temp. Database: c:\temp\ntds.dit
Defragmentation Status ( % complete )
0 10 20 30 40 50 60 70 80 90 100
| | | | 00| | | | | | |
...................................................
Note:
It is recommended that you immediately perform a full backup
of this database. If you restore a backup made before the
defragmentation, the database will be rolled back to the state
it was in at the time of that backup.
Operation completed successfully in 22.172 seconds.
Spawned Process Exit code 0x0(0) - Copy the new Ntds.dit file to the original NTDS directory. If you want, you can leave the new directory where it is and redirect the Directory pointers:
Set Path Backup <directory>
Set path DB <directory>
Set path logs <directory>
Set path working dir <directory>
If you normally keep your logs on a different drive, you can leave that pointer alone.
Repairing the Active Directory Database
If the ESE engine encounters a problem caused by corrupted pages in the database or a corrupt index file or a combination of the two, you may need to repair the database. Symptoms of this kind of problem are Event log entries, console errors, or the machine might reboot with errors from the Local Security Authority Subsystem (LSASS).Active Directory repair has two stages:
- Soft recovery.
This stage rebuilds the database entries using the logs and checkpoint file and then rebuilds the indexes. - Hard repair.
This stage covers the same ground as the soft recovery but also deletes any corrupted pages. This can cause loss of data, so don't do a hard repair unless you have no other alternative. You should always get a backup of the Directory prior to performing any database repair.
Both of these stages require that you restart in Directory Services Restore mode. When you're ready, proceed as follows in Procedure 10.11.Procedure 10.11 Performing a Soft Recovery of Active Directory
- Open a console session.
- Run Ntdsutil.
- At the prompt, enter files. This opens the file maintenance: prompt.
- Enter recover. An example output looks like this:
Executing Command: C:\Windows\system32\esentutl.exe /r /8 /o /l"e:\Windows\NTDS"
/s" e:\Windows\NTDS" /!10240Initiating RECOVERY mode...Log files:
e:\Windows\NTDSSystem files: e:\Windows\NTDS
Performing soft recovery...
Operation completed successfully in 6.985 seconds.
Spawned Process Exit code 0x0(0)
If recovery was successful, it is recommended
you run semantic database analysis to insure
semantic database consistency as well.
As you can see, this operation proceeds relatively painlessly as long as nothing is wrong with the database. If a problem is discovered, the system will attempt to fix it. You should then perform a Semantic Database Analysis from Ntdsutil to verify and/or repair the internal name links in the database.If the results of the soft recovery indicate that a problem persists, you may need to perform a hard repair. Consider contacting Microsoft Product Support Services before proceeding. They may have other suggestions that are not as drastic. When you do need to perform a hard repair, follow Procedure 10.12.Procedure 10.12 Performing a Hard Repair of Active Directory
- In Ntdsutil, from the file maintenance: prompt, enter repair. An example output looks like this:
[View full width]Opening database [Current].
Executing Command: C:\Windows\system32\esentutl.exe /p "e:\Windows\NTDS\ntds.dit" /!10240 /8 /v /x /o
Initiating REPAIR mode...
Database: e:\Windows\NTDS\ntds.dit
Temp. Database: REPAIR.EDB
got 3910 buffers
checking database header
forcing database to consistent state
checking database integrity
<<result of integrity check deleted for brevity>>
integrity check completed.
Warning:
You MUST delete the logfiles for this database
Note:
It is recommended that you immediately perform a full backup
of this database. If you restore a backup made before the
repair, the database will be rolled back to the state
it was in at the time of that backup.
Operation completed successfully in 4.336 seconds.
Spawned Process Exit code 0x0(0)
If a problem is encountered during the repair, the error is written to the Repair.txt file in the \WindowsWindows\NTDS directory where the Ntds.dit file resides. You should also check the Event log for any errors. - Perform a full backup of the System State files using the procedure outlined in the "Backing Up the Directory" section earlier in this chapter.
Moving Active Directory Support Files
When you promote a domain controller, you select where you want the main Active Directory file, Ntds.dit, and the log files. You can change this location if you decide that you need to improve performance by putting the logs on a different spindle or you want to get the files off the system partition, where they go by default.To move the files, you must boot into Active Directory Restore mode. This requires that you know the local Administrator password, also called the Active Directory Restore password. You should always put the files on an NTFS partition to get security and good random access performance. When you are ready to move the files, follow Procedure 10.13.Procedure 10.13 Changing Active Directory File Locations
- Boot to AD Restore Mode.
- Open a console session.
- Run Ntdsutil.
- Enter files to get to the files maintenance prompt. Enter ? to get an option list:
file maintenance: ?
? - Show this help information
Compact to %s - Compact DB to specified directory
Header - Dump the Jet database header
Help - Show this help information
Info - Return information about DS files
Integrity - Perform Jet integrity check
Move DB to %s - Move DB to specified directory
Move logs to %s - Move log files to specified directory
Quit - Return to the prior menu
Recover - Perform soft database recovery
Set path backup %s - Set online backup directory path
Set path DB %s - Set DB file path
Set path logs %s - Set logging directory path
Set path working dir %s - Set NTDS working directory path - Use the move db to %s or move logs to %s options to move the database or the logs. Replace %s with the full path name, such as D:\Windows\NTDS.