SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Backup users and permissions before database restore


Backup users and permissions before database restore

Author
Message
Robin35
Robin35
SSCommitted
SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)

Group: General Forum Members
Points: 1835 Visits: 1290
Hi,

We are refreshing our test environment daily from our production backup. But the users are loosing their permissions in dev environment. Can anyone suggest me how to automate the process of user and their permission backup and execute the permission script post -refresh ?

I have a query that takes the user, role permissions for a particular database, i need to automate this process. Please post your suggestions.

thanks in advance
Keith Tate
Keith Tate
SSCrazy
SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)

Group: General Forum Members
Points: 2386 Visits: 979
Do you use a scheduled job to refresh the test database? If so, then add a step to run your script. If you don't use a scheduled job how do you automate the process of the restore?



Microsoft Certified Master - SQL Server 2008
Follow me on twitter: @keith_tate

Forum Etiquette: How to post data/code on a forum to get the best help
Robin35
Robin35
SSCommitted
SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)

Group: General Forum Members
Points: 1835 Visits: 1290
Keith Tate (10/7/2013)
Do you use a scheduled job to refresh the test database? If so, then add a step to run your script. If you don't use a scheduled job how do you automate the process of the restore?


Thanks Keith for the response. Yes, we use a scheduled job to refresh and yes we can add a step but this script just outputs the users,permissions which we again need to execute after the refresh is complete.

Script output ( example for one user ) :
IF NOT EXISTS (SELECT name FROM sys.database_principals WHERE name = 'Test') CREATE USER [Test] FOR LOGIN [Test] WITH DEFAULT_SCHEMA =dbo;
EXEC sp_AddRoleMember @rolename = 'fairparamwriter', @membername = 'Test';
EXEC sp_AddRoleMember @rolename = 'fairparamwriter', @membername = 'Test';
GRANT EXECUTE TO [Test];
GRANT SELECT ON [dbo].[dbatesttable] TO [Test];
Summer90
Summer90
SSCertifiable
SSCertifiable (7.4K reputation)SSCertifiable (7.4K reputation)SSCertifiable (7.4K reputation)SSCertifiable (7.4K reputation)SSCertifiable (7.4K reputation)SSCertifiable (7.4K reputation)SSCertifiable (7.4K reputation)SSCertifiable (7.4K reputation)

Group: General Forum Members
Points: 7423 Visits: 3831
The way I solved this is once the db is refreshed, add back what you need manually like via the GUI and script out the commands... then simply put those commands into a step after the restore.
free_mascot
free_mascot
SSCertifiable
SSCertifiable (7.7K reputation)SSCertifiable (7.7K reputation)SSCertifiable (7.7K reputation)SSCertifiable (7.7K reputation)SSCertifiable (7.7K reputation)SSCertifiable (7.7K reputation)SSCertifiable (7.7K reputation)SSCertifiable (7.7K reputation)

Group: General Forum Members
Points: 7695 Visits: 2250
Check for stored procedure to fix orphaned users or fix user login which may help. Or create a script of commands which manually you are executing on server to fix users and execute by creating additional step after restore.

---------------------------------------------------
"Thare are only 10 types of people in the world:
Those who understand binary, and those who don't."
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search