Azure Cosmos DB 中的联机备份和按需数据还原Online backup and on-demand data restore in Azure Cosmos DB

适用于: SQL API Cassandra API Gremlin API 表 API Azure Cosmos DB API for MongoDB

Azure Cosmos DB 会定期自动备份数据。Azure Cosmos DB automatically takes backups of your data at regular intervals. 自动备份不会影响数据库操作的性能或可用性。The automatic backups are taken without affecting the performance or availability of the database operations. 所有备份单独存储在一个存储服务中并进行多区域复制,以便针对区域性灾难进行复原。All the backups are stored separately in a storage service, and those backups are multiple-regionally replicated for resiliency against regional disasters. 如果意外删除或更新了 Azure Cosmos 帐户、数据库或容器,而稍后需要恢复数据,那么在这种情况下自动备份非常有用。The automatic backups are helpful in scenarios when you accidentally delete or update your Azure Cosmos account, database, or container and later require the data recovery.

自动联机备份Automatic and online backups

使用 Azure Cosmos DB,数据和数据备份都高度冗余,并且具有可复原性,能抵御区域性灾难。With Azure Cosmos DB, not only your data, but also the backups of your data are highly redundant and resilient to regional disasters. 以下步骤演示 Azure Cosmos DB 如何执行数据备份:The following steps show how Azure Cosmos DB performs data backup:

  • Azure Cosmos DB 每 4 小时自动完整备份数据库一次,默认情况下在任何时间点都只存储最新的 2 个备份。Azure Cosmos DB automatically takes a full backup of your database every 4 hours and at any point of time, only the latest two backups are stored by default. 如果默认间隔不能满足工作负荷要求,则可以从 Azure 门户更改备份间隔和保留期。If the default intervals aren't sufficient for your workloads, you can change the backup interval and the retention period from the Azure portal. 可以在创建 Azure Cosmos 帐户期间或之后更改备份配置。You can change the backup configuration during or after the Azure Cosmos account is created. 如果删除了容器或数据库,Azure Cosmos DB 会将给定容器或数据库中的现有快照保留 30 天。If the container or database is deleted, Azure Cosmos DB retains the existing snapshots of a given container or database for 30 days.

  • Azure Cosmos DB 将这些备份存储在 Azure Blob 存储中,而实际数据以本地形式驻留在 Azure Cosmos DB 中。Azure Cosmos DB stores these backups in Azure Blob storage whereas the actual data resides locally within Azure Cosmos DB.

  • 为保证低延迟,备份的快照将存储在 Azure Blob 存储中,且所在区域与当前写入区域(如果有多区域写入配置,则为其中一个写入区域)相同。To guarantee low latency, the snapshot of your backup is stored in Azure Blob storage in the same region as the current write region (or one of the write regions, in case you have a multi-region write configuration). 对于针对区域性灾难的恢复,Azure Blob 存储中备份数据的屏幕快照将通过异地冗余存储 (GRS) 再次复制到另一区域。For resiliency against regional disaster, each snapshot of the backup data in Azure Blob storage is again replicated to another region through geo-redundant storage (GRS). 根据源区域以及与源区域关联的区域对确定备份复制的目标区域。The region to which the backup is replicated is based on your source region and the regional pair associated with the source region. 若要了解详细信息,请参阅 Azure 区域的异地冗余对列表一文。To learn more, see the list of geo-redundant pairs of Azure regions article. 不能直接访问此数据库。You cannot access this backup directly. 当你通过支持请求来请求还原后,Azure Cosmos DB 团队将还原你的备份。Azure Cosmos DB team will restore your backup when you request through a support request.

    下图显示了如何在中国北部的远程 Azure Blob 存储帐户中备份 Azure Cosmos 容器(其三个主要物理分区全部位于中国北部),然后将其复制到中国东部:The following image shows how an Azure Cosmos container with all the three primary physical partitions in China North is backed up in a remote Azure Blob Storage account in China North and then replicated to China East:

    GRS Azure 存储中所有 Cosmos DB 实体的定期完整备份

  • 备份不会影响应用程序的性能或可用性。The backups are taken without affecting the performance or availability of your application. Azure Cosmos DB 在后台执行数据备份,不会消耗任何其他预配吞吐量 (RU),也不会影响数据库的性能和可用性。Azure Cosmos DB performs data backup in the background without consuming any additional provisioned throughput (RUs) or affecting the performance and availability of your database.

修改备份时间间隔和保持期Modify the backup interval and retention period

Azure Cosmos DB 每 4 小时自动对数据库执行一次完整备份,而且在任何时候都只存储最新的 2 个备份。Azure Cosmos DB automatically takes a full backup of your data for every 4 hours and at any point of time, the latest two backups are stored. 此配置是默认选项,无需额外付费即可使用。This configuration is the default option and it's offered without any additional cost. 你可以在创建 Azure Cosmos 帐户期间或创建帐户之后更改默认备份时间间隔和保持期。You can change the default backup interval and retention period during the Azure Cosmos account creation or after the account is created. 备份配置是在 Azure Cosmos 帐户级别设置的,需要在每个帐户上配置。The backup configuration is set at the Azure Cosmos account level and you need to configure it on each account. 为帐户配置备份选项后,它将应用于该帐户中的所有容器。After you configure the backup options for an account, it's applied to all the containers within that account. 目前,你只能从 Azure 门户更改它们的备份选项。Currently you can change them backup options from Azure portal only.

如果数据被意外删除或损坏,在你创建支持请求以申请还原数据之前,请确保将帐户的备份保留期延长到至少 7 天。最好在发生此事件的 8 小时内延长保留期。If you have accidentally deleted or corrupted your data, before you create a support request to restore the data, make sure to increase the backup retention for your account to at least seven days. It's best to increase your retention within 8 hours of this event. 这样,Azure Cosmos DB 团队才有足够的时间来还原你的帐户。This way, the Azure Cosmos DB team has enough time to restore your account.

使用以下步骤可为现有 Azure Cosmos 帐户更改默认备份选项:Use the following steps to change the default backup options for an existing Azure Cosmos account:

  1. 登录到 Azure 门户Sign into the Azure portal.

  2. 导航到你的 Azure Cosmos 帐户,打开“备份和还原”窗格。Navigate to your Azure Cosmos account and open the Backup & Restore pane. 根据需要更新备份间隔和备份保持期。Update the backup interval and the backup retention period as required.

    • 备份间隔 - 这是 Azure Cosmos DB 尝试对数据进行备份的间隔。Backup Interval - It's the interval at which Azure Cosmos DB attempts to take a backup of your data. 备份需要一定的时间,在某些情况下,可能由于下游依赖项而失败。Backup takes a non-zero amount of time and in some case it could potentially fail due to downstream dependencies. Azure Cosmos DB 会尽力按配置的间隔进行备份,但它不能保证备份在该时间间隔内完成。Azure Cosmos DB tries its best to take a backup at the configured interval, however, it doesn't guarantee that the backup completes within that time interval. 可以按小时或分钟配置此值。You can configure this value in hours or minutes. 备份间隔不能小于 1 小时且不能超过 24 小时。Backup Interval cannot be less than 1 hour and greater than 24 hours. 更改此间隔后,新间隔将从进行上次备份时开始生效。When you change this interval, the new interval takes into effect starting from the time when the last backup was taken.

    • 备份保持期 - 它表示保留每个备份的时间段。Backup Retention - It represents the period where each backup is retained. 可以按小时或天配置它。You can configure it in hours or days. 最小保持期不能小于备份间隔的两倍(以小时为单位),并且不能超过 720 小时。The minimum retention period can't be less than two times the backup interval (in hours) and it can't be greater than 720 hours.

    • 保留的数据副本 - 默认情况下,会免费提供数据的两个备份副本。Copies of data retained - By default, two backup copies of your data are offered at free of charge. 如果需要两个以上的副本,则需支付额外费用。There is an additional charge if you need more than two copies. 请参阅定价页中的“已用存储”部分,了解额外副本的确切价格。See the Consumed Storage section in the Pricing page to know the exact price for additional copies.

    为现有 Azure Cosmos 帐户配置备份间隔和保留期

如果在帐户创建过程中配置备份选项,则可以配置“备份策略”(是“定期”或“连续”) 。If you configure backup options during the account creation, you can configure the Backup policy, which is either Periodic or Continuous. 定期策略使你可以配置备份间隔和备份保留期。The periodic policy allows you to configure the Backup interval and Backup retention. 连续策略目前仅通过注册提供。The continuous policy is currently available by sign-up only. Azure Cosmos DB 团队会评估你的工作负载并审批你的请求。The Azure Cosmos DB team will assess your workload and approve your request.

为新 Azure Cosmos 帐户配置定期或连续备份策略

请求从备份还原数据Request data restore from a backup

如果意外删除了数据库或容器,可以提交支持工单联系 Azure 支持,以便从自动联机备份中还原数据。If you accidentally delete your database or a container, you can file a support ticket or call the Azure support to restore the data from automatic online backups. Azure 支持仅适用于选定的计划,例如“标准”、“开发人员”以及更高级别的计划 。Azure support is available for selected plans only such as Standard, Developer, and plans higher than those. 不适用于基本计划 。Azure support is not available with Basic plan. 若要了解不同的支持方案,请参阅 Azure 支持计划页。To learn about different support plans, see the Azure support plans page.

若要还原备份的特定快照,Azure Cosmos DB 要求在该快照的备份周期的持续时间内可用。To restore a specific snapshot of the backup, Azure Cosmos DB requires that the data is available for the duration of the backup cycle for that snapshot. 在请求还原之前,应该了解以下详细信息:You should have the following details before requesting a restore:

  • 准备好订阅 ID。Have your subscription ID ready.

  • 应根据数据被意外删除或修改的方式,准备好提供其他信息。Based on how your data was accidentally deleted or modified, you should prepare to have additional information. 建议提前准备可用的信息,从而尽量减少可能在某些有时效的情况下造成不良影响的来回传输。It is advised that you have the information available ahead to minimize the back-and-forth that can be detrimental in some time sensitive cases.

  • 如果删除了整个 Azure Cosmos DB 帐户,则需要提供删除的帐户的名称。If the entire Azure Cosmos DB account is deleted, you need to provide the name of the deleted account. 如果创建了同名的另一个帐户,请与支持团队共享该帐户,因为这有助于确定要选择的正确帐户。If you create another account with the same name as the deleted account, share that with the support team because it helps to determine the right account to choose. 建议为删除的每个帐户提交不同的支持工单,因为这可以最大限度地减少还原状态的混乱。It's recommended to file different support tickets for each deleted account because it minimizes the confusion for the state of restore.

  • 如果删除了一个或多个数据库,应提供 Azure Cosmos 帐户及 Azure Cosmos 数据库名,并指定是否存在同名的新数据库。If one or more databases are deleted, you should provide the Azure Cosmos account, as well as the Azure Cosmos database names and specify if a new database with the same name exists.

  • 如果删除了一个或多个容器,应提供 Azure Cosmos 帐户名、数据库名和容器名。If one or more containers are deleted, you should provide the Azure Cosmos account name, database names, and the container names. 并指定是否存在同名容器。And specify if a container with the same name exists.

  • 如果意外删除或损坏了数据,则应在 8 小时内联系 Azure 支持,以便 Azure Cosmos DB 团队帮助你从备份中还原数据。If you have accidentally deleted or corrupted your data, you should contact Azure support within 8 hours so that the Azure Cosmos DB team can help you restore the data from the backups. 在你创建支持请求以申请还原数据之前,请确保将帐户的备份保留期延长到至少 7 天。最好在发生此事件的 8 小时内延长保留期。Before you create a support request to restore the data, make sure to increase the backup retention for your account to at least seven days. It's best to increase your retention within 8 hours of this event. 这样,Azure Cosmos DB 支持团队才有足够的时间来还原你的帐户。This way the Azure Cosmos DB support team will have enough time to restore your account.

除了 Azure Cosmos 帐户名、数据库名、容器名以外,还应指定数据可以还原到的时间点。In addition to Azure Cosmos account name, database names, container names, you should specify the point in time to which the data can be restored to. 务必尽量精确,因为这有助于我们确定当时可用的最佳备份。It is important to be as precise as possible to help us determine the best available backups at that time. 指定 UTC 时间也很重要。It is also important to specify the time in UTC.

下面的屏幕截图说明如何为容器(集合/图/表)创建通过 Azure 门户还原数据的支持请求。The following screenshot illustrates how to create a support request for a container(collection/graph/table) to restore data by using Azure portal. 提供其他详细信息(例如数据类型、还原目的、删除数据的时间),以帮助我们设置请求的优先级。Provide additional details such as type of data, purpose of the restore, time when the data was deleted to help us prioritize the request.

使用 Azure 门户创建备份支持请求

从备份还原数据时的注意事项Considerations for restoring the data from a backup

在以下情况之一中,可能会意外删除或修改数据:You may accidentally delete or modify your data in one of the following scenarios:

  • 删除整个 Azure Cosmos 帐户。Delete the entire Azure Cosmos account.

  • 删除一个或多个 Azure Cosmos 数据库。Delete one or more Azure Cosmos databases.

  • 删除一个或多个 Azure Cosmos 容器。Delete one or more Azure Cosmos containers.

  • 删除或修改容器中的 Azure Cosmos 项(例如文档)。Delete or modify the Azure Cosmos items (for example, documents) within a container. 此特定情况通常称为"数据损坏"。This specific case is typically referred to as data corruption.

  • 删除或损坏共享产品数据库中的共享产品数据库或容器。A shared offer database or containers within a shared offer database are deleted or corrupted.

在上述所有情况中,Azure Cosmos DB 均可还原数据。Azure Cosmos DB can restore data in all the above scenarios. 进行还原时,会创建一个新的 Azure Cosmos 帐户来保存还原数据。When restoring, a new Azure Cosmos account is created to hold the restored data. 如果未指定新帐户的名称,则其名称将采用 <Azure_Cosmos_account_original_name>-restored1 格式。The name of the new account, if it's not specified, will have the format <Azure_Cosmos_account_original_name>-restored1. 如果尝试多次还原,则最后一位数将递增。The last digit is incremented when multiple restores are attempted. 不能将数据还原到预先创建的 Azure Cosmos 帐户中。You can't restore data to a pre-created Azure Cosmos account.

意外删除 Azure Cosmos 帐户后,如果该帐户名未被使用,则可将数据还原到相同名称的帐户中。When you accidentally delete an Azure Cosmos account, we can restore the data into a new account with the same name, provided that the account name is not in use. 因此,建议不要在删除帐户后重新创建它。So, we recommend that you don't re-create the account after deleting it. 因为这样不仅会阻止还原数据使用相同的名称,还会难以确定正确还原帐户。Because it not only prevents the restored data to use the same name, but also makes discovering the right account to restore from difficult.

意外删除 Azure Cosmos 数据库后,我们可以还原整个数据库或该数据库中的容器子集。When you accidentally delete an Azure Cosmos database, we can restore the whole database or a subset of the containers within that database. 还可以跨数据库选择特定容器并将它们还原到新的 Azure Cosmos 帐户中。It is also possible to select specific containers across databases and restore them to a new Azure Cosmos account.

如果意外删除或修改了容器中的一个或多个项(即数据损坏情况),需要指定还原到的时间。When you accidentally delete or modify one or more items within a container (the data corruption case), you need to specify the time to restore to. 如果数据损坏,则时间很重要。Time is important if there is data corruption. 由于容器是实时的,所以备份仍在运行,因此如果超过了保持期(默认值为 8 小时),备份将被覆盖。Because the container is live, the backup is still running, so if you wait beyond the retention period (the default is eight hours) the backups would be overwritten. 若要防止备份被覆盖,请将帐户的备份保留期增加到至少七天。In order to prevent the backup from being overwritten, increase the backup retention for your account to at least seven days. 最好在发生数据损坏后的 8 小时内延长保留期。It's best to increase your retention within 8 hours from the data corruption.

如果意外删除或损坏了数据,则应在 8 小时内联系 Azure 支持,以便 Azure Cosmos DB 团队帮助你从备份中还原数据。If you have accidentally deleted or corrupted your data, you should contact Azure support within 8 hours so that the Azure Cosmos DB team can help you restore the data from the backups. 这样,Azure Cosmos DB 支持团队才有足够的时间来还原你的帐户。This way the Azure Cosmos DB support team will have enough time to restore your account.

备注

还原数据后,并非所有源功能或设置都会转移到还原的帐户。After you restore the data, not all the source capabilities or settings are carried over to the restored account. 以下设置不会转移到新帐户:The following settings are not carried over to the new account:

  • VNET 访问控制列表VNET access control lists
  • 存储过程、触发器和用户定义的函数Stored procedures, triggers and user-defined functions
  • 多区域设置Multi-region settings

如果在数据库级别预配吞吐量,那么在这种情况下,将对整个数据库,而不是单个容器进行备份和还原。If you provision throughput at the database level, the backup and restore process in this case happen at the entire database level, and not at the individual containers level. 在这种情况下,无法选择还原容器子集。In such cases, you can't select a subset of containers to restore.

管理自己的备份的选项Options to manage your own backups

通过 Azure Cosmos DB SQL API 帐户,还可采用以下某一方法维护备份:With Azure Cosmos DB SQL API accounts, you can also maintain your own backups by using one of the following approaches:

  • 使用 Azure 数据工厂定期将数据移至所选的存储。Use Azure Data Factory to move data periodically to a storage of your choice.

  • 使用 Azure Cosmos DB 更改源定期读取数据来进行完整备份或增量更改,并将其存储在自己的存储中。Use Azure Cosmos DB change feed to read data periodically for full backups or for incremental changes, and store it in your own storage.

还原后的操作Post-restore actions

数据还原的主要目标是恢复意外删除或修改的数据。The primary goal of the data restore is to recover the data that you have accidentally deleted or modified. 因此,建议先检查已还原数据,确保其中包含所需内容。So, we recommend that you first inspect the content of the recovered data to ensure it contains what you are expecting. 如果一切正常,则可以将数据迁移回主帐户。If everything looks good, you can migrate the data back to the primary account. 尽管可以使用已还原帐户作为新的活动帐户,但如果有生产工作负载则不建议这样做。Although it is possible to use the restored account as your new active account, it's not a recommended option if you have production workloads.

还原数据后,你会收到有关新帐户名(通常采用 <original-name>-restored1 格式)和帐户要还原到的时间的通知。After you restore the data, you get a notification about the name of the new account (it's typically in the format <original-name>-restored1) and the time when the account was restored to. 还原的帐户与原始帐户具有相同的预配吞吐量、索引策略,并且二者位于同一区域。The restored account will have the same provisioned throughput, indexing policies and it is in same region as the original account. 角色为订阅管理员或共同管理员的用户可以看到还原的帐户。A user who is the subscription admin or a co-admin can see the restored account.

将数据迁移到原始帐户Migrate data to the original account

可通过下述不同方式将数据迁移回原始帐户:The following are different ways to migrate data back to the original account:

建议在迁移数据之后立即删除容器或数据库。It is advised that you delete the container or database immediately after migrating the data. 如果不删除已还原的数据库或容器,它们将在请求单位、存储和流出量方面产生成本。If you don't delete the restored databases or containers, they will incur cost for request units, storage, and egress.

后续步骤Next steps

接下来可了解如何从 Azure Cosmos 帐户还原数据,或了解如何将数据迁移到 Azure Cosmos 帐户Next you can learn about how to restore data from an Azure Cosmos account or learn how to migrate data to an Azure Cosmos account