Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Restoring database with TDE to a 2nd instance Expand / Collapse
Author
Message
Posted Tuesday, September 29, 2009 1:23 PM
SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Wednesday, December 10, 2014 4:05 AM
Points: 907, Visits: 1,903
I was unsure of how to do this so i done some googling and a few tests of my own, and although i am successful, i have a few questions. heres what i did:

On Instance 1 I created a master key, created a server cert, backed up the server cert and encrypted it with a password. I then created a db encryption key using the server cert and enabled TDE, and took a backup. no problems
use master
GO
--create master key
create master key encryption by password = 'strong_Passw0rD'
GO
--create server certificate
Create certificate ServerCert with subject = 'server cert for use with TDE'
GO
--backup server cert, encrypting it by password
Backup certificate ServerCert to file = 'C:\cert_Backups\servercert.cer'
with private key (file = 'C:\cert_Backups\servercert.key',encryption By Password = 'strong_Passw0rD')
go

use security_testing
GO
--create db encryption key which is encrypted by the serverCert
create database encryption key with algorithm = AES_128
encryption by server certificate ServerCert
GO

--enable encryption
Alter database security_testing
set encryption on
GO

--backup encrypted database
backup database security_testing
to disk = 'C:\cert_Backups\db_bak\security_testing_encrypted_bak.bak'

On instance 2, i tried to restore the backup, this failed, so i created a new server master key, and then restored the server cert and had no problems restoring the backup:
--try to restore database on 2nd instance
RESTORE DATABASE [TDE_Restore] FROM DISK = N'C:\cert_Backups\db_bak\security_testing_encrypted_bak.bak' WITH FILE = 1,
MOVE N'Security_Testing' TO N'C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\TDE_Restore.mdf',
MOVE N'Security_Testing_log' TO N'C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\TDE_Restore_1.LDF', NOUNLOAD, STATS = 10
GO
--cannot restore database.

--trying to restore keys first.

USE master
GO
CREATE MASTER KEY ENCRYPTION BY PASSWORD = 'TDEtesting123'
GO

CREATE CERTIFICATE serverCert FROM FILE = 'C:\cert_Backups\servercert.cer'
WITH PRIVATE KEY (FILE = 'C:\cert_Backups\servercert.key', DECRYPTION BY PASSWORD = 'strong_Passw0rD')
GO

RESTORE DATABASE [TDE_Restore] FROM DISK = N'C:\cert_Backups\db_bak\security_testing_encrypted_bak.bak' WITH FILE = 1,
MOVE N'Security_Testing' TO N'C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\TDE_Restore.mdf',
MOVE N'Security_Testing_log' TO N'C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\TDE_Restore_1.LDF', NOUNLOAD, STATS = 10
GO
--Success

My question surrounds the server master key. i thought i should have to backup the server master key from instance 1 and restore it to instance 2 in order to be able to restore the server cert and thus the database. as you can see above, i dont, as i created a completely new server master key on instance 2 with a completely different password. what is the purpose of the server master key in this case?

Question 2 is where does the Service Master Key fit into all this?
Post #795405
Posted Tuesday, September 29, 2009 2:02 PM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Yesterday @ 5:09 AM
Points: 2,373, Visits: 6,769
If my understanding is correct, Master key just protect the private key of certificates and asymmetric keys that are present in the DB. It is the certificate that matters in TDE.
That is my understanding


-Roy
Post #795429
Posted Tuesday, September 29, 2009 2:08 PM
SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Wednesday, December 10, 2014 4:05 AM
Points: 907, Visits: 1,903
Roy Ernest (9/29/2009)
If my understanding is correct, Master key just protect the private key of certificates and asymmetric keys that are present in the DB. It is the certificate that matters in TDE.
That is my understanding


to protect the cert from what though? If i have the cert and the password to decrypt the cert, theres no way a master key can protect it, but the master key is still required to create the server certificate ( and prob keys in the db, have not checked this yet though).
Post #795437
Posted Thursday, October 17, 2013 4:17 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Thursday, December 11, 2014 9:34 PM
Points: 51, Visits: 319
Master key is created at instance level and hence it is absolutely OK to create a master key for the destination database instance which you did.

The Certificate and Keys becaked up from the source database server are the ones that will be used to encrypt.
Post #1505575
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse