在 Azure Redis 缓存中导入和导出数据Import and Export data in Azure Cache for Redis

导入/导出是一种 Azure Redis 缓存数据管理操作,可用于通过从高级缓存导入 Azure Redis 缓存数据库 (RDB) 快照以及将 Azure Redis 缓存数据库 (RDB) 快照导出到 Azure 存储帐户中的 blob 来相应地将数据导入到 Azure Redis 缓存以及从 Azure Redis 缓存导出数据。Import/Export is an Azure Cache for Redis data management operation, which allows you to import data into Azure Cache for Redis or export data from Azure Cache for Redis by importing and exporting an Azure Cache for Redis Database (RDB) snapshot from a premium cache to a blob in an Azure Storage Account.

  • 导出 - 可以将 Azure Redis 缓存 RDB 快照导出到页 Blob。Export - you can export your Azure Cache for Redis RDB snapshots to a Page Blob.
  • 导入 - 可以从页 Blob 或块 Blob 导入 Azure Redis 缓存 RDB 快照。Import - you can import your Azure Cache for Redis RDB snapshots from either a Page Blob or a Block Blob.

通过导入/导出可在不同的 Azure Redis 缓存实例之间进行迁移,或者在使用之前使用数据填充缓存。Import/Export enables you to migrate between different Azure Cache for Redis instances or populate the cache with data before use.

本文提供使用 Azure Redis 缓存导入和导出数据的指南,并提供常见问题的解答。This article provides a guide for importing and exporting data with Azure Cache for Redis and provides the answers to commonly asked questions.

重要

导入/导出仅适用于高级层缓存。Import/Export is only available for Premium tier caches.

ImportImport

导入可用于从任何云或环境中运行的任何 Redis 服务器引入与 Redis 兼容的 RDB 文件,包括在 Linux、Windows 上运行的 Redis 或任何云提供程序(如 Amazon Web Services 等)。Import can be used to bring Redis compatible RDB files from any Redis server running in any cloud or environment, including Redis running on Linux, Windows, or any cloud provider such as Amazon Web Services and others. 导入数据是使用预先填充的数据创建缓存的简单方式。Importing data is an easy way to create a cache with pre-populated data. 在导入过程中,Azure Redis 缓存从 Azure 存储将 RDB 文件加载到内存中,再将密钥插入到缓存中。During the import process, Azure Cache for Redis loads the RDB files from Azure storage into memory and then inserts the keys into the cache.

备注

在开始导入操作之前,请确保 Redis 数据库 (RDB) 文件已上传到 Azure 存储的页 blob 或块 blob 中,并与 Azure Redis 缓存实例在同一区域和订阅中。Before beginning the import operation, ensure that your Redis Database (RDB) file or files are uploaded into page or block blobs in Azure storage, in the same region and subscription as your Azure Cache for Redis instance. 有关详细信息,请参阅 Azure Blob 存储入门For more information, see Get started with Azure Blob storage. 如果已使用 Azure Redis 缓存导出功能导出 RDB 文件,则 RDB 文件已存储在页 blob 中并已准备好进行导入。If you exported your RDB file using the Azure Cache for Redis Export feature, your RDB file is already stored in a page blob and is ready for importing.

  1. 若要导入一个或多个导出的缓存 blob,请在 Azure 门户中浏览到缓存,然后在“资源”菜单中单击“导入数据”。To import one or more exported cache blobs, browse to your cache in the Azure portal and click Import data from the Resource menu.

    导入数据

  2. 单击“选择 Blob”,并选择包含要导入数据的存储帐户 。Click Choose Blob(s) and select the storage account that contains the data to import.

    选择存储帐户

  3. 单击包含要导入数据的容器。Click the container that contains the data to import.

    选择容器

  4. 通过单击 blob 名称的左侧区域选择要导入的一个或多个 blob,并单击“选择” 。Select one or more blobs to import by clicking the area to the left of the blob name, and then click Select.

    选择 blob

  5. 单击“导入”以开始导入过程 。Click Import to begin the import process.

    重要

    在导入过程中,缓存客户端无法访问该缓存,并且将删除该缓存中的任何现有数据。The cache is not accessible by cache clients during the import process, and any existing data in the cache is deleted.

    Import

    可以通过关注 Azure 门户中的通知或通过查看审核日志中的事件,来监视导入操作的进度。You can monitor the progress of the import operation by following the notifications from the Azure portal, or by viewing the events in the audit log.

    导入进度

ExportExport

使用导出可以将 Azure Redis 缓存中存储的数据导出到与 Redis 兼容的 RDB 文件。Export allows you to export the data stored in Azure Cache for Redis to Redis compatible RDB file(s). 可以使用此功能将一个 Azure Redis 缓存实例中的数据移到另一个 Azure Redis 缓存实例或另一个 Redis 服务器。You can use this feature to move data from one Azure Cache for Redis instance to another or to another Redis server. 在导出过程中,会在托管 Azure Redis 缓存服务器实例的 VM 上创建临时文件,并将该文件上传到指定的存储帐户。During the export process, a temporary file is created on the VM that hosts the Azure Cache for Redis server instance, and the file is uploaded to the designated storage account. 导出操作完成后,无论状态为成功还是失败,都会删除临时文件。When the export operation completes with either a status of success or failure, the temporary file is deleted.

  1. 若要将缓存的当前内容导出到存储,请在 Azure 门户中浏览到缓存,然后在“资源”菜单中单击“导出数据”。To export the current contents of the cache to storage, browse to your cache in the Azure portal and click Export data from the Resource menu.

    选择存储容器

  2. 单击“选择存储容器”并选择所需的存储帐户 。Click Choose Storage Container and select the desired storage account. 存储帐户必须与缓存在同一订阅和区域中。The storage account must be in the same subscription and region as your cache.

    重要

    导出适用于页 blob,经典存储帐户和 Resource Manager 存储帐户都支持页 blob,但目前 Blob 存储帐户不支持页 blob。Export works with page blobs, which are supported by both classic and Resource Manager storage accounts, but are not supported by Blob storage accounts at this time. 有关详细信息,请参阅 Azure 存储帐户概述For more information, see Azure storage account overview.

    存储帐户

  3. 选择所需的 blob 容器,并单击“选择” 。Choose the desired blob container and click Select. 要使用新容器,请单击“添加容器”,先添加容器,再从列表中选择容器 。To use new a container, click Add Container to add it first and then select it from the list.

    选择存储容器

  4. 键入 Blob 名称前缀,并单击“导出”以开始导出过程 。Type a Blob name prefix and click Export to start the export process. blob 名称前缀用作此导出操作生成的文件名的前缀。The blob name prefix is used to prefix the names of files generated by this export operation.

    Export

    可通过关注 Azure 门户中的通知或查看审核日志中的事件,来监视导出操作的进度。You can monitor the progress of the export operation by following the notifications from the Azure portal, or by viewing the events in the audit log.

    导出数据完成

    在导出过程中,缓存仍可供使用。Caches remain available for use during the export process.

导入/导出常见问题解答Import/Export FAQ

本部分包含有关导入/导出功能的常见问题解答。This section contains frequently asked questions about the Import/Export feature.

哪些定价层可以使用导入/导出?What pricing tiers can use Import/Export?

导入/导出仅在高级定价层中可用。Import/Export is available only in the premium pricing tier.

能否从任何 Redis 服务器导入数据?Can I import data from any Redis server?

能,除了导入从 Azure Redis 缓存实例导出的数据外,还可以从任何云或环境中运行的任何 Redis 服务器导入 RDB 文件,如 Linux、Windows 或云提供程序(如 Amazon Web Services)。Yes, in addition to importing data exported from Azure Cache for Redis instances, you can import RDB files from any Redis server running in any cloud or environment, such as Linux, Windows, or cloud providers such as Amazon Web Services. 为此,请从所需的 Redis 服务器将 RDB 文件上传到 Azure 存储帐户中的页 blob 或块 blob,然后将其导入到高级 Azure Redis 缓存实例中。To do this, upload the RDB file from the desired Redis server into a page or block blob in an Azure Storage Account, and then import it into your premium Azure Cache for Redis instance. 例如,你可能想要从生产缓存导出数据,然后将其导入到用作过渡环境一部分的缓存,用于测试或迁移。For example, you may want to export the data from your production cache and import it into a cache used as part of a staging environment for testing or migration.

重要

使用页 blob 时,要成功导入从非 Azure Redis 缓存的 Redis 服务器导出的数据,页 blob 大小必须在 512 字节边界上对齐。To successfully import data exported from Redis servers other than Azure Cache for Redis when using a page blob, the page blob size must be aligned on a 512 byte boundary. 有关用于执行任何所需的字节填充的示例代码,请参阅示例页 blob 上传For sample code to perform any required byte padding, see Sample page blob upload.

可以导入哪些 RDB 版本?What RDB versions can I import?

对于 RDB 版本 7,Azure Redis 缓存支持 RDB 导入。Azure Cache for Redis supports RDB import up through RDB version 7.

导入/导出操作期间缓存是否可用?Is my cache available during an Import/Export operation?

  • 导出 - 缓存保持可用,可以在导出操作过程中继续使用缓存。Export - Caches remain available and you can continue to use your cache during an export operation.
  • 导入 - 在导入操作开始时,缓存即变为不可用,在导入操作完成后,缓存变为可供使用。Import - Caches become unavailable when an import operation starts, and become available for use when the import operation completes.

能否对 Redis 群集使用导入/导出?Can I use Import/Export with Redis cluster?

能,并且可以在群集缓存和非群集缓存之间导入/导出。Yes, and you can import/export between a clustered cache and a non-clustered cache. 由于 Redis 群集仅支持数据库 0,因此将不会导入 0 以外的数据库中的任何数据。Since Redis cluster only supports database 0, any data in databases other than 0 isn't imported. 导入群集缓存数据时,密钥会在群集的分片之间重新分发。When clustered cache data is imported, the keys are redistributed among the shards of the cluster.

导入/导出如何可用于自定义数据库设置?How does Import/Export work with a custom databases setting?

某些定价层具有不同的数据库限制,因此,如果在缓存创建过程中为 databases 设置配置了自定义值,则在导入时需注意一些注意事项。Some pricing tiers have different databases limits, so there are some considerations when importing if you configured a custom value for the databases setting during cache creation.

  • 当导入到的定价层的 databases 限制低于导出层的相应限制时:When importing to a pricing tier with a lower databases limit than the tier from which you exported:
    • 如果使用默认 databases 数(对于所有定价层来说均为 16),则不会丢失数据。If you are using the default number of databases, which is 16 for all pricing tiers, no data is lost.
    • 如果使用的是在要导入到的层的限制内的自定义 databases 数,则不会丢失数据。If you are using a custom number of databases that falls within the limits for the tier to which you are importing, no data is lost.
    • 如果导出的数据包含超出新层限制的数据库中的数据,则将不会导入这些更高版本数据库中的数据。If your exported data contained data in a database that exceeds the limits of the new tier, the data from those higher databases is not imported.

导入/导出与 Redis 持久性有何区别?How is Import/Export different from Redis persistence?

Azure Redis 缓存暂留能够将 Redis 中存储的数据长期保存在 Azure 存储中。Azure Cache for Redis persistence allows you to persist data stored in Redis to Azure Storage. 配置暂留以后,Azure Redis 缓存按照可配置的备份频率,将 Azure Redis 缓存的快照以 Redis 二进制格式暂留在磁盘上。When persistence is configured, Azure Cache for Redis persists a snapshot of the Azure Cache for Redis in a Redis binary format to disk based on a configurable backup frequency. 如果发生了灾难性事件,导致主缓存和副本缓存都无法使用,则会使用最新快照自动还原缓存数据。If a catastrophic event occurs that disables both the primary and replica cache, the cache data is restored automatically using the most recent snapshot. 有关详细信息,请参阅如何为高级 Azure Redis 缓存配置数据持久性For more information, see How to configure data persistence for a Premium Azure Cache for Redis.

使用导入/导出,可以在 Azure Redis 缓存中引入或导出数据。Import/ Export allows you to bring data into or export from Azure Cache for Redis. 它不使用 Redis 持久性配置备份和还原。It does not configure backup and restore using Redis persistence.

能否使用 PowerShell、CLI 或其他管理客户端自动执行导入/导出?Can I automate Import/Export using PowerShell, CLI, or other management clients?

是,有关 PowerShell 说明,请参阅导入 Azure Redis 缓存导出 Azure Redis 缓存Yes, for PowerShell instructions see To import an Azure Cache for Redis and To export an Azure Cache for Redis.

在导入/导出操作期间收到超时错误。I received a timeout error during my Import/Export operation. 它意味着什么?What does it mean?

如果在发起操作前停留在“导入数据”或“导出数据”边栏选项卡的时间超过 15 分钟,则将收到错误,其错误消息类似于以下示例 :If you remain on the Import data or Export data blade for longer than 15 minutes before initiating the operation, you receive an error with an error message similar to the following example:

The request to import data into cache 'contoso55' failed with status 'error' and error 'One of the SAS URIs provided could not be used for the following reason: The SAS token end time (se) must be at least 1 hour from now and the start time (st), if given, must be at least 15 minutes in the past.

若要解决此问题,请在经过 15 分钟前发起导入或导出操作。To resolve this, initiate the import or export operation before 15 minutes has elapsed.

在将数据导出到 Azure Blob 存储时遇到错误。I got an error when exporting my data to Azure Blob Storage. 发生了什么情况?What happened?

导出仅适用于以页 blob 形式存储的 RDB 文件。Export works only with RDB files stored as page blobs. 目前不支持其他 blob 类型,包括带有热层和冷层的 Blob 存储帐户。Other blob types are not currently supported, including Blob storage accounts with hot and cool tiers. 有关详细信息,请参阅 Azure 存储帐户概述For more information, see Azure storage account overview.

后续步骤Next steps

了解有关 Azure Cache for Redis 功能的详细信息。Learn more about Azure Cache for Redis features.