Solved

T-SQL script to automate the process of transferring SQL server 2005 login from SQL server 2005 mirror primary site to DR site

Posted on 2014-09-23
6
100 Views
Last Modified: 2015-04-23
Dear all,

I have a script to automate the process of transferring SQL server 2005 login from SQL server 2005 mirror primary site to DR site, see attached.

but it doesn't take care the transfer or change of login status ( disabled/deleted).

see the statement here:

	If Not Exists (Select 1 From sys.server_principals
				Where name = @LoginName)

Open in new window


so it only copy new login but not any altered login and deleted login,

any way to improve it ?
dba-CopyLogins.sql
0
Comment
Question by:marrowyung
  • 5
6 Comments
 
LVL 17

Accepted Solution

by:
dbaSQL earned 500 total points
Comment Utility
>>so it only copy new login but not any altered login and deleted login,

I'm not sure if I follow you exactly, but if you've deleted a login, there isn't one to copy.  Are you saying that if you delete a login, you want that action to also occur on the mirror server?

If that is what you mean, you probably need to revise your script to first compare the logins between the Principal and the Mirror.  Then, of course, if there is no match at the principal, you can assume the login may be removed from the mirror.    

A slightly more complex, but potentially safer, method would be a database trigger that fires when the DROP LOGIN is run on the Primary.  These logins could be written to a table within a DBA administrative-type database, which could then be referenced to perform the same action in the Mirror.

I say 'safer' because this allows you to review the login actions -- delete or alter -- before pushing the changes to the Mirror.  


Same principal could be used for the 'altered' logins.
0
 
LVL 1

Author Comment

by:marrowyung
Comment Utility
"I'm not sure if I follow you exactly, but if you've deleted a login, there isn't one to copy.  Are you saying that if you delete a login, you want that action to also occur on the mirror server?"

yes sure ! that's why I am going to inprove this script further, that scritp can handle new login and disabled login but not deleted login

"
 A slightly more complex, but potentially safer, method would be a database trigger that fires when the DROP LOGIN is run on the Primary. "

Already has a plan but for that script, has to run on DR server, I can't trigger it from primary server. can I make the trigger to execute the Script/sp  located on DR server ?

"These logins could be written to a table within a DBA administrative-type database, which could then be referenced to perform the same action in the Mirror.
"
The while loop in the script already doing this!  but temp table.

"I say 'safer' because this allows you to review the login actions -- delete or alter -- before pushing the changes to the Mirror."

I don't understnad why and what it means, please say it again.
0
 
LVL 1

Author Comment

by:marrowyung
Comment Utility
if  I create a SP by that script on the DR mirror server, can I call that remote SP from mirror primary server like that by DDL trigger so that whenever a new login added/altered, the remote SP fire out and get new login from primary server?

Create Trigger CopyLoginsToDestination
On All Server
After Create_Login, Alter_Login
As
exec <mirror DR partner serer>.master.dbo.dba_CopyLogins 

Open in new window


will it works in this way ?
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 1

Author Comment

by:marrowyung
Comment Utility
by the way, is the create trigger statment works?


Should be

On Server 

Open in new window


instead of

On All Server

Open in new window


right?
0
 
LVL 1

Author Comment

by:marrowyung
Comment Utility
please reply to this.
0
 
LVL 1

Author Closing Comment

by:marrowyung
Comment Utility
tks.
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now