AD De-fragmentation both online & Offline

There are two methods of Active Directory defragmentation available:

Online Defragmentation – Windows Server 2000 introduced a method that runs in certain intervals automatically to defragment the Active Directory database. It is part of active directory garbage collection process. When completed, it optimizes the data storage and reclaims the space for new active directory objects. This however will not reduce the size of the Active Directory database. The bonus of utilizing Online Defragmentation is that it not required to bring any service offline complete the task.

Offline Defragmentation – This method requires an IT administrator to stop the Active Directory service. In stopping said service, the process will create compact version of the existing Active directory database in different location. Once completed, the new defragmented compact database is copied to the original location.  Estimates are that the database is shrunk to 1/6th of its original size after offline fragmentation.

The “ntdsutil” is needed to perform defragmentation and is the same tool used to check Active Directory errors.  The following steps will detail the process.

Prerequisites

  1. Plan the Active Directory shutdown impact properly and measure how it will affect the rest of the organization. Length of time to complete the defragmentation depends on the size of the Active Directory database and the how bad it is fragmented.
  2. Always perform a system state backup prior to the process.

Step 1: Stopping the Active Directory Service

  1. Login to the primary domain controller as Domain admin or Enterprise Admin
  2. Navigate to Server Manager > Tools > Servicesopt1
  3. In Services.mmc right-click on Active Directory Domain Services and click Stopopt2
  4. Services to be stopped are then listed. Click Yes to continue.opt3

Step 2: Perfroming the Offline Active Directory Fragmentation

  1. Once services stops, run the Command Prompt in Administrator mode
  2. In the Command prompt window, type ntdsutil and press enteropt5
  3. In prompt type activate instance NTDS and press enteropt6
  4. Type files and press enteropt7
  5. At the file maintenance we need specify the location where NTDS compact database will save. For this Step-By-Step, the folder C:\CompactDB was created. Type compact to C:\CompactDB and press enter
  6. The defragment process begins. The time to completion will depend on the size of the databaseopt8
  7. Once completed type q to exit from the utility
  8. Close the Command Prompt console
  9. Copy the defragmented database from C:\CompactDB\ntds.dit to C:\Windows\NTDS\ntds.dit
  10. Delete the log files found in the directory
  11. Return to the Services.mmc
  12. Right-click on Active Directory Domain Services and click Start

The defragmentation of the Active Directory database is now complete.

 

 

 

 

Active Directory automatically performs online defragmentation of the database at certain intervals as part of the Garbage Collection process. (By default, this occurs every 12 hours.) Online defragmentation does not reduce the size of the database file (Ntds.dit) but instead optimizes data storage in the database and reclaims space in the directory for new objects.

Performing an offline defragmentation creates a new version of the database file without internal fragmentation. It also re-creates all indexes. Depending on how fragmented the original database file was, the new file may be much smaller.

More information

To perform offline defragmentation of the Active Directory database:

  1. Back up Active Directory. Windows Server Backup natively supports backing up Active Directory while online. This occurs automatically when you select the option to back up everything on the computer in the Backup Wizard, or independently by selecting to back up the “System State” in the wizard.
  2. For Windows 2000 Server and Windows Server 2003
    Restart the domain controller, select the appropriate installation from the boot menu, and then press F8 to display the Windows 2000 Server Advanced Options menu. Select Directory Services Restore Mode, and then press Enter. Press Enter again to restart.For Windows Server 2008 and later versions
    Take one of the following actions:

    • Stop the “Active Directory Domain Services” or LDS instance.
    • Start “msconfig,” and go to the boot pane. Select the OS installation that you want to configure. Select Safe Boot in the Boot options section, and also select the Active Directory repair item. After you click OK, the tool asks you to restart. Restart the computer.
  3. Log on to the administrator account by using the password that is defined for the local administrator account in the Directory Service Restore Mode SAM. For more information about how to use the offline SAM database, click the following article number to view the article in the Microsoft Knowledge Base:
    223301 Protection of the administrator account in the offline SAM
  4. Click Start, point to Programs, point to Accessories, and then click Command Prompt.
  5. At the command prompt, type cmd, and then press Enter.
  6. NTDSUTIL uses the TEMP and TMP environment variables to create a temporary database during defragmentation. If the free space on your standard volume used is less than the size of the compacted database, you receive the following error:
    file maintenance: compact to d:\compactDB
    Initiating DEFRAGMENTATION mode…
    Source Database: D:\windows\NTDS\ntds.dit
    Target Database: d:\compactDB\ntds.ditDefragmentation  Status (% complete)0    10   20   30   40   50   60   70   80   90  100

    |—-|—-|—-|—-|—-|—-|—-|—-|—-|—-|

    ……………………..Operation terminated with error -1808( JET_errDiskFull, No space left on disk ).

    In the Application log, you see an event that resembles the following:

    Log Name:      Application
    Source:        ESENT
    Event ID:      482
    Task Category: General
    Level:         Error
    Keywords:      Classic
    Description:NTDS (12852) An attempt to write to the file “C:\Users\administrator\AppData\Local\Temp\tmp.edb” at offset 49315536896 (0x0000000b7b6f6000) for 0 (0x00000000) bytes failed after 0.015 seconds with system error 112 (0x00000070): “There is not enough space on the disk. “.  The write operation will fail with error -1808 (0xfffff8f0).  If this error persists then the file may be damaged and may need to be restored from a previous backup.

    In this case, set the environment variables TMP and TEMP to a volume that has enough free space for the task. For example, use the following settings:

    Md d:\temp

    Set tmp=d:\temp

    Set temp=d:\temp

    Note This problem can also occur during an integrity check of the database.

  7. Run NTDSUTIL.
  8. For Windows 2008 and later versions
    Type activate instance ntds to select the Active Directory database instance.  Use the LDS instance name if you want to compact an LDS database.
  9. Type files, and then press Enter.
  10. Type info, and then press Enter. This displays current information about the path and size of the Active Directory database and its log files. Note the path.
  11. Establish a location that has sufficient drive space for the compacted database to be stored.
  12. Type compact to drive:\directory, and then press Enter. Note, in this command, the placeholders drive and directory represent the path of the location that you established in the previous step.Note You must specify a directory path. If the path contains any spaces, the whole path must be enclosed in quotation marks. For example, type:
    compact to “c:\new folder”
  13. A new database that is named Ntds.dit or AdamNtds.dit is created in the path that you specified.
  14. Type quit, and then press Enter. Type quit again to return to the command prompt.
  15. If defragmentation succeeds without errors, follow the Ntdsutil.exe on-screen instructions. Delete all the log files in the log directory by typing the following command:
    del drive :\ pathToLogFiles \*.log

    Copy the new Ntds.dit or AdamNtds.dit file over the old database file in the current database path that you noted in step 5.

    Note You do not have delete the Edb.chk file.

  16. For Windows 2000 Server and Windows Server 2003
    Restart the computer.For Windows Server 2008 and later versions
    If you stopped Active Directory Domain Services or LDS instance, you can restart it now.
  17. For Windows Server 2008 and later versions
    If you are working in the Active Directory Restore mode, start msconfig and go to the boot pane. Select the operating system installation that you want to configure. Click to clear Safe Boot in the Boot options section. When you click OK, the tool asks you to restart. Restart the computer.
Properties

Applies to

Windows Server 2012 R2 Standard, Windows Server 2012 R2 Essentials, Windows Server 2012 R2 Datacenter, Windows Server 2012 Standard, Windows Server 2012 Essentials, Windows Server 2012 Datacenter, Windows Server 2008 R2 Standard, Windows Server 2008 R2 Enterprise, Windows Server 2008 Standard, Windows Server 2008 Enterprise, Microsoft Windows Server 2003 Service Pack 2, Microsoft Windows 2000 Server, Microsoft Windows 2000 Advanced Server

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s