Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How To: Check and Repair an Exchange Database

Exchange Maintenance

How To: Check and Repair an Exchange Database

by  markdmac  Posted    (Edited  )
This FAQ will walk you through the process of performing an offline defrag of your database and show you how, if there are errors to correct them. An offline defrag of the database may be needed if you have deleted a number of users and need to reduce the overall size of the Exchange databases. Note that normal online defrag will EVENTUALLY get this job done, however there are times when the need is more urgent particularly when having problems backing up data.

Note: Add the path to your Exchsvr\Bin directory to your Environmental Variables PATH statement. That way you can execute ESEUTIL from within your MDBDATA directory.

[green]Note: Delete log files whenever instructed by ESEUTIL or ISINTEG[/green]

Begin by stopping the information store service

Open a command prompt and navigate to your Exchsvr\MDBDATA directory

[red]Check for Clean Shutdown[/red]
Run the following commands
Eseutil /mh priv1.edb
Eseutil /mh pub1.edb

Check for logs needed. If the report shows Logs Required 0/0 then delete all log files.
Delete *.log
If the shutdown was clean, skip to the defrag section of this FAQ.

OK, so IF the logs required was not 0/0 then lets try and repair the database. The text in bold that follows are the commands you need to run.

[red]Attempt a Soft Recovery[/red]

Eseutil /r E00


[red]If soft recovery fails, do a hard repair[/red]

Eseutil /p priv1.edb
Eseutil /p pub1.edb
Delete *.log

Mount and then dismount stores one at a time.

OK, by now your transaction logs should all be committed. Let's move on and defrag the database to free up the space within the database that was being used up by deleted users.

[red]Defrag the database[/red]

Before you defrag the database, you need to decide if you will perform the defrag in the current database or instead you can choose to have a brand new database created by the defrag. The latter choice will give you a new database and even tighter defragmentation than the former. Using this scenario the original database remains intact so there is less risk involved.

Verify that you have sufficient disk space to have two copies of your database in the same location. If you do not then the defrag will fail. If you are low on disk space, use the /t switch to identify WHERE to create the temp file used by ESEUTIL. I will demonstrate the use of the /t switch in my second example.

I'll outline the differences in the commands needed below.

[red]Quick and simple defrag:[/red]

Open a command prompt. Navigate to the location of your database files. If you added the Exchange bin folder to your path statement as specified above then you do not need to include path information to the ESEUTIL command. Execute the following commands.


Eseutil /d priv1.edb
Eseutil /d pub1.edb


Start the Information Store service
Dismount the stores in Exchange System Manager
Note: if no repair was needed above you can start your stores again and you are done. Please note that Microsoft recommends mounting and dismounting the stores after a defrag.

[red]Creating a new database during defrag:[/red]

Eseutil /d priv1.edb /t <tempfilename.edb> /p
Eseutil /d pub1.edb /t <tempfilename.edb> /p


At the conclusion of the above commands you will have new EDB and STM files with the names specified in tempfilename. Archive off or rename your current database files and then rename the newly created files to Priv1 and Pub1. Move these files to the same location as the original database, you can then start the Information Store Service.

For those who have been experiencing errors logged in backups due to mailbox corruption, then the following will be really important to you. You will want to run ISINTEG to fix any errors in the database itself. It is important to run ISINTEG multiple times until you either get no errors, or you get the same errors reported each time.

[red]Repair Errors In the Database With ISINTEG[/red]

Isinteg -s servername -fix -test alltests


Note: This is important so I will repeat this point. ISINTEG should be run multiple times until it returns either no errors or the same errors repeatedly. At a minimum it should be executed twice.

At this point you should be able to return all services etc. to normal operation and allow users access to their mailboxes.

Depending on hardware and database sizes, running ESEUTIL or ISINTEG can take anywhere from 15 minutes to days of time. Since down time equals a loss in productivity, it is essential to get mail back up and running or move on to the next troubleshooting steps as quickly as possible. While the mail stores are down during the above maintenance, SMTP is still available. You can leverage this fact by running a script on the server to notify you the moment when ESEUTIL or ISINTEG has completed. In order for this script to work, the IP address of the Exchange box needs to be in the Allowed To Relay list for your Virtual SMTP Server.

You must modify the sections in [red]red[/red]

Code:
[green]
'==========================================================='
' NAME: NotifyESEUTILCompletion.vbs
'
' AUTHOR: Mark D. MacLachlan , The Spider's Parlor
' URL: http://www.thespidersparlor.com
' DATE  : 9/28/2007
' COPYRIGHT (c) 2007 All Rights Reserved
'
' COMMENT: Notifies via SMTP email when the ESEUTIL process
'          has stopped.
'
'    THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT 
'    WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, 
'    INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF 
'    MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR 
'    PURPOSE.
'
'    IN NO EVENT SHALL THE SPIDER'S PARLOR AND/OR ITS 
'    RESPECTIVE SUPPLIERS BE LIABLE FOR ANY SPECIAL, 
'    INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 
'    WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
'    WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER 
'    TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH 
'    THE USE OR PERFORMANCE OF THIS CODE OR INFORMATION.
'
'    YOU ARE FREE TO USE AND SHARE THIS SCRIPT PROVIDED YOU 
'    ONLY ALTER THE SECTION MARKED FOR EDIT AND PROVIDED 
'    YOU RETAIN THIS HEADER.
'
'    THIS SCRIPT AND MANY MORE ARE INCLUDED IN 
'    THE ADMIN SCRIPT PACK
'    PUBLISHED BY THE SPIDER'S PARLOR.  
'    WORK SMARTER, NOT HARDER.
'    
'==========================================================='
'EDIT THE FOLLOWING SECTION
' Set the company specific information[/green]
strFrom = "[red]Administrator@company.com[/red]"
[green]' Set the SMTP server IP[/green]
strMyIP = "[red]192.168.16.2[/red]" 
[green]' Where do you want the message to be delivered
' Use semicolons to seperate multiple addresses[/green]
strTo = "[red]youremailaddress@company.com[/red]"
[green]'END EDIT SECTION[/green]










domain = Right(strFrom,InStrRev(strFrom,"@")+1)

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")


Do Until IsRunning = "No"
    IsRunning = CheckProcess
Loop
Report = "ESEUTIL completed for " & domain & " at " & Now 


' Set the visual basic constants as they do not exist within VBScript.
' Do not set your smtp server information here.
Const cdoSendUsingMethod = "http://schemas.microsoft.com/cdo/configuration/sendusing", _
cdoSendUsingPort = 2, _
cdoSMTPServer = "http://schemas.microsoft.com/cdo/configuration/smtpserver"

' Create the CDO connections.
Dim iMsg, iConf, Flds
Set iMsg = CreateObject("CDO.Message")
Set iConf = CreateObject("CDO.Configuration")
Set Flds = iConf.Fields

' SMTP server configuration.
With Flds
.Item(cdoSendUsingMethod) = cdoSendUsingPort

' Set the SMTP server address here.
.Item(cdoSMTPServer) = strMyIP
.Update
End With

' Set the message properties.
With iMsg
Set .Configuration = iConf
.To = strTo
.From = strFrom
.Subject = domain & " Information Store(s) Needs Immediate Attention"
.TextBody = Report
End With

'Send the message.
iMsg.Send 


Function CheckProcess
    AppFound = "No"
    Set colProcessList = objWMIService.ExecQuery("Select * from Win32_Process")
    For Each objProcess in colProcessList
        If objProcess.Name = "[blue]eseutil[/blue].exe" Then
            AppFound = "Yes"
        End If
    Next
    CheckProcess = AppFound
End Function

Save the above code to text file in notepad. Rename the extension from TXT to VBS. Then double click the script. It will monitor for the ESEUTIL process to complete and send you an email. It should go without saying (but I will say it anyway) that the address you send to has to be on a different mail system since your information stores are currently down. Use a cell phone address, HOTMAIL, YahooMail, G-Mail etc. for the strTo address.

Test the script before you start ESEUTIL. If you execute the script without ESEUTIL running then the SMTP email should be sent immediately. Also note that if you are running ISINTEG, you can modify the above script section in blue and replace ESEUTIL with ISINTEG to be notified when that process completes.
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top