您现在访问的是微软AZURE全球版技术文档网站,若需要访问由世纪互联运营的MICROSOFT AZURE中国区技术文档网站,请访问 https://docs.azure.cn.

教程:在 Azure 中备份和还原 Windows 虚拟机的文件Tutorial: Back up and restore files for Windows virtual machines in Azure

可以通过定期创建备份来保护数据。You can protect your data by taking backups at regular intervals. Azure 备份可创建恢复点,这些恢复点存储在异地冗余的恢复保管库中。Azure Backup creates recovery points that are stored in geo-redundant recovery vaults. 从恢复点还原时,可以还原整个 VM,也可以仅还原特定的文件。When you restore from a recovery point, you can restore the whole VM or specific files. 本文介绍了如何将单个文件还原到运行 Windows Server 和 IIS 的 VM。This article explains how to restore a single file to a VM running Windows Server and IIS. 如果尚没有 VM 可使用,可以参考 Windows 快速入门创建一个 VM。If you don't already have a VM to use, you can create one using the Windows quickstart. 本教程介绍如何执行下列操作:In this tutorial you learn how to:

  • 创建 VM 的备份Create a backup of a VM
  • 计划每日备份Schedule a daily backup
  • 从备份还原文件Restore a file from a backup

备份概述Backup overview

当 Azure 备份服务启动备份作业时,将触发备份扩展来创建时间点快照。When the Azure Backup service initiates a backup job, it triggers the backup extension to take a point-in-time snapshot. Azure 备份服务使用 VMSnapshot 扩展。The Azure Backup service uses the VMSnapshot extension. 该扩展是在首次 VM 备份(如果 VM 正在运行)期间安装的。The extension is installed during the first VM backup if the VM is running. 如果 VM 未运行,备份服务将创建基础存储的快照(因为在 VM 停止时不会发生任何应用程序写入)。If the VM is not running, the Backup service takes a snapshot of the underlying storage (since no application writes occur while the VM is stopped).

创建 Windows VM 快照时,备份服务与卷影复制服务 (VSS) 互相配合,来获取虚拟机磁盘的一致性快照。When taking a snapshot of Windows VMs, the Backup service coordinates with the Volume Shadow Copy Service (VSS) to get a consistent snapshot of the virtual machine's disks. Azure 备份服务创建快照后,数据将传输到保管库。Once the Azure Backup service takes the snapshot, the data is transferred to the vault. 为最大限度地提高效率,服务仅标识和传输自上次备份以后已更改的数据块。To maximize efficiency, the service identifies and transfers only the blocks of data that have changed since the previous backup.

数据传输完成后,会删除快照并创建恢复点。When the data transfer is complete, the snapshot is removed and a recovery point is created.

创建备份Create a backup

在恢复服务保管库中创建一个简单的已计划每日备份。Create a simple scheduled daily backup to a Recovery Services Vault.

  1. 登录到 Azure 门户Sign in to the Azure portal.
  2. 在左侧菜单中选择“虚拟机”。In the menu on the left, select Virtual machines.
  3. 从列表中选择要备份的 VM。From the list, select a VM to back up.
  4. 在 VM 边栏选项卡上的“设置”部分中,单击“备份”。On the VM blade, in the Settings section, click Backup. 此时会打开“启用备份”边栏选项卡。The Enable backup blade opens.
  5. 在“恢复服务保管库”中,单击“新建”并为新保管库提供名称。In Recovery Services vault, click Create new and provide the name for the new vault. 将在与虚拟机相同的资源组和位置中创建新保管库。A new vault is created in the same Resource Group and location as the virtual machine.
  6. 单击“备份策略”。Click Backup policy. 对于本示例,请保留默认值,并单击“确定”。For this example, keep the defaults and click OK.
  7. 在“启用备份”边栏选项卡中,单击“启用备份”。On the Enable backup blade, click Enable Backup. 这会根据默认的计划创建每日备份。This creates a daily backup based on the default schedule.
  8. 若要创建初始恢复点,请在“备份”边栏选项卡中单击“立即备份”。To create an initial recovery point, on the Backup blade click Backup now.
  9. 在“立即备份”边栏选项卡中单击日历图标,使用日历控件选择保留此恢复点的最后一天,并单击“备份”。On the Backup Now blade, click the calendar icon, use the calendar control to select the last day this recovery point is retained, and click Backup.
  10. 在 VM 的“备份”边栏选项卡中,可以看到已完成的恢复点数。In the Backup blade for your VM, you see the number of recovery points that are complete.

    恢复点

首次备份大约需要 20 分钟。The first backup takes about 20 minutes. 完成备份后,请继续执行本教程的下一部分。Proceed to the next part of this tutorial after your backup is finished.

恢复文件Recover a file

如果意外删除或更改了某个文件,可以使用文件恢复从备份保管库恢复该文件。If you accidentally delete or make changes to a file, you can use File Recovery to recover the file from your backup vault. 文件恢复使用一个在 VM 上运行的脚本将恢复点装载为本地驱动器。File Recovery uses a script that runs on the VM, to mount the recovery point as local drive. 这些驱动器会保持装载 12 小时,以便可以从恢复点复制文件并将其还原到 VM。These drives remain mounted for 12 hours so that you can copy files from the recovery point and restore them to the VM.

本示例展示了如何恢复在 IIS 的默认网页中使用的图像文件。In this example, we show how to recover the image file that is used in the default web page for IIS.

  1. 打开浏览器,并连接到 VM 的 IP 地址来显示默认 IIS 页面。Open a browser and connect to the IP address of the VM to show the default IIS page.

    默认 IIS 网页

  2. 连接到 VM。Connect to the VM.

  3. 在 VM 上,打开文件资源管理器并导航到 \inetpub\wwwroot and delete the file iisstart.pngOn the VM, open File Explorer and navigate to \inetpub\wwwroot and delete the file iisstart.png.
  4. 在本地计算机上,刷新浏览器,检查默认 IIS 页面上的图像是否已消失。On your local computer, refresh the browser to see that the image on the default IIS page is gone.

    默认 IIS 网页

  5. 在本地计算机上,打开一个新选项卡,并转到 Azure 门户On your local computer, open a new tab and go the Azure portal.

  6. 在左侧菜单中,选择“虚拟机”,并从列表中选择 VM。In the menu on the left, select Virtual machines and select the VM from the list.
  7. 在 VM 边栏选项卡上的“设置”部分中,单击“备份”。On the VM blade, in the Settings section, click Backup. 此时会打开“备份”边栏选项卡。The Backup blade opens.
  8. 在边栏选项卡顶部的菜单中,选择“文件恢复”。In the menu at the top of the blade, select File Recovery. 此时会打开“文件恢复”边栏选项卡。The File Recovery blade opens.
  9. 在“步骤 1: 选择恢复点”中,从下拉列表中选择恢复点。In Step 1: Select recovery point, select a recovery point from the drop-down.
  10. 在“步骤 2: 下载脚本以浏览并恢复文件”中,单击“下载可执行文件”按钮。In Step 2: Download script to browse and recover files, click the Download Executable button. 将文件保存到下载文件夹。Save the file to your Downloads folder.
  11. 在本地计算机上,打开文件资源管理器,导航到下载文件夹并复制所下载的 .exe 文件。On your local computer, open File Explorer and navigate to your Downloads folder and copy the downloaded .exe file. 该文件名以 VM 名称作为前缀。The filename is prefixed by your VM name.
  12. 在 VM 上(通过 RDP 连接),将该 .exe 文件粘贴到 VM 的桌面。On your VM (over the RDP connection) paste the .exe file to the Desktop of your VM.
  13. 导航到 VM 的桌面并双击该 .exe 文件。Navigate to the desktop of your VM and double-click on the .exe. 这会启动一个命令提示符,然后将恢复点装载为可以访问的文件共享。This launches a command prompt and then mount the recovery point as a file share that you can access. 完成该共享创建时,键入 q 以关闭命令提示符。When it is finished creating the share, type q to close the command prompt.
  14. 在 VM 上,打开文件资源管理器,导航到用于该文件共享的驱动器号。On your VM, open File Explorer and navigate to the drive letter that was used for the file share.
  15. 导航到 \inetpub\wwwroot,从文件共享中复制 iisstart.png 并将其粘贴到 \inetpub\wwwroot 中。Navigate to \inetpub\wwwroot and copy iisstart.png from the file share and paste it into \inetpub\wwwroot. 例如,复制 F:\inetpub\wwwroot\iisstart.png 并将其粘贴到 c:\inetpub\wwwroot 中以恢复该文件。For example, copy F:\inetpub\wwwroot\iisstart.png and paste it into c:\inetpub\wwwroot to recover the file.
  16. 在本地计算机上,打开从中连接到 VM 的 IP 地址的浏览器选项卡,其中显示了 IIS 默认页面。On your local computer, open the browser tab where you are connected to the IP address of the VM showing the IIS default page. 按 CTRL + F5 刷新浏览器页面。Press CTRL + F5 to refresh the browser page. 现在,应该会看到图像已还原。You should now see that the image has been restored.
  17. 在本地计算机上,返回到 Azure 门户的浏览器选项卡,并在“步骤 3: 恢复后卸载磁盘”中单击“卸载磁盘”按钮。On your local computer, go back to the browser tab for the Azure portal and in Step 3: Unmount the disks after recovery click the Unmount Disks button. 如果忘记执行此步骤,与装入点的连接会在 12 小时后自动关闭。If you forget to do this step, the connection to the mountpoint is automatically close after 12 hours. 在这 12 个小时后,若要创建新的装入点,需要下载新脚本。After those 12 hours, you need to download a new script to create a new mountpoint.

后续步骤Next steps

本教程介绍了如何:In this tutorial, you learned how to:

  • 创建 VM 的备份Create a backup of a VM
  • 计划每日备份Schedule a daily backup
  • 从备份还原文件Restore a file from a backup

请转到下一教程,了解如何监视虚拟机。Advance to the next tutorial to learn about monitoring virtual machines.