You know how when you are nervous about something and so try to do a perfect job and hope for the best, things will inevitably go wrong! Yeah, they don’t lie about that. :)
I had to do an Exchange 2013 restore. My first time, to be honest, if you don’t count the one time I restored a folder in my home lab. And things didn’t go as smoothly as one would have hoped for. But hey it’s not a bad thing coz I get to learn a lot in the process. So no complaints, but it has been a nervous experience.
Initially I had a lot of DPM troubles restoring. These were solved by attaching my Azure recovery vault to a different server and doing a restore from there. In the process though I didn’t get DPM to clean up and mount the database directly on Exchange; rather I asked it to restore as files to a location and I decided to do the restore from there.
It is pretty straightforward according to the docs.
- Restore the database files.
- Bring the files of the restored database to a clean shutdown state
- Create a new recovery database, pointing to the previously cleaned up database files.
- Mount database.
- Do a restore request.
That’s all!
Here’s some more useful details I picked up along the way, including an error that caused some delays for me.
1 Restore all files to a location
Now, this is important. After restoring *do not* rename the database file. I did that and it an “Operation terminated with error -1216 (JET_errAttachedDatabaseMismatch)” error. You don’t want that! Keep the database name as is. Keep the folder names too as is, it doesn’t really matter.
2.1 Check the database state
You run the eseutil /mh “\path\to\edb\file”
command for this.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
[C:] eseutil /mh f:\Recovery2\RecoveryDB\RecoveryDB.edb Extensible Storage Engine Utilities for Microsoft(R) Exchange Server Version 15.00 Copyright (C) Microsoft Corporation. All Rights Reserved. Initiating FILE DUMP mode... Database: RecoveryDB.edb DATABASE HEADER: Checksum Information: Expected Checksum: 0xdd62a2ca Actual Checksum: 0xdd62a2ca Fields: File Type: Database Checksum: 0xdd62a2ca Format ulMagic: 0x89abcdef Engine ulMagic: 0x89abcdef Format ulVersion: 0x620,20 Engine ulVersion: 0x620,20 Created ulVersion: 0x620,20 DB Signature: Create time:04/17/2018 20:18:47.835 Rand:697063639 Computer: cbDbPage: 32768 dbtime: 4400444 (0x43253c) State: Dirty Shutdown <-------------- note the state Log Required: 785885-785891 (0xbfddd-0xbfde3) <-------------- I have these Log Committed: 0-785892 (0x0-0xbfde4) Log Recovering: 0 (0x0) |
Two things to note. First, the state – “Dirty Shutdown” – so I need to clean up the database. And second, the logs required. If I check the restored folder I should see files of this name there. In my case I did have files along these lines:
1 2 3 4 5 6 7 |
f:\Recovery2\RecoveryDB\E02000BFDDD.log f:\Recovery2\RecoveryDB\E02000BFDDE.log f:\Recovery2\RecoveryDB\E02000BFDDF.log f:\Recovery2\RecoveryDB\E02000BFDE0.log f:\Recovery2\RecoveryDB\E02000BFDE1.log f:\Recovery2\RecoveryDB\E02000BFDE2.log f:\Recovery2\RecoveryDB\E02000BFDE3.log |
2.2 Confirm that the logs are in a good state
You run the eseutil /mh “\path\to\log files\EXX”
command for this (where XX is the log prefix).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
[C:] eseutil /ml f:\Recovery2\RecoveryDB\e02 Extensible Storage Engine Utilities for Microsoft(R) Exchange Server Version 15.00 Copyright (C) Microsoft Corporation. All Rights Reserved. Initiating FILE DUMP mode... Verifying log files... Base name: e02 Log file: f:\Recovery2\RecoveryDB\E02000BFD93.log - OK Log file: f:\Recovery2\RecoveryDB\E02000BFD94.log - OK Log file: f:\Recovery2\RecoveryDB\E02000BFD95.log - OK Log file: f:\Recovery2\RecoveryDB\E02000BFD96.log - OK Log file: f:\Recovery2\RecoveryDB\E02000BFD97.log - OK Log file: f:\Recovery2\RecoveryDB\E02000BFD98.log - OK Log file: f:\Recovery2\RecoveryDB\E02000BFD99.log - OK Log file: f:\Recovery2\RecoveryDB\E02000BFD9A.log - OK Log file: f:\Recovery2\RecoveryDB\E02000BFD9B.log - OK Log file: f:\Recovery2\RecoveryDB\E02000BFD9C.log - OK |
All looks good.
2.3 Bring the database files to a clean shutdown state
For this you run eseutil /R EXX /l “\path\to\log\files” /s “\path\to\edb\file” /d “\path\to\edb\file”
(where XX is the log prefix). I remember the /lsd switches coz they look like LSD. :) They specify the path to the log files, the system files (this can be skipped in which case the current directory is used; I prefer to point this to the recovered folder), and the database file.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
[C:] eseutil /r e02 /l “f:\Recovery2\RecoveryDB" /s "f:\Recovery2\RecoveryDB" /d "f:\Recovery2\RecoveryDB" Extensible Storage Engine Utilities for Microsoft(R) Exchange Server Version 15.00 Copyright (C) Microsoft Corporation. All Rights Reserved. Initiating RECOVERY mode... Logfile base name: e02 Log files: RecoveryDB System files: RecoveryDB Database Directory: RecoveryDB Performing soft recovery... Restore Status (% complete) 0 10 20 30 40 50 60 70 80 90 100 |----|----|----|----|----|----|----|----|----|----| ................................................... Operation completed successfully in 0.797 seconds. |
Looks good!
The first few times I ran this command I got the following error –
1 |
Operation terminated with error -1216 (JET_errAttachedDatabaseMismatch, An outstanding database attachment has been detected at the start or end of recovery, but database is missing or does not match attachment info) after 0.344 seconds. |
I went on a tangent due to this. :( Found many outdated blog posts (e.g. this one) that suggest adding a “/i” switch because apparently the error is caused by a mis-match with the STM database. I should have remembered STM databases don’t exist in 2013 (they were discontinued in 2010 I think, but I could be wrong; they used to be the database where you stored attachments). When I added the “/i” switch the operation succeeded but the database remained in a “dirty shutdown” state and subsequent runs of the eseutil
command without this switch didn’t make any difference. I had to start from scratch (luckily I was working on a copy of the restored files, so didn’t have to do a fresh restore!).
Later I had the smart idea of checking the event logs to see why this was happening. And there I saw entries like this:
1 |
eseutil (4132) Database recovery failed with error -1216 because it encountered references to a database, 'f:\Recovery2\RecoveryDB\Mailbox Database 10.edb', which is no longer present. The database was not brought to a Clean Shutdown state before it was removed (or possibly moved or renamed). The database engine will not permit recovery to complete for this instance until the missing database is re-instated. If the database is truly no longer available and no longer required, procedures for recovering from this error are available in the Microsoft Knowledge Base or by following the "more information" link at the bottom of this message. |
You see I had the “smart” idea of renaming my database file to something else. It was a stupid idea because the database still had references to the old name and that’s why this was failing. None of the blog posts or articles I read did a database rename, but none of them said don’t do it either … so how was I to know? :)
Anyways, if you haven’t renamed your database you should be fine. You could still get this or any other error … but again, don’t be an idiot like me and go Googling. Check your event logs. That’s what I usually do when I am sensible, just that being nervous and all here I skipped my first principles.
2.4 Confirm the database state is clean
Run the eseutil /mh
command of step 2.1 and now it should say “Clean Shutdown”.
At this point your recovered database files are in a clean state. Now to the next step!
3 Create a new recovery database, pointing to the restored database files.
Do this in the Exchange Management Shell.
1 |
New-MailboxDatabase -Recovery -Name "Recovery DB" -EdbFilePath 'F:\Recovery2\RecoveryDB\RecoveryDB.edb' -LogFolderPath 'F:\Recovery2\RecoveryDB' -Server rak1exch01 |
You will get a warning about restarting the Information Store service. Don’t do it! Restarting the Information Store will cause all Outlook connections to that server to disconnect and reconnect – you definitely don’t want that in a production environment! :) Restarting is only required if you are adding a new production database and Exchange has to allocate memory for this database. Exchange 2013 does this when the Information Store is (re)started. We are dealing with a Recovery Database here and it will be deleted soon – so don’t bother.
Also, remember that Recovery databases don’t appear in EAC so don’t worry if you don’t see it there.
If you want to read more on Recovery databases this is a good article.
4 Mount the recovery database
Again in EMS:
1 |
Mount-Database “Recovery DB" |
5 Do a restore request
Still in EMS:
1 |
New-MailboxRestoreRequest -SourceDatabase "Recovery DB" -SourceStoreMailbox "User Mailbox" -TargetRootFolder "RecoveredContacts" -TargetMailbox “User Mailbox" -SourceRootFolder Contacts -AllowLegacyDNMismatch |
I am restoring a folder called “Contacts” from “User Mailbox” back to “User Mailbox” under a folder called “RecoveredContacts”.
You can keep an eye on the restore request thus:
1 |
Get-MailboxRestoreRequest | Get-MailboxRestoreRequestStatistics | fl percentcomplete,itemstransferred,*count* |
5+ Cleanup tasks
And once done you can remove all completed requests:
1 |
Get-MailboxRestoreRequest -Status Completed | Remove-MailboxRestoreRequest |
That’s it!
You can also remove the Recovery database now. Dismount it first.
1 |
Dismount-Database "RecoveryDB" |
1 |
Remove-MailboxDatabase "Recovery DB" |
This doesn’t remove the EDB files or logs, so remove them manually.
Some links that I came across while reading up on this:
- https://blogs.technet.microsoft.com/mspfe/2012/09/06/why-exchange-databases-might-remain-dirty-after-eseutil-r-recovery/ – a very good blog post.
- https://practical365.com/exchange-server/restoring-exchange-server-2016-mailboxes-and-items-using-a-recovery-database/ – another very good blog post; covers more scenarios than I did above. One difference is the author of this post creates the Recovery Database first and then restores the files to it, followed by bringing it up to a clean shutdown state. Same difference I guess, I dunno.
- https://docs.microsoft.com/en-us/exchange/move-a-mailbox-database-using-database-portability-exchange-2013-help – database portability. This is for when you want to recover the whole database to a different server. (I too was recovering to a different server, but my servers were part of the same DAG and so it doesn’t matter I guess. Or maybe I was only restoring the contents of a single folder from the database and so it didn’t matter. I am not a 100% sure).
- You find a lot of articles saying you can try
eseutil /p
to recover a database that stays in a “dirty shutdown” state even after running recovery. This blog post tells you what this switch does. Also as a reminder to myself, copy-pasting this definition of eseutil for my own reference: “ESEUTIL.exe or the Exchange Storage Engine Utility is an executable file residing in the bin directory which is used to perform various operations like recovery, repair, integrity check on an Exchange database while it is offline.“
My first baby step production Exchange 2013 restore. Finally! :)