I discovered this week, the hard way, that the database restore options NORECOVERY
and KEEP_CDC
are mutually exclusive. So, this begs the question. How do you do a database restore, keeping CDC intact, with both full and log backups?
Doing research on MSDN etc. I cannot find any documentation on restoring a database with KEEP_CDC
using any other option than a single full db restore with RECOVERY
specified.
I was able to find one attempt that did the full and subsequent logs without the keep_cdc
option waiting until the final log. Only then was the table brought online with the RECOVERY
and KEEP_CDC
option. The result was a corrupt CDC schema as demonstrated here.
If the intent is to KEEP_CDC
on restore are you truley limited to a full backup only or is there a mechanism similar to the attempt above to keep it intact during multi-file restors on a server other than the original?
Best Answer
Change Data Capture, or CDC, does not require the
KEEP_CDC
keyword when restoring a database to the original server. When restoring a database to a server other than the original server, you can use theKEEP_CDC
keyword to specify that the change data capture data is retained in the database. This is by design, and is clearly stated in BOL here under the section entitled "Restoring or Attaching a Database Enabled for Change Data Capture"This code shows CDC in action both before and after a
RESTORE DATABASE ... WITH NORECOVERY
Restoring the same backup onto the same server as a new database name appears to retain CDC: