Sunday, June 10, 2012

De fragmentation


In a windows 2003 environment, if you low on disk space, or if you have deleted a lot of objects since you promote your DC. You should perform an offline degragmentation to the DIT file. As you might know, there are two type of defragmentation in windows 2003 family,
- online Defragmentation
- offline Defragmentation

Online Defragmentation

By default in windows 2003, the online defrag process runs every 12 hours on each domain controller. This process defrags the Active Directory database (ntds.dit) by combining whitespace generated from deleted objects, but does not reduce the size of the database file.
you can check the Directory Event log to see when the last online defrag was performed. See Figure-1 for NTDS online Defrag Event 700 (Online Defrag start) in Directory Service log indicates the online Defrag has started.
[AD-Tutorial]-How-to-perform-Active-Directory-Defrag1
Figure-1 NTDS online Defrag Event 700 (Online Defrag started)

upon completion of Online defrag, an event number 701 is logged. See Figure-2
[AD-Tutorial]-How-to-perform-Active-Directory-Defrag2
Figure-2 NTDS online Defrag Event 701 (Online Defrag Ended)

You can also manually start the online Defrag, here is how:
1. Start => Run => "LDP" to start up LDP
2. Select Connection => Connect, enter name of Domain controller with Default Port 389
3. Connection => bind, then enter admin credential
[AD-Tutorial]-How-to-perform-Active-Directory-Defrag3
Figure-3 Bind with Admin Credential
4. Browse => Modify,
   - Leave DN Blank
   - For Attribute, enter " DoOnlineDefrag"
   - Value enter Maximum time(SEC) the defrag should run, here we use  180
   - For Operation, choose Add,
   - click enter
[AD-Tutorial]-How-to-perform-Active-Directory-Defrag4
Figure-4 Add DoOnlineDefrag Attribute to trigger the online Defrag
5. click Run
Offline Defragmentation

Beside online defragmentation which is performed automatically at default interval of 12 Hours as part of Windows Maintenance(Garbage Collection), offline defragmentation create compacted version of database file which in most case will be considerably smaller. here is how you can start offline defrag:
1. you need to first reboot the server into DS restore mode, please see "How to perform a Nonauthoritative Restore to Domain Controller? "  for more detail on how to boot to DS Restore mode.
2. Check Directory Integrity, detail see "How to check Active Directory database integrity(DIT File's Integrity)? "
3.  Open up command prompt and type ntdsutil
4. goto files menu
5. issue command " compact to C:\TempFolder, you can use single command too:
ntdsutil files "compact to P:\TempFolder"
See Figure-5 for output of compact subcommand
[AD-Tutorial]-How-to-perform-Active-Directory-Defrag5
Figure-5 Compact to C:\TempFolder output
6. next you need to delete the Transcation Log files in the current NTDS directory.
   del C:\WINDOWS\NTDS\*.log 
7. Next to move the dit file in the temperory folder to original directory, it's recommended to rename the original DIT file and store in the temperory location to ensure nothing "Strange" happened to compacted DIT.
Below command is to move and rename the older DIT file to the temp folder
move c:\WINDOWS\NTDS\ntds.dit P:\TempFolder\ntds_old.dit
next, move new ntds.dit file to windows\ntds directory:
move P:\TempFolder\ntds.dit C:\WINDOWS\NTDS\ntds.dit
8. Now we need to run another integrity check of DIT file.(refer to step 2)

No comments:

Post a Comment