通过递增快照备份 Azure 非托管 VM 磁盘Back up Azure unmanaged VM disks with incremental snapshots

概述Overview

Azure 存储提供创建 Blob 快照的功能。Azure Storage provides the capability to take snapshots of blobs. 快照将捕获该时间点的 Blob 状态。Snapshots capture the blob state at that point in time. 本文介绍有关如何使用快照维护虚拟机磁盘备份的方案。In this article, we describe a scenario in which you can maintain backups of virtual machine disks using snapshots. 如果选择不使用 Azure 备份和恢复服务,但想要为虚拟机磁盘创建自定义备份策略,则可以使用此方法。You can use this methodology when you choose not to use Azure Backup and Recovery Service, and wish to create a custom backup strategy for your virtual machine disks. 对于运行业务或任务关键型工作负载的虚拟机,建议使用 Azure 备份作为备份策略的一部分。For virtual machines running business or mission critical workloads, it's recommended to use Azure Backup as part of the backup strategy.

Azure 虚拟机磁盘在 Azure 存储中存储为页 Blob。Azure virtual machine disks are stored as page blobs in Azure Storage. 本文介绍的是虚拟机磁盘的备份策略,因此,我们指的是页 Blob 上下文中的快照。Since we are describing a backup strategy for virtual machine disks in this article, we refer to snapshots in the context of page blobs. 若要详细了解快照,请参阅 创建 Blob 的快照To learn more about snapshots, refer to Creating a Snapshot of a Blob.

什么是快照?What is a snapshot?

Blob 快照是在某个时间点捕获的 Blob 只读版本。A blob snapshot is a read-only version of a blob that is captured at a point in time. 在创建快照后,可以读取、复制或删除该快照,但无法对其进行修改。Once a snapshot has been created, it can be read, copied, or deleted, but not modified. 利用快照,可以在某个时间点备份显示的 Blob。Snapshots provide a way to back up a blob as it appears at a moment in time. 在 REST 2015-04-05 版之前,可以复制完整快照。Until REST version 2015-04-05, you had the ability to copy full snapshots. 使用 REST 2015-07-08 版或更高版本,还可以复制增量快照。With the REST version 2015-07-08 and above, you can also copy incremental snapshots.

完整快照复制Full snapshot copy

可将快照作为 Blob 复制到另一个存储帐户,以保留基本 Blob 的备份。Snapshots can be copied to another storage account as a blob to keep backups of the base blob. 你还可以复制快照覆盖基本 Blob,这类似于将 Blob 还原到以前的版本。You can also copy a snapshot over its base blob, which is like restoring the blob to an earlier version. 将快照从某个存储帐户复制到另一个存储帐户时,将占用与基本页 Blob 相同的空间。When a snapshot is copied from one storage account to another, it occupies the same space as the base page blob. 因此,将整个快照从某个存储帐户复制到另一个存储帐户时速度较慢,并且会消耗目标存储帐户中的大量空间。Therefore, copying whole snapshots from one storage account to another is slow and consumes much space in the target storage account.

备注

如果将基本 Blob 复制到另一个目标,则不会一起复制 Blob 的快照。If you copy the base blob to another destination, the snapshots of the blob are not copied along with it. 同样,如果使用副本覆盖基本 Blob,与基本 Blob 关联的快照不会受到影响,并且可让基本 Blob 名称保持不变。Similarly, if you overwrite a base blob with a copy, snapshots associated with the base blob are not affected and stay intact under the base blob name.

使用快照备份磁盘Back up disks using snapshots

作为虚拟机磁盘的备份策略,可以创建磁盘或页 Blob 的定期快照,并使用复制 Blob 操作或 AzCopy 之类的工具将其复制到另一个存储帐户。As a backup strategy for your virtual machine disks, you can take periodic snapshots of the disk or page blob, and copy them to another storage account using tools like Copy Blob operation or AzCopy. 可将快照复制到具有不同名称的目标页 Blob。You can copy a snapshot to a destination page blob with a different name. 生成的目标页 Blob 是可编写的页 Blob,而不是快照。The resulting destination page blob is a writeable page blob and not a snapshot. 本文稍后介绍使用快照创建虚拟机磁盘备份的步骤。Later in this article, we describe steps to take backups of virtual machine disks using snapshots.

使用快照还原磁盘Restore disks using snapshots

需要将磁盘还原到以前在某个备份快照中捕获的稳定版本时,可以复制一个快照来覆盖基本页 Blob。When it is time to restore your disk to a stable version that was previously captured in one of the backup snapshots, you can copy a snapshot over the base page blob. 将快照升级到基本页 Blob 之后,快照会保留,但会使用可读写的副本覆盖其源。After the snapshot is promoted to the base page blob, the snapshot remains, but its source is overwritten with a copy that can be both read and written. 本文稍后介绍从快照还原旧版磁盘的步骤。Later in this article we describe steps to restore a previous version of your disk from its snapshot.

实现完整快照复制Implementing full snapshot copy

可以通过执行以下操作实现完整快照复制:You can implement a full snapshot copy by doing the following,

  • 首先,使用 快照 Blob 操作创建基本 Blob 的快照。First, take a snapshot of the base blob using the Snapshot Blob operation.
  • 然后,使用复制 Blob 将快照复制到目标存储帐户。Then, copy the snapshot to a target storage account using Copy Blob.
  • 重复此过程以保留基本 Blob 的备份副本。Repeat this process to maintain backup copies of your base blob.

增量快照复制Incremental snapshot copy

GetPageRanges API 中的新功能提供更好的方式来备份页 Blob 或磁盘的快照。The new feature in the GetPageRanges API provides a much better way to back up the snapshots of your page blobs or disks. 此 API 返回在基 blob 和快照之间所做更改的列表,从而减少了在备份帐户上使用的存储空间量。The API returns the list of changes between the base blob and the snapshots, which reduces the amount of storage space used on the backup account. 该 API 支持高级存储以及标准存储的页 Blob。The API supports page blobs on Premium Storage as well as Standard Storage. 可以使用此 API 为 Azure VM 构建更快速有效的备份解决方案。Using this API, you can build faster and more efficient backup solutions for Azure VMs. 此 API 适用于 REST 2015-07-08 和更高版本。This API will be available with the REST version 2015-07-08 and higher.

增量快照复制可让你将以下两者之间的差异从一个存储帐户复制到另一个存储帐户:Incremental Snapshot Copy allows you to copy from one storage account to another the difference between,

  • 基本 Blob 及其快照,或Base blob and its Snapshot OR
  • 基本 Blob 的任意两个快照Any two snapshots of the base blob

必须符合以下先决条件:Provided the following conditions are met,

  • Blob 是在 2016 年 1 月 1 日或之后创建。The blob was created on Jan-1-2016 or later.
  • 未在两个快照之间使用 PutPage复制 Blob 覆盖 Blob。The blob was not overwritten with PutPage or Copy Blob between two snapshots.

备注

此功能适用于高级和标准 Azure 页 Blob。This feature is available for Premium and Standard Azure Page Blobs.

如果存在使用快照的自定义备份策略,则将快照从一个存储帐户复制到另一个存储帐户可能会慢,并且将消耗大量的存储空间。When you have a custom backup strategy using snapshots, copying the snapshots from one storage account to another can be slow and can consume much storage space. 可以将连续快照之间的差异写入备份页 Blob,而不是将整个快照复制到备份存储帐户。Instead of copying the entire snapshot to a backup storage account, you can write the difference between consecutive snapshots to a backup page blob. 这样,便可以大量减少复制的时间和存储备份的空间。This way, the time to copy and the space to store backups is substantially reduced.

实现增量快照复制Implementing Incremental Snapshot Copy

可以通过执行以下操作实现增量快照复制:You can implement incremental snapshot copy by doing the following,

  • 使用 快照 Blob创建基本 Blob 的快照。Take a snapshot of the base blob using Snapshot Blob.
  • 使用复制 Blob 将快照复制到相同区域或任何其他 Azure 区域中的目标备份存储帐户。Copy the snapshot to the target backup storage account in same or any other Azure region using Copy Blob. 这是备份页 Blob。This is the backup page blob. 创建备份页 Blob 的快照,并将其存储在备份帐户中。Take a snapshot of the backup page blob and store it in the backup account.
  • 使用快照 Blob 创建基本 Blob 的另一个快照。Take another snapshot of the base blob using Snapshot Blob.
  • 使用 GetPageRanges 获取基本 Blob 的第一个与第二个快照之间的差异。Get the difference between the first and second snapshots of the base blob using GetPageRanges. 使用新参数 prevsnapshot 指定要用于获取差异的快照的 DateTime 值。Use the new parameter prevsnapshot, to specify the DateTime value of the snapshot you want to get the difference with. 如果提供此参数,则 REST 响应只包含在目标快照与先前快照之间更改的页面(包括清除页面)。When this parameter is present, the REST response includes only the pages that were changed between target snapshot and previous snapshot including clear pages.
  • 使用 PutPage 将这些更改应用到备份页 Blob。Use PutPage to apply these changes to the backup page blob.
  • 最后,创建备份页 Blob 的快照,并将其存储在备份存储帐户中。Finally, take a snapshot of the backup page blob and store it in the backup storage account.

下一部分详细说明如何使用增量快照复制维护磁盘的备份In the next section, we will describe in more detail how you can maintain backups of disks using Incremental Snapshot Copy

方案Scenario

在本部分中,我们介绍一种方案,它涉及到使用快照针对虚拟机磁盘实施自定义的备份策略。In this section, we describe a scenario that involves a custom backup strategy for virtual machine disks using snapshots.

假设在某个 DS 系列 Azure VM 上附加了一个高级存储 P30 磁盘。Consider a DS-series Azure VM with a premium storage P30 disk attached. 名为 mypremiumdisk 的 P30 磁盘存储在名为 mypremiumaccount 的高级存储帐户中。The P30 disk called mypremiumdisk is stored in a premium storage account called mypremiumaccount. 名为 mybackupstdaccount 的标准存储帐户用于存储 mypremiumdisk 的备份。A standard storage account called mybackupstdaccount is used for storing the backup of mypremiumdisk. 我们希望每隔 12 小时保留 mypremiumdisk 的一个快照。We would like to keep a snapshot of mypremiumdisk every 12 hours.

要了解如何创建存储帐户,请参阅创建存储帐户To learn about creating a storage account, see Create a storage account.

若要了解如何备份 Azure VM,请参阅规划 Azure VM 备份To learn about backing up Azure VMs, refer to Plan Azure VM backups.

使用增量快照维护磁盘备份的步骤Steps to maintain backups of a disk using incremental snapshots

下述步骤介绍如何创建 mypremiumdisk 的快照,并在 mybackupstdaccount 中维护备份。The following steps describe how to take snapshots of mypremiumdisk and maintain the backups in mybackupstdaccount. 备份是名为 mybackupstdpageblob 的标准页 Blob。The backup is a standard page blob called mybackupstdpageblob. 备份页 Blob 始终反映与 mypremiumdisk 的最新快照相同的状态。The backup page blob always reflects the same state as the last snapshot of mypremiumdisk.

  1. 为高级存储磁盘创建备份页 blob,方法是拍摄名为 mypremiumdisk_ss1 的 mypremiumdisk 的快照。 Create the backup page blob for your premium storage disk, by taking a snapshot of mypremiumdisk called mypremiumdisk_ss1.
  2. 将此快照复制到 mybackupstdaccount,用作名为 mybackupstdpageblob 的页 Blob。Copy this snapshot to mybackupstdaccount as a page blob called mybackupstdpageblob.
  3. 使用创建 Blob 快照mybackupstdpageblob 创建名为 mybackupstdpageblob_ss1 的快照,并将其存储在 mybackupstdaccount 中。Take a snapshot of mybackupstdpageblob called mybackupstdpageblob_ss1, using Snapshot Blob and store it in mybackupstdaccount.
  4. 在备份时段内,创建 mypremiumdisk 的另一个快照(即 mypremiumdisk_ss2),并将其存储在 mypremiumaccount 中。During the backup window, create another snapshot of mypremiumdisk, say mypremiumdisk_ss2, and store it in mypremiumaccount.
  5. prevsnapshot 参数设置为 mypremiumdisk_ss1 时间戳的情况下,在 mypremiumdisk_ss2 使用 GetPageRanges 获取两个快照(mypremiumdisk_ss2 与 mypremiumdisk_ss1 )之间的增量更改。Get the incremental changes between the two snapshots, mypremiumdisk_ss2 and mypremiumdisk_ss1, using GetPageRanges on mypremiumdisk_ss2 with the prevsnapshot parameter set to the timestamp of mypremiumdisk_ss1. 将这些增量更改写入到 mybackupstdaccount 中的备份页 Blob mybackupstdpageblobWrite these incremental changes to the backup page blob mybackupstdpageblob in mybackupstdaccount. 如果增量更改中有已删除的范围,则必须从备份页 Blob 中清除这些范围。If there are deleted ranges in the incremental changes, they must be cleared from the backup page blob. 使用 PutPage 将增量更改写入备份页 Blob。Use PutPage to write incremental changes to the backup page blob.
  6. 为备份页 blob mybackupstdpageblob 创建名为 mybackupstdpageblob_ss2 的快照。Take a snapshot of the backup page blob mybackupstdpageblob, called mybackupstdpageblob_ss2. 从高级存储帐户删除以前的快照 mypremiumdisk_ss1Delete the previous snapshot mypremiumdisk_ss1 from premium storage account.
  7. 在每个备份时段内重复步骤 4-6。Repeat steps 4-6 every backup window. 这样,即可在标准存储帐户中维护 mypremiumdisk 的备份。In this way, you can maintain backups of mypremiumdisk in a standard storage account.

使用增量快照备份磁盘

从快照还原磁盘的步骤Steps to restore a disk from snapshots

下述步骤介绍如何将高级磁盘 mypremiumdisk 从备份存储帐户 mybackupstdaccount 还原到以前的快照。The following steps, describe how to restore the premium disk, mypremiumdisk to an earlier snapshot from the backup storage account mybackupstdaccount.

  1. 确定要将高级磁盘还原到的时间点。Identify the point in time that you wish to restore the premium disk to. 假设这是存储在备份存储帐户 mybackupstdaccount 中的快照 mybackupstdpageblob_ss2 。Let's say that it is snapshot mybackupstdpageblob_ss2, which is stored in the backup storage account mybackupstdaccount.
  2. 在 mybackupstdaccount 中,将快照 mybackupstdpageblob_ss2 升级为新的备份基本页 Blob mybackupstdpageblobrestoredIn mybackupstdaccount, promote the snapshot mybackupstdpageblob_ss2 as the new backup base page blob mybackupstdpageblobrestored.
  3. 为此已还原的备份页 Blob 创建名为 mybackupstdpageblobrestored_ss1 的快照。Take a snapshot of this restored backup page blob, called mybackupstdpageblobrestored_ss1.
  4. 将已还原页 Blob mybackupstdpageblobrestoredmybackupstdaccount 复制到 mypremiumaccount,作为新的高级磁盘 mypremiumdiskrestoredCopy the restored page blob mybackupstdpageblobrestored from mybackupstdaccount to mypremiumaccount as the new premium disk mypremiumdiskrestored.
  5. mypremiumdiskrestored 创建名为 mypremiumdiskrestored_ss1 的快照,以便将来执行增量备份。Take a snapshot of mypremiumdiskrestored, called mypremiumdiskrestored_ss1 for making future incremental backups.
  6. 将 DS 系列 VM 指向已还原的磁盘 mypremiumdiskrestored,并从 VM 分离旧的 mypremiumdiskPoint the DS series VM to the restored disk mypremiumdiskrestored and detach the old mypremiumdisk from the VM.
  7. 使用 mybackupstdpageblobrestored 作为备份页 Blob,根据前一部分中所述,开始针对已还原的磁盘 mypremiumdiskrestored 执行备份过程。Begin the Backup process described in previous section for the restored disk mypremiumdiskrestored, using the mybackupstdpageblobrestored as the backup page blob.

从快照还原磁盘

后续步骤Next Steps

使用以下链接详细了解如何创建 Blob 的快照和规划 VM 备份基础结构。Use the following links to learn more about creating snapshots of a blob and planning your VM backup infrastructure.