Please start any new threads on our new site at http://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 Script Library
 How to set up replication from backup files
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Lumbago
Norsk Yak Master

Norway
3271 Posts

Posted - 06/10/2009 :  05:09:23  Show Profile  Reply with Quote
/*
Steps to set up replication using backup files instead of snapshots

1. Run the Create Publication wizard on the publisher. Make sure NOT to create a snapshot.

2. Once the wizard has finished, right-click the new publication, choose Properties
   and make sure that the "Allow initialization from backup files" is set to True

3. Disable the "Distribution clean up: distribution" job to make sure that no 
   commands are deleted from MSrepl_commands before the entire backup/restore operation 
   is complete

4. Create a full database backup to disk and make sure that the file is available for the 
   publisher until the entire replication setup is finished. 

5. Transfer the backup file to the subscriber server and restore it there. If you do 
   regular backups to disk make sure to use one that was taken *after* the publication 
   was created. Also restore trans log backups taken after the full backup. The last backup
   should be restored using WITH RECOVERY, and keep in mind that a more recent backup saves 
   you time in the syncing process when the replication is being initialized.

6. Disable all triggers on the subscriber database:
   EXEC sp_msforeachtable 'ALTER TABLE ? DISABLE TRIGGER all'

7. Disable all constraints on subscriber database:
   EXEC sp_msforeachtable 'ALTER TABLE ? NOCHECK CONSTRAINT ALL' 

8. Run the following script ON THE PUBLISHING SERVER IN THE PUBLISHING DATABASE to enable 
   the replication:
   EXEC sp_addsubscription 
	   @publication ='myPublication',              --> Name of the publication
	   @subscriber = 'myserver.myDomain.com',      --> Fully qualified name or IP of subscriber server
	   @destination_db ='MySubscriberDB',          --> Name of the database you just restored (doesn't have to be the same as the publisher)
	   @sync_type = 'initialize with backup',      --> no need to change this
	   @backupdevicetype = 'disk',                 --> no need to change this
	   @backupdevicename = 'F:\backupfile.bak'     --> Pointer to the last backupfile that was restored, but from the folder on the on the 
                                                     publishing server. If you restored trans logs also the last translog file is what you
                                                     need to put here

9. Enable the "Distribution clean up: distribution" job again 
*/


- Lumbago

sodeep
Flowing Fount of Yak Knowledge

USA
7174 Posts

Posted - 06/14/2009 :  11:33:50  Show Profile  Reply with Quote
Good job Lumbago. This is how I have setup Transaction Replication for 250 GB Databases. Also You can Enable constraints after replication is setup in subscriber.
Go to Top of Page

Lumbago
Norsk Yak Master

Norway
3271 Posts

Posted - 06/15/2009 :  04:05:50  Show Profile  Reply with Quote
Thanx sodeep, I did consider enabling the constraints again but I figured that since the constraints are enabled in the publishing database it won't cause any harm to leave them disabled on the subscribers.

- Lumbago
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000