Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Backup users and permissions before database restore Expand / Collapse
Author
Message
Posted Monday, October 7, 2013 12:46 PM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Tuesday, November 17, 2015 1:35 PM
Points: 100, Visits: 880
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
Post #1502313
Posted Monday, October 7, 2013 1:13 PM


SSChasing Mays

SSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing Mays

Group: General Forum Members
Last Login: Tuesday, January 12, 2016 12:41 PM
Points: 604, Visits: 958
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
Post #1502323
Posted Monday, October 7, 2013 1:21 PM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Tuesday, November 17, 2015 1:35 PM
Points: 100, Visits: 880
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];

Post #1502330
Posted Tuesday, October 8, 2013 11:07 AM


UDP Broadcaster

UDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP Broadcaster

Group: General Forum Members
Last Login: Today @ 6:09 AM
Points: 1,466, Visits: 3,403
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.


Post #1502722
Posted Wednesday, October 9, 2013 6:55 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: 2 days ago @ 5:33 AM
Points: 2,794, Visits: 2,216
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."
Post #1503074
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse