Solved

Script to capture logins and user permissions prior to a restore?

Posted on 2014-04-01
2
1,770 Views
Last Modified: 2014-04-07
I'm trying to figure out a way to automate the creation of logins and user permissions. I'm new to SQL administration and inadvertently keep missing one permission here and there and I'm trying to find a full-proof way not to miss any logins and permissions. Below is the manual process I do simply because I don't know any better. Surely there is an automated way to do this?

Scenario:
I have a DB on our test server. I've been asked to restore the DB from production to test and to keep the existing logins and permissions that were on the test DB before the restore.

Current Process:
1) I log onto the test DB.

2) Run the "sp_helpuser" command to capture the existing logins and permissions. Take a screenshot of the results using Snagit or if too large to display all on the screen I copy all with headers and paste it into an Excel spreadsheet.

3) Select the task to "Generate Scripts" and select the following options.
    a) Select specific database objects
    b) Select "users"
    c) Select "Database Roles"
    d) Copy to clipboard

4) Then I store the script to my log file.

5) Backup DB.

Restore Process:

1) Restore DB.

2) Run script that re-creates the Users and Database Roles.

3) Run "sp_helpuser" and reset the missing permissions and orphaned users. I miss these occasionally.
    a) I type the following command to fix the orphaned user issue.
         i) sp_change_users_login 'Auto_Fix', 'User_ID'

Does anyone have a better way of preserving and restoring the logins, users and permissions than what I am doing? I am open to any and all suggestions as I hate making  mistakes.

Thanks
0
Comment
Question by:Lobsterguy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 40

Accepted Solution

by:
lcohan earned 500 total points
ID: 39970581
Assuming you take and use a FULL database backup do the following:

Before you RESTORE the database on the other server you should transfer all the Logins by using:
"How to transfer logins and passwords between instances of SQL Server"
http://support.microsoft.com/kb/918992

when you run that sql script on the Source server it will generate output to be executed on the Target server and you can take out logins you don't need to move - don't worry passwords are included but they are hashed.

This way this is the only thing to do security related and after you restore the DB all users from the database will be already binded to the database roles.

That is - Security exists at SQL Server level and must be done first then at the Database level and that's done for you during the database restore.
0
 

Author Closing Comment

by:Lobsterguy
ID: 39983178
Thanks for the input. Should get me going.
0

Featured Post

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
sql server cross db update 2 23
SQL Server Express or Standard? 5 34
SSRS Page Header from Group Data 2 29
Find special characters using tSQL 6 20
Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Via a live example, show how to shrink a transaction log file down to a reasonable size.

730 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