[英]Restore encrypted Backup in SQL
I use this code我用这段代码
USE master;
GO
CREATE MASTER KEY ENCRYPTION BY PASSWORD = '1234';
GO
CREATE CERTIFICATE Cer
WITH SUBJECT = 'Hello';
GO
and then backup database with this code然后用这段代码备份数据库
backup database Temp to disk = 'D:\Backup\temp.bak'
WITH
COMPRESSION,
ENCRYPTION
(
ALGORITHM = AES_256,
SERVER CERTIFICATE = Cer
),
STATS = 10
now I can not restore it to another server i create this master key on another server but it dose not work现在我无法将它恢复到另一台服务器 我在另一台服务器上创建了这个主密钥但是它不起作用
The master key
is used to protect the certificate
used for the backup encryption. master key
用于保护用于备份加密的certificate
。 The certificate
is unique - specifying same name for executing the CREATE CERTIFICATE
statement creates different certificate. certificate
是唯一的 - 为执行CREATE CERTIFICATE
语句指定相同的名称会创建不同的证书。
If this was not true, everyone with access to your backup would be able to decrypt it.如果这不是真的,那么每个有权访问您的备份的人都可以解密它。
So, you need to export your certificate:因此,您需要导出证书:
-- Backup the certificate
BACKUP CERTIFICATE BackupEncryptCert TO FILE = 'H:\MSSQL\Backup\Keys\BackupEncryptCert.cer'
WITH PRIVATE KEY (FILE = 'H:\MSSQL\Backup\Keys\BackupEncryptCert.PrivateKey.pvk',
ENCRYPTION BY PASSWORD = 'doodle$7')
GO
and then to create it on the new instance:然后在新实例上创建它:
-- Restoring a certificate from existing certificate backup
CREATE CERTIFICATE BackupEncryptCert
FROM FILE = 'H:\MSSQL\Backup\Keys\BackupEncryptCert.cer'
WITH PRIVATE KEY (FILE = 'H:\MSSQL\Backup\BackupEncryptCert.PrivateKey.pvk',
DECRYPTION BY PASSWORD = 'doodle$7')
GO
Then you will be able to restore your encrypted backup.然后您将能够恢复您的加密备份。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.