Compartilhar via

使用Azure CLI恢复Azure Files

Azure CLI提供了用于管理Azure资源的命令行体验。 这是生成自定义自动化以使用Azure资源的绝佳工具。 本文介绍如何使用 Azure CLI 从 Azure Backup 创建的还原点还原整个文件共享或特定文件。 还可以使用 Azure portalAzure PowerShellREST API2 还原Azure Files。

阅读完本文后,你将学习如何使用 Azure CLI 执行以下操作:

  • 查看Azure Files备份的还原点。
  • 还原完整Azure Files。
  • 还原单个文件或文件夹。

注意事项

若要了解 Azure Files支持的备份和还原方案、区域可用性和限制,请参阅 support matrix。 有关常见问题,请参阅 常见问题

先决条件

本文假定你已经有一个由 Azure Backup 备份的Azure Files。 如果没有,请参阅使用 CLI 备份Azure Files为文件共享配置备份。 本文将使用以下资源:

文件共享 存储帐户 区域 详细信息
azurefiles afsaccount ChinaNorth 使用 Azure Backup 备份的原始源
azurefiles1 afaccount1 ChinaNorth 用于备用位置恢复的目标源

可以使用类似的文件共享结构来尝试本文中所述的不同类型的还原。

为Azure CLI准备环境

  • 如果希望在本地运行 CLI 引用命令,install Azure CLI。 如果在 Windows 或 macOS 上运行,请考虑在 Docker 容器中运行Azure CLI。 有关详细信息,请参阅 如何在 Docker 容器中运行Azure CLI

    • 如果使用本地安装,请使用 az login 命令登录到Azure CLI。 若要完成身份验证过程,请遵循终端中显示的步骤。 有关其他登录选项,请参阅Azure CLI登录。

    • 出现提示时,请在首次使用时安装 Azure CLI 扩展。 有关扩展的详细信息,请参阅 使用 Azure CLI 的扩展。

    • 运行 az 版本查找已安装的版本和依赖库。 若要升级到最新版本,请运行 az upgrade

  • 本教程需要 2.0.18 或更高版本的Azure CLI。

获取 Azure Files 的恢复点

使用 az backup recoverypoint list cmdlet 列出备份文件共享的所有恢复点。

以下示例提取 azurefiles storage 帐户中文件共享的恢复点列表。

az backup recoverypoint list --vault-name azurefilesvault --resource-group azurefiles --container-name "StorageContainer;Storage;AzureFiles;afsaccount" --backup-management-type azurestorage --item-name "AzureFileShare;azurefiles" --workload-type azurefileshare --out table

还可以通过提供以下两个附加参数,使用容器和项的易记名称来运行之前的 cmdlet:

  • --backup-management-type:azurestorage
  • --workload-type:azurefileshare
az backup recoverypoint list --vault-name azurefilesvault --resource-group azurefiles --container-name afsaccount --backup-management-type azurestorage --item-name azurefiles --workload-type azurefileshare --out table

结果集是具有每个还原点的时间和一致性详细信息的恢复点列表。

Name                Time                        Consistency
------------------  -------------------------   --------------------
932887541532871865  2020-01-05T07:08:23+00:00   FileSystemConsistent
932885927361238054  2020-01-05T07:08:10+00:00   FileSystemConsistent
932879614553967772  2020-01-04T21:33:04+00:00   FileSystemConsistent

输出中的Name属性对应于可用作恢复操作中--rp-name参数值的还原点名称。

使用 Azure CLI 进行完全共享恢复

可以使用此还原选项在原始或备用位置还原完整的文件共享。

定义以下参数以执行还原操作:

  • -container-name:承载备份的原始文件共享的storage帐户的名称。 若要检索容器的名称或友好名称,请使用 az 备份容器列表命令。
  • --item-name:想要用于还原操作的已备份原始文件共享的名称。 若要检索备份项的名称或友好名称,请使用 az 备份项列表命令。

将完整共享还原到原始位置

还原到原始位置时,无需指定与目标相关的参数。 仅“解决冲突”必须提供。

以下示例使用将还原模式设置为 az backup restore restore-azurefileshareoriginallocation cmdlet 还原原始位置中的 azurefiles 文件共享。 您使用的是在获取 Azure 文件的恢复点中获取的恢复点932883129628959823:

az backup restore restore-azurefileshare --vault-name azurefilesvault --resource-group azurefiles --rp-name 932887541532871865   --container-name "StorageContainer;Storage;AzureFiles;afsaccount" --item-name "AzureFileShare;azurefiles" --restore-mode originallocation --resolve-conflict overwrite --out table
Name                                  ResourceGroup
------------------------------------  ---------------
6a27cc23-9283-4310-9c27-dcfb81b7b4bb  azurefiles

输出中的“Name”属性对应于备份服务为还原操作创建的作业的名称。 若要跟踪作业的状态,请使用 az backup job show 命令。

将完全共享还原到备用位置

可以使用此选项将文件共享还原到备用位置,并使原始文件共享保持原样。 为备用位置恢复指定以下参数:

  • --target-storage-account:用于还原备份内容的存储帐户。 目标存储帐户必须与保管库位于同一位置。
  • --target-file-share:目标存储帐户中的文件共享,备份内容将还原至此处。
  • --target-folder:文件共享中要将数据还原到的文件夹。 如果要将备份内容还原到根文件夹,请将目标文件夹值指定为空字符串。
  • “--resolve-conflict”:在与还原的数据发生冲突时,提供操作指引。 接受覆盖跳过

以下示例使用 `az backup restore restore-azurefileshare` 和恢复模式 `alternatelocation` 来将 `` 存储帐户中的 `azurefiles` 文件共享恢复为 `azurefiles1` 文件共享在 `afaccount1` 存储帐户中。

az backup restore restore-azurefileshare --vault-name azurefilesvault --resource-group azurefiles --rp-name 932883129628959823 --container-name "StorageContainer;Storage;AzureFiles;afsaccount" --item-name "AzureFileShare;azurefiles" --restore-mode alternatelocation --target-storage-account afaccount1 --target-file-share azurefiles1 --target-folder restoredata --resolve-conflict overwrite --out table
Name                                  ResourceGroup
------------------------------------  ---------------
babeb61c-d73d-4b91-9830-b8bfa83c349a  azurefiles

输出中的“Name”属性对应于备份服务为还原操作创建的作业的名称。 若要跟踪作业的状态,请使用 az backup job show cmdlet。

项目级恢复

可以使用此还原选项来还原原始或备用位置中的单个文件或文件夹。

定义以下参数以执行还原操作:

  • -container-name:承载备份的原始文件共享的storage帐户的名称。 若要检索容器的名称或友好名称,请使用 az 备份容器列表命令。
  • --item-name:想要用于还原操作的已备份原始文件共享的名称。 若要检索备份项的名称或友好名称,请使用 az 备份项列表命令。

为想要恢复的项指定以下参数:

  • SourceFilePath:文件共享中要还原的文件的绝对路径(字符串格式)。 此路径与 az storage 文件下载az storage 文件 show CLI 命令中使用的路径相同。
  • “SourceFileType”:选择是否已选择目录或文件。 接受目录文件
  • ResolveConflict:与还原的数据发生冲突时的指示。 接受覆盖跳过

将单个文件或文件夹还原到原始位置

使用设置为 az backup restore restore-azurefiles 的还原模式的 originallocation cmdlet,将特定文件或文件夹还原到其原始位置。

下面的示例将“RestoreTest.txt”文件还原到其原始位置: 文件共享。azurefiles

az backup restore restore-azurefiles --vault-name azurefilesvault --resource-group azurefiles --rp-name 932881556234035474 --container-name "StorageContainer;Storage;AzureFiles;afsaccount" --item-name "AzureFileShare;azurefiles" --restore-mode originallocation  --source-file-type file --source-file-path "Restore/RestoreTest.txt" --resolve-conflict overwrite  --out table
Name                                  ResourceGroup
------------------------------------  ---------------
df4d9024-0dcb-4edc-bf8c-0a3d18a25319  azurefiles

输出中的“Name”属性对应于备份服务为还原操作创建的作业的名称。 若要跟踪作业的状态,请使用 az backup job show cmdlet。

将单个文件或文件夹还原到备用位置

若要将特定文件或文件夹还原到备用位置,请使用将还原模式设置为 az backup restore restore-azurefilesalternatelocation cmdlet 并指定以下与目标相关的参数:

  • --target-storage-account:用于还原备份内容的存储帐户。 目标存储帐户必须与保管库位于同一位置。
  • --target-file-share:目标存储帐户中的文件共享,备份内容将还原至此处。
  • --target-folder:文件共享中要将数据还原到的文件夹。 如果要将备份内容还原到根文件夹,请将目标文件夹的值指定为空字符串。

以下示例将最初存在于 文件共享中的 azurefiles 文件还原到备用位置:restoredata 文件夹中 azurefiles1 文件共享托管在 afaccount1 storage 帐户中。

az backup restore restore-azurefiles --vault-name azurefilesvault --resource-group azurefiles --rp-name 932881556234035474 --container-name "StorageContainer;Storage;AzureFiles;afsaccount" --item-name "AzureFileShare;azurefiles" --restore-mode alternatelocation --target-storage-account afaccount1 --target-file-share azurefiles1 --target-folder restoredata --resolve-conflict overwrite --source-file-type file --source-file-path "Restore/RestoreTest.txt" --out table
Name                                  ResourceGroup
------------------------------------  ---------------
df4d9024-0dcb-4edc-bf8c-0a3d18a25319  azurefiles

输出中的“Name”属性对应于备份服务为还原操作创建的作业的名称。 若要跟踪作业的状态,请使用 az backup job show cmdlet。

将多个文件或文件夹还原到原始或备用位置

若要为多个项执行还原,请传递“source-file-path”参数的值作为想要还原的所有文件或文件夹的“space separated”路径。

下面的示例将“Restore.txt”和“AFS testing Report.docx”文件还原到其原始位置。

az backup restore restore-azurefiles --vault-name azurefilesvault --resource-group azurefiles --rp-name 932889937058317910 --container-name "StorageContainer;Storage;AzureFiles;afsaccount" --item-name "AzureFileShare;azurefiles" --restore-mode originallocation  --source-file-type file --source-file-path "Restore Test.txt" "AFS Testing Report.docx" --resolve-conflict overwrite  --out table

输出将如下所示:

Name                                          ResourceGroup
------------------------------------          ---------------
649b0c14-4a94-4945-995a-19e2aace0305          azurefiles

输出中的“Name”属性对应于备份服务为还原操作创建的作业的名称。 若要跟踪作业的状态,请使用 az backup job show cmdlet。

如果想要将多个项还原到备用位置,请通过指定与目标相关的参数来使用上面的命令,如将单个文件或文件夹还原到备用位置部分所述。

后续步骤

使用 Azure portalAzure PowerShellAzure CLIREST API 管理Azure Files备份。