为什么 Azure VM 快照复制到 Azure 中的存储帐户时大小为 0 字节?

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

我制作了虚拟机的快照并复制到存储帐户,但它的大小为 0 字节

我使用以下方式复制到存储帐户:

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

问题是它的大小是0字节

azure azure-virtual-machine
1个回答
0
投票

我已经尝试过了。问题是复制到存储总是显示“失败”,而且我不知道什么时候成功。我需要循环状态检查直到“成功”吗?

可以使用下面的脚本,直到复制状态成功;它将在您的环境中运行。

脚本:

resourceGroupName="xxxx"
snapshotName="xxx"
sasExpiryDuration=3600
storageAccountName="venkat123"
storageContainerName="test"
storageAccountKey="MnvIVSoYytjs0HEREfTatdvBIRnoYUC2ZJVyIDNqDaBk+Mb/2+QGn50A/sfw0k8yMJad+G9+SrsS+AStxf+aMQ=="
destinationVHDFileName="abcd.vhd"


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

# Copy snapshot to Azure Storage
copyId=$(az storage blob copy start --account-name $storageAccountName --destination-blob $destinationVHDFileName --destination-container $storageContainerName --account-key $storageAccountKey --source-uri $sas --query id --output tsv)

# Check status of blob copy operation
status=$(az storage blob show --account-name $storageAccountName --container-name $storageContainerName --name $destinationVHDFileName --query properties.copy.status -o tsv --account-key $storageAccountKey)

# Wait for blob copy operation to complete
while [ "$status" != "success" ]
do
    echo "Blob copy operation status: $status"
    sleep 10
    status=$(az storage blob show --account-name $storageAccountName --container-name $storageContainerName --name $destinationVHDFileName --query properties.copy.status -o tsv --account-key $storageAccountKey)
done

echo "Blob copy operation completed successfully."

上面的脚本会一直执行,直到状态复制成功。

输出:

Blob copy operation completed successfully.

enter image description here

但是,我建议你使用

azcopy
,因为它更快。

脚本:

resourceGroupName="v-vsettu-mindtree"
snapshotName="snap1"
sasExpiryDuration=3600
storageAccountName="venkat123"
storageContainerName="test"
storageAccountKey="MnvIVSoYytjs0HEREfTatdvBIRnoYUC2ZJVyIDNqDaBk+Mb/2+QGn50A/sfw0k8yMJad+G9+SrsS+AStxf+aMQ=="
destinationVHDFileName="abcd.vhd"
sastoken="sv=2022-11-02&ss=bfqt&srt=co&sp=rwdlacupiytfx&se=2024-04-12T13:18:23Z&st=2024-04-12T05:18:23Z&spr=https&sig=nt0kh7MMc7dciYbGAYzF9nv5Z1XFR%2B4ARKxYr%2BmssUY%3D"

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

# Copy snapshot to Azure Storage using AzCopy
azcopy copy $sas "https://$storageAccountName.blob.core.windows.net/$storageContainerName/$destinationVHDFileName?$sastoken" --recursive=true 

echo "Blob copy operation completed successfully."

输出:

INFO: Scanning...
INFO: azcopy: A newer version 10.24.0 is available to download

INFO: Any empty folders will not be processed, because the source and/or destination don't have full folder support

Job b51597xxxxd285b354 has started
Log file is located at: /home/venkatesan/.azcopy/b51xxxxx4b-58ed-c63bd285b354.log

93.3 %, 0 Done, 0 Failed, 1 Pending, 0 Skipped, 1 Total, 2-sec Throughput (Mb/s): 3723.9013


Job b515970f-58b1-164b-58ed-c63bd285b354 summary
Elapsed Time (Minutes): 0.2335
Number of File Transfers: 1
Number of Folder Property Transfers: 0
Total Number of Transfers: 1
Number of Transfers Completed: 1
Number of Transfers Failed: 0
Number of Transfers Skipped: 0
TotalBytesTransferred: xxxx
Final Job Status: Completed

Blob copy operation completed successfully.

enter image description here

复制到 Blob 存储后,您可以使用相同的 azcopy 下载到本地环境。

命令:

azcopy copy "https://$storageAccountName.blob.core.windows.net/$storageContainerName/$destinationVHDFileName?$sastoken"  "C:\demo\abcd.vhd" --recursive=true 

它将下载到您的本地环境。

参考:

azcopy 复制 |微软学习

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