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

 All Forums
 SQL Server 2000 Forums
 SQL Server Administration (2000)
 synchronize Users/Logins Frm prod To DR Server

Author  Topic 

cshekar
Starting Member

49 Posts

Posted - 2004-08-19 : 11:27:32
I need synchronize all the users from production servers to DR server where they are going do the testing. In DR Server

I have about 15 Production databases and each database about 80 – 100 users and
10 Roles on each database.

My problem is How to synchronize all the users and roles from production into DR server.I known when I do the Backup the user database it will not copy the users, Logins and the Roles. On each database, so I do not know how to how to bring the logins to Dr server.

Is that If I backup the Master database is all the users will copy as well or not


Please help me to how to copy the Users, Logins and roles based on corresponding database

Thanks
chandra

Kristen
Test

22859 Posts

Posted - 2004-08-19 : 13:08:24
Dunno if this is suitable, but you could run this on the database AFTER restore (in TEXT RESULTS mode in Query Anayser) and it will give you some SQL Code to execute to reinstate the users. You can choose which users you want to actually restore, and any users already on the server will be resynchronised, rather than recreated

-- List any User/Group profiles that need creating/reinstating
PRINT 'Cut&Paste the following code and EXECUTE any appropriate snippets'
SET NOCOUNT ON
SELECT DISTINCT
CASE WHEN L.sid IS NOT NULL
THEN '-- User ' + COALESCE(U.[name], '[NULL]') + ' already exists on server'
ELSE 'EXEC sp_addlogin ''' + U.name + ''', ''password'', ''' + db_name() + ''''
+ CHAR(9) + '-- Only add if required!!'
END,
CHAR(13)+CHAR(10)+LEFT('-- EXEC ' + db_name()
+ '.dbo.sp_dropuser @name_in_db = '
+ '''' + U.name + ''' -- Remove if access no longer require to this DB', 200),
CHAR(13)+CHAR(10)+LEFT('EXEC ' + db_name()
+ '.dbo.sp_change_users_login ''Update_One'', '
+ '''' + U.name + ''', '
+ '''' + U.name + '''', 90),
CHAR(13)+CHAR(10)+'------------------------------'
from sysusers U
left outer join (sysmembers M inner join sysusers G on G.uid = M.groupuid) on M.memberuid = U.uid
left outer join master.dbo.syslogins L on L.[name] COLLATE SQL_Latin1_General_CP1_CI_AS = U.[name] COLLATE SQL_Latin1_General_CP1_CI_AS
where U.islogin = 1
and U.isaliased = 0
and U.hasdbaccess = 1
and
(
G.issqlrole = 1
or G.uid is null
)
and U.name not in ('dbo')

Kristen
Go to Top of Page

cshekar
Starting Member

49 Posts

Posted - 2004-08-19 : 13:31:41
Thank you so much kristen
but I want to synchronize all th users and roles same as production to DR server
can I just just this scripts right after the teh restore the database.
Thanks
chandra




chandra shekar
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2004-08-19 : 14:16:09
The database backup will contain the roles and users, but it will not contain the logins. You can use sp_help_revlogin.

Search the forums for sp_help_revlogin.

I use my own custom one called isp_Transfer_Logins. You can find this code in the forums as well.

Tara
Go to Top of Page
   

- Advertisement -