30.06.2013 Views

SQL Server Backup and Restore - Simple Talk

SQL Server Backup and Restore - Simple Talk

SQL Server Backup and Restore - Simple Talk

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 4: Restoring From Full <strong>Backup</strong><br />

production. Even if a user doesn't have a login on the production database server, the<br />

restored database still holds the permissions. If that user is eventually given access to<br />

the production machine, he or she will automatically have that level of access, even if it<br />

wasn't explicitly given by the DBA team.<br />

The only case when this may not happen is when the user is using <strong>SQL</strong> <strong>Server</strong> authentication<br />

<strong>and</strong> the internal SID, a unique identifying value, doesn't match on the original <strong>and</strong><br />

target server. If two <strong>SQL</strong> logins with the same name are created on different machines,<br />

the underlying SIDs will be different. So, when we move a database from <strong>Server</strong> A to<br />

<strong>Server</strong> B, a <strong>SQL</strong> login that has permission to access <strong>Server</strong> A will also be moved to <strong>Server</strong><br />

B, but the underlying SID will be invalid <strong>and</strong> the database user will be "orphaned." This<br />

database user will need to be "de-orphaned" (see below) before the permissions will be<br />

valid. This will never happen for matching Active Directory accounts since the SID is<br />

always the same across a domain.<br />

In order to prevent this from happening in our environments, every time we restore a<br />

database from one environment to another we should:<br />

• audit each <strong>and</strong> every login – never assume that if a user has certain permissions in one<br />

environment they need the same in another; fix any internal user mappings for logins<br />

that exist on both servers, to ensure no one gets elevated permissions<br />

• perform orphaned user maintenance – remove permissions for any users that do not<br />

have a login on the server to which we are moving the database; the sp_change_<br />

users_login stored procedure can help with this process, reporting all orphans,<br />

linking a user to its correct login, or creating a new login to which to link:<br />

• EXEC sp_change_users_login 'Report'<br />

• EXEC sp_change_users_login 'Auto_Fix', 'user'<br />

• EXEC sp_change_users_login 'Auto_Fix', 'user', 'login',<br />

'password'<br />

121

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!