Script for mirroring and log shipping

  • Hi,

    I have been asked to setup a script to make setting up mirroring a little quicker. The main problem is one must run the ALTER commands and create endpoint command on two different servers. Can this be done within the script with something like Connect to:: or linked servers, or something I don't know about?

    CREATE ENDPOINT EndPointName

    STATE=STARTED AS TCP(LISTENER_PORT = PortNumber, LISTENER_IP = ALL)

    FOR DATA_MIRRORING(ROLE = PARTNER, AUTHENTICATION = WINDOWS NEGOTIATE, ENCRYPTION = REQUIRED ALGORITHM RC4)

    -- On Mirror

    -- How can I connect?

    CREATE ENDPOINT EndPointName

    STATE=STARTED AS TCP(LISTENER_PORT = PortNumber, LISTENER_IP = ALL)

    FOR DATA_MIRRORING(ROLE = PARTNER, AUTHENTICATION = WINDOWS NEGOTIATE, ENCRYPTION = REQUIRED ALGORITHM RC4)

    /*Set partner and setup job on mirror server*/

    ALTER DATABASE DatabaseName SET PARTNER = N'TCP://PrincipalServer:PortNumber'

    EXEC sys.sp_dbmmonitoraddmonitoring -- default is 1 minute

  • For Linked servers, i know you can do DDL commands, like CREATE TABLE, via EXECUTE AT;

    I'd bet any other commands like the ALTER and CREATE ENDPOINT would work just as well ,

    EXECUTE ( 'CREATE TABLE AdventureWorks2008R2.dbo.SalesTbl

    (SalesID int, SalesName varchar(10)) ; ' ) AT SeattleSales;

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • Yes but those DDL commands often specify a from clause which is where I can put in the linked server. These do not.

  • lmacdonald (6/25/2013)


    Yes but those DDL commands often specify a from clause which is where I can put in the linked server. These do not.

    ahh, you missed the point.

    I created a linked server named SeattleSales.

    the EXECUTE('some command') AT SeattleSales performs the action on the remote linked server, and not locally; you only need a four-part name for DML commands; for DDL, you use the AT <MyLinkedServer> format.

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • Oh nice, that may just work )

    However my linked server is actually on the same machine, but another instance. There is a syntax error, it does not like the \ between servername\instance so I tried it like servername.instance and it did not like the slash or the period.

  • lmacdonald (6/25/2013)


    Oh nice, that may just work )

    However my linked server is actually on the same machine, but another instance. There is a syntax error, it does not like the \ between servername\instance so I tried it like servername.instance and it did not like the slash or the period.

    oh that's easy to fix too; you just need to put it in brackets:

    EXECUTE AT('some command') AT [macdonald\SQL2008]

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • Thanks, that helped so much!

  • To bad variables get lost when you do an execute at another server. I thought everything was good but now I have that problem.

Viewing 8 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic. Login to reply