The repair process was as follows:
- Created a new database, specifying the edb file name for the ‘defunct’ database and did not mount the database.
- Copied the files from the ‘defunct’ database to this new directory.
- Ran a soft recovery to replay logs.
- Checked the database and its now in a clean shutdown state – eseutil /mh
Once the database was mounted we need to ‘re-home’ the mailboxes using a feature called database portability:
- http://technet.microsoft.com/en-us/library/dd876873.aspx
- http://exchangeserverpro.com/exchange-2010-database-portability-disaster-recovery
A simple Powershell command is all we need to re-home the mailboxes:
- Get-Mailbox -Database db02 |where {$_.ObjectClass -NotMatch ‘(SystemAttendantMailbox|ExOleDbSystemMailbox)’}| Set-Mailbox -Database db02-new
Once all the mailboxes are re-homed to the new database any emails that were bound for the mailboxes while they were in the old store are now stuck in a queue specific to that database. The solution is to do the following:
- Suspend messages in the queue
- Export the messages to EML files
- Put these into the pickup folder of a Hub Transport server
- Wait for the pickup directory to be empty and delete any BAD emails
- Delete the messages in the queue.
Suspend Messages
First we need to know the name of the message queue. To do this we need to open up the queue viewer which is located in the Exchange System Console under Toolbox:
Once we have the Queue Viewer up, look for the queue for the database that is hung going to the defunct database:
Double click on that queue and get a properties of one message in the queue:
Notice the circled area in the message properties. That sequence is as follows server:
First we need to suspend all of the messages in the queue:
Exporting emails
We can now use PowerShell to export the emails. First we need a complete list of messageids which is the unique property for each message we need to export:
get-message -queue \ -resultsize unlimited | ft messageidentity
From this list we can build a series of commands to make this easier. This can be done either using a PowerShell script using arrays or and Excel spreadsheet. In my case this was a one off and I knew that I could fix this faster using Excel. Here is how to do it:
‘export-message -identity’ | assemblemessage -path “c:\temp\.eml”
Put these into the pickup folder of a Hub Transport server
Now that all the messages have been exported to EML files, open up a Windows Explorer window to copy the files from the ‘C:\temp’ directory (or wherever you placed them) to the Pickup folder for an Exchange 2010 Hub Transport server. This folder is typically in the ‘C:\Program Files\Microsoft\Exchange Server\V14\TransportRoles\Pickup’ directory. Once the files are copied there then they will be delivered to the mailboxes in the new mailbox database.
Delete BAD Emails
Once all the EML files are process and BAD emails are left behind you can delete these messages as they will not be delivered. Why would these messages be marked as BAD?
http://technet.microsoft.com/en-us/library/bb124230.aspx
Badmail A message classified as badmail has serious problems that prevent the Pickup or Replay directories from submitting the message for delivery. The other condition that causes badmail is when the message is formatted correctly, but the recipients aren’t valid, and an NDR message can’t be sent to the sender because the sender isn’t valid.
Once this is completed you can remove the messages in the original queue. All future emails will go to the correct database now.