Recently I have encountered a interesting scenario relate to SQL server backups.In our environment there are few SQL servers are running. They are backed up and databases are also backed up. So everything was running smoothly. Until it's not. One of our servers has crashed.
Well, no one was worried, because we had backups and there were not much of data loss.
So after we rebuild the server (we built it from scratch rather than from backups, because we need to refresh the OS anyway), and after installing SQL server, we tried restoring databases.
Then only everyone realized that, backups were encrypted. I know it is our bad, we should have tested restoring periodically, but in small business like us, that never get happen.
So how do we restore the backups. We needed the DEK (Database Encryption Key) which those backups were encrypted.
Luckily we found, set of certificate backups which were use to encrypt database backups.
Every one was happy.
However, how do we know which certificate to use on this particular server. Name didn't really give us a clue.
So we had to Google/Chat with AI a bit.
That's when we came up following approach.
First you need to restore the backup with just header only.
RESTORE HEADERONLY
FROM DISK = 'D:\Backups\MyEncryptedBackup.bak';
This will show, result set similar to below:
This result set have following columns (56 of them):BackupName
BackupDescription
BackupType
ExpirationDate
Compressed
Position
DeviceType
UserName
ServerName
DatabaseName
DatabaseVersion
DatabaseCreationDate
BackupSize
FirstLSN
LastLSN
CheckpointLSN
DatabaseBackupLSN
BackupStartDate
BackupFinishDate
SortOrder
CodePage
UnicodeLocaleId
UnicodeComparisonStyle
CompatibilityLevel
SoftwareVendorId
SoftwareVersionMajor
SoftwareVersionMinor
SoftwareVersionBuild
MachineName
Flags
BindingID
RecoveryForkID
Collation
FamilyGUID
HasBulkLoggedData
IsSnapshot
IsReadOnly
IsSingleUser
HasBackupChecksums
IsDamaged
BeginsLogChain
HasIncompleteMetaData
IsForceOffline
IsCopyOnly
FirstRecoveryForkID
ForkPointLSN
RecoveryModel
DifferentialBaseLSN
DifferentialBaseGUID
BackupTypeDescription
BackupSetGUID
CompressedBackupSize
Containment
KeyAlgorithm
EncryptorThumbprint
EncryptorType
Last two columns, EncryptorThumbprint and EncryptorType will tell you which certificate has been used.
Something I didn't know before.