azure - 如何使用 Powershell 从 Microsoft Azure 恢复已删除的容器?

标签 azure powershell azure-container-service soft-delete recover

我正在尝试使用 Azure Powershell 将软删除的容器恢复到 Microsoft Azure 中的存储帐户中。

实际上在门户中我们可以手动执行此操作,但我没有找到使用 powershell 命令的解决方案,我只是通过将容器恢复到之前的时间找到了解决方案,因此它也恢复了软删除的 blob,但它仍然无法恢复软删除的容器。

最佳答案

我试图找到直接取消删除容器的方法,但似乎不存在。

有一个解决方法,使用 Powershell 调用 Rest API .

PUT https://myaccount.blob.core.windows.net/destinationcontainer?restype=container&comp=undelete

这是代码示例:

# login
Connect-AzAccount

# get accessToken
$resource = "https://storage.azure.com"
$context = [Microsoft.Azure.Commands.Common.Authentication.Abstractions.AzureRmProfileProvider]::Instance.Profile.DefaultContext
$accessToken = [Microsoft.Azure.Commands.Common.Authentication.AzureSession]::Instance.AuthenticationFactory.Authenticate($context.Account, $context.Environment, $context.Tenant.Id.ToString(), $null, [Microsoft.Azure.Commands.Common.Authentication.ShowDialog]::Never, $null, $resource).AccessToken

#request REST API
$uri = "{Request URI}"
Invoke-RestMethod -Method 'Put' -Uri $uri -Headers @{ Authorization = "Bearer " + $accessToken }

您需要添加Request Headers使其发挥作用。

关于azure - 如何使用 Powershell 从 Microsoft Azure 恢复已删除的容器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64823359/

相关文章:

azure - Azure Sql 数据库高级版是否允许超过 150GB 的数据库?

regex - 修剪或替换 PowerShell 字符串变量

包含二进制可执行文件的 Windows 批处理脚本

c# - Azure 函数通过具有输入数据存储绑定(bind)的队列触发

c# - 我的 Blazor 服务器应用程序在一台本地计算机上的 Azure B2c 登录中遇到空引用错误,但在另一台本地计算机上却没有,有什么想法吗?

powershell - 如何禁用短参数名称

azure - Kubernetes:无法从私有(private)容器注册表中提取镜像

azure - 如何从 GitLab 容器注册表将 Docker 容器部署到 Azure 应用服务

azure - 无法删除或创建 azure aks 实例

azure - AZ CLI 问题 - Github Actions 自托管运行程序