如何将 Azure VM 快照复制到 Azure 存储?

问题描述 投票:0回答:1

我创建了一个 VM 快照并尝试将其复制到 Azure 存储,如下所示

subscriptionId="xxxx"
resourceGroupName="xxx" 
snapshotName="snap1"
sasExpiryDuration=3600
storageAccountName="testsa"
storageContainerName="test"
storageAccountKey="xxxx"
destinationVHDFileName="sample.vhd"

az account set --subscription $subscriptionId

sas=$(az snapshot grant-access --resource-group $resourceGroupName --name $snapshotName - 
-duration-in-seconds $sasExpiryDuration --query [accessSas] -o tsv)

az storage blob copy start --account-name $storageAccountName --destination-blob $destinationVHDFileName --destination-container $storageContainerName  --account-key $storageAccountKey --source-uri $sas

然后我尝试复制到本地电脑,如下所示:

 $filename=  'c:\snapshots\' + $snapshotName
 az storage blob download --container-name 'mycontainer' --name $snapshotName --file 
 $filename --account-name 'mystorageaccount' --account-key <my-key>

文件被复制到本地驱动器,但问题是大小为 0 字节。

为什么大小为 0 字节以及如何将快照复制到本地驱动器?

azure powershell azure-blob-storage virtual-machine
1个回答
0
投票

为什么大小为0字节,如何将快照复制到本地驱动器?

当快照未成功复制到您的存储帐户时,就会出现这种情况。

使用命令

az storage blob copy start
从快照复制到 Azure Blob 存储后,此命令需要一些时间才能从快照复制到 Azure Blob 存储。您需要使用以下命令验证它是否已被复制。 这是验证文件状态的命令:

命令:

az storage blob show --account-name "venkat123" --account-key "xxxx"  --container-name "test" --name "sample.vhd"

输出:

xxxx az storage blob show --account-name "venkat123" --account-key "xxxx"  --container-name "test" --name "sample.vhd"
{
"copy": {
      "completionTime": null,
      "destinationSnapshot": null,
      "id": "e4f1bcd7-8549-47c3-82f1-d49f32cc6dfb",
      "incrementalCopy": null,
      "progress": "32213303808/32213303808",
      "source": xxxx",
      "status": "success",
      "statusDescription": null
    }

enter image description here

现在,看到状态成功后,我在我的环境中运行相同的命令从blob下载到本地,它执行成功并下载成功。

命令:

$snapshotName="test.vhd"
$filename=  'C:\demo\' + $snapshotName
az storage blob download --container-name 'test' --name $snapshotName --file $filename --account-name 'venkat123' --account-key "Mxxxxx"

输出:

$snapshotName="xxx"
$filename=  'C:\demo\' + $snapshotName
az storage blob download --container-name 'test' --name $snapshotName --file $filename --account-name 'venkat123' --account-key "Mxxxxx" 
Finished[#############################################################]  100.0000% 
"copy": {
      "completionTime": null,
      "destinationSnapshot": null,
      "id": "1b9f4234-c276-4a26-8f87-de703c88fdb7",
      "incrementalCopy": null,
      "progress": "4294967808/4294967808",
      "source": "hxxxxxxx",
      "status": "success",
      "statusDescription": null
    },

enter image description here

对于较大的文件下载,我建议您参考azcopy命令。

文件:

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.