Forgive me if this sounds angry/rant-y, but it kinda is.
High Level Overview:
How can I restore a SQL DB that's involved in transactional replication with 5 pub/subs, without having to drop, create, & re-initialize (or re-snapshot) all the subs. Or at least, without having to re-init/re-snapshot. I can handle scripting the pubs/subs themselves, that's understandable (somewhat). But, I have a known good backup, and/or am willing to make a "fresh" backup on the primary server to share with the secondary server, in an attempt to use the "initialize from backup" feature when creating the subscriptions, and I just can't seem to get that to work.
Rant-y version:
Why can't SQL Server "trust me" that the publisher and subscriber DBs are in sync by nature of being restored from the SAME backup file, and that replication can simply continue on its merry way without having to do a damn reinit or be re-created from scratch!?
The Details:
I have a database MyCoolDB
. It lives (originates) on server OldFoo
. In the "Old" environment, it's replicated to server OldBar
, for read-only reporting purposes. I am prepping a migration to a "New" environment, with similarly named servers NewFoo
and NewBar
. For purposes of this discussion, Foo
servers will be the publishers, and Bar
servers will be the subscribers. To simplify things, we'll be letting the publisher double as the distributor, i.e. OldFoo
will publish & distribute to OldBar
, and same for NewFoo
to NewBar
.
In the "New" environ, I want to restore MyCoolDB
to both NewFoo
(pub) and NewBar
(sub), using the same backup file. AND, because I'm doing this multiple times to refresh said environ before final cutover, I want to NOT have to drop, re-create, and re-init or re-snapshot the pubs/subs every dang time.
Is that so much to ask? Surely there must be a way to "refresh" Dev & QA environments, from higher (Prod/Pre-Prod) environments, when it comes to SQL DBs that may be involved in replication.
Assumptions/Notes:
- I can effectively "Pause" replication by stopping the associated Agent Jobs in the Repl categories (Distribution & Log-Reader agents). This may be a bad assumption.
- I can quickly and efficiently restore
MyCoolDB
from a native backup file on-disk & accessible to both server instances. - I have scripted-out the repl pub/sub creation for the
NewFoo
instance by going thru the generated-scripts fromOldFoo
and doing string-replacement. I have also verified that, when using said creation scripts and initializing the normal way, things work as expected. - I have reviewed articles & blog posts that purport to walk thru the "init a subscription from a backup" process but have not found a working solution. I got close; details below.
- While the environs in question here are definitively NOT production, this is all prep & practice for a production migration that involves similar issues (replicated DB, re-init causes performance problems).
Close, but No Cigar:
After attempting this methodology...
- Delete Pubs/Subs
- restore DB on Publisher
- create Pubs
- backup DB to special location
- restore DB on Subscriber from special location
- create Subs with init-from-backup in special location
I checked the Repl-Monitor for the subscription, and under the Log Reader Agent status, the following error was shown. The error below is why I attempted to exec sp_replrestart
, but as I said, that failed too.
The process could not execute 'sp_repldone/sp_replcounters' on 'NewFoo'. (Source: MSSQL_REPL, Error number: MSSQL_REPL20011)
Get help: http://help/MSSQL_REPL20011
The log scan number (267414:8865:55) passed to log scan in database 'Grading' is not valid. This error may indicate data corruption or that the log file (.ldf) does not match the data file (.mdf). If this error occurred during replication, re-create the publication. Otherwise, restore from backup if the problem results in a failure during startup. (Source: MSSQLServer, Error number: 9003)
Get help: http://help/9003
The process could not set the last distributed transaction. (Source: MSSQL_REPL, Error number: MSSQL_REPL22017)
Get help: http://help/MSSQL_REPL22017
The process could not execute 'sp_repldone/sp_replcounters' on 'NewFoo'. (Source: MSSQL_REPL, Error number: MSSQL_REPL22037)
Get help: http://help/MSSQL_REPL22037
Any takers?
TL;DR: My primary goal is to understand how to get replication subscriptions initialized from a backup, so that re-init/re-snapshot isn't needed. My secondary goal would be to avoid having to drop & re-create (from scripts) the pubs/subs every time, but at this point that's a "nice to have", not a "requirement".