BACKUP MASTER KEY (Transact-SQL)BACKUP MASTER KEY (Transact-SQL)

适用对象: yesSQL ServeryesAzure SQL 数据库noAzure SQL 数据仓库no并行数据仓库APPLIES TO: yesSQL Server noAzure SQL Database noAzure SQL Data Warehouse noParallel Data Warehouse

导出数据库主密钥。Exports the database master key.

主题链接图标 TRANSACT-SQL 语法约定Topic link icon Transact-SQL Syntax Conventions

语法Syntax

  
BACKUP MASTER KEY TO FILE = 'path_to_file'   
    ENCRYPTION BY PASSWORD = 'password'  

参数Arguments

FILE ='path_to_file' FILE ='path_to_file'
指定主密钥将导入的文件的完整路径(包括文件名)。Specifies the complete path, including file name, to the file to which the master key will be exported. 此路径可以是本地路径,也可以是网络位置的 UNC 路径。This may be a local path or a UNC path to a network location.

PASSWORD ='password' PASSWORD ='password'
用于加密文件中主密钥的密码。Is the password used to encrypt the master key in the file. 此密码应通过复杂性检查。This password is subject to complexity checks. 有关详细信息,请参阅 Password PolicyFor more information, see Password Policy.

RemarksRemarks

主密钥必须为打开状态,因此在备份主密钥之前应对其进行解密。The master key must be open and, therefore, decrypted before it is backed up. 如果主密钥使用服务主密钥进行加密,则不必显式打开。If it is encrypted with the service master key, the master key does not have to be explicitly opened. 但如果主密钥仅使用密码进行加密,则必须显式打开。But if the master key is encrypted only with a password, it must be explicitly opened.

我们建议您在创建主密钥之后立即对其进行备份,并存储于另外一个安全的位置中。We recommend that you back up the master key as soon as it is created, and store the backup in a secure, off-site location.

权限Permissions

要求对数据库具有 CONTROL 权限。Requires CONTROL permission on the database.

示例Examples

以下示例创建 AdventureWorks2012 主密钥的备份。The following example creates a backup of the AdventureWorks2012 master key. 由于该主密钥未使用服务主密钥进行加密,因此必须指定密码才能将其打开。Because this master key is not encrypted by the service master key, a password must be specified when it is opened.

USE AdventureWorks2012;  
OPEN MASTER KEY DECRYPTION BY PASSWORD = 'sfj5300osdVdgwdfkli7';  
BACKUP MASTER KEY TO FILE = 'c:\temp\exportedmasterkey'   
    ENCRYPTION BY PASSWORD = 'sd092735kjn$&adsg';  
GO   

另请参阅See Also

CREATE MASTER KEY (Transact-SQL) CREATE MASTER KEY (Transact-SQL)
OPEN MASTER KEY (Transact-SQL) OPEN MASTER KEY (Transact-SQL)
CLOSE MASTER KEY (Transact-SQL) CLOSE MASTER KEY (Transact-SQL)
RESTORE MASTER KEY (Transact-SQL) RESTORE MASTER KEY (Transact-SQL)
ALTER MASTER KEY (Transact-SQL) ALTER MASTER KEY (Transact-SQL)
DROP MASTER KEY (Transact-SQL) DROP MASTER KEY (Transact-SQL)
加密层次结构Encryption Hierarchy