azure Python:如何使用start_copy_from_url API将数据从快照复制到磁盘

lg40wkob  于 2023-04-12  发布在  Python
关注(0)|答案(1)|浏览(97)

我在项目中使用Microsoft Azure SDK for Python。我想将数据从快照复制到磁盘。对于此任务,我使用快照的可读SASuri和磁盘的可写SASuri。
下面是我用来传输数据的例子。

blob_client = BlobClient.from_blob_url("https://<writable-SASUri-disk>")
copy_source_url = r"https://<readable-SASUri-snapshot>"
blob_client.start_copy_from_url(copy_source_url, metadata=None, incremental_copy=False,requires_sync=True)

我得到下面的错误:enter image description here
有什么办法解决这个问题吗?

pkwftd7m

pkwftd7m1#

我尝试使用下面的代码通过使用我的SAS URL使用blob客户端复制URL将我的快照复制到磁盘,但收到一个错误,限制如下:-
验证码:-

import asyncio
from azure.storage.blob import BlobClient

async def copy_snapshot_to_disk():
    # Create a BlobClient object for the writable SAS URI of the disk
    disk_client = BlobClient.from_blob_url("https://valleystrg.blob.core.windows.net/disk/abcd?sp=rw&st=2023-04-03T10:27:36Z&se=2023-04-03T18:27:36Z&spr=https&sv=2021-12-02&sr=b&sig=xxxxxxxxxxxxxxxxxxxxJtcei011QjEcoC7A%3D")
    # Create a BlobClient object for the readable SAS URI of the snapshot
    snapshot_client = BlobClient.from_blob_url("https://valleystrg.blob.core.windows.net/disk/abcd%20(1)?sp=r&st=2023-04-03T10:25:25Z&se=2023-04-03T18:25:25Z&spr=https&sv=2021-12-02&sr=b&sig=xxxxxtEQ3er2SSVWqshkiXJ8CEpn7s68O%2FOjm0%3D")

    # Start the copy operation from the snapshot to the disk
    headers = {"x-ms-copy-source": snapshot_client.url, "x-ms-copy-type": "blob"}
    copy_id = await disk_client.start_copy_from_url(snapshot_client.url, headers=headers, metadata=None, incremental_copy=False, requires_sync=True)

    # Wait for the copy operation to complete
    while True:
        properties = await disk_client.get_blob_properties()
        if properties.copy.status == "success":
            break
        await asyncio.sleep(1)

    # Print the copy operation result
    print("Copy operation status: ", properties.copy.status)

async def main():
    await copy_snapshot_to_disk()

loop = asyncio.get_event_loop()
loop.run_until_complete(main())

输出:

azure.core.exceptions.ResourceExistsError: **The source request body for synchronous copy is too large and exceeds the maximum permissible limit (256MB).**
Time:2023-04-03T10:46:30.3838959Z
ErrorCode:CannotVerifyCopySource
Content: <?xml version="1.0" encoding="utf-8"?><Error><Code>CannotVerifyCopySource</Code><Message>The source request body for synchronous copy is too large and exceeds the maximum permissible limit (256MB).
Time:2023-04-03T10:46:30.3838959Z</Message></Error>

使用blob客户端复制url将数据复制到目标路径的限制为256 MB,快照或磁盘的大小为1GB或更大,因此使用上述方法将无法工作。
作为替代,您可以使用az复制工具将快照复制到磁盘,如下所示:-

命令:

azcopy copy `"https://valleystrg.blob.core.windows.net/disk/abcd%20(1)?<SAS-Token>" "https://valleystrg.blob.core.windows.net/disk/abcd?<SAS-Token>" --recursive=true`

输出:

INFO: Scanning...
INFO: azcopy: A newer version 10.17.0 is available to download
INFO: Failed to create one or more destination container(s). Your transfers may still succeed if the container already exists.
INFO: Any empty folders will not be processed, because source and/or destination doesn't have full folder support
Job xxxxxxxx-ddb3dd4dc3ec has started
Log file is located at: /home/xxxx/.azcopy/xxxxxxc.log

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

Job xxxxx-ddb3dd4dc3ec summary
Elapsed Time (Minutes): 0.0667
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: 1073742336
Final Job Status: Completed

参考号:-

az storage blob copy start fails when files are larger than 256MB and requires-sync=true - Microsoft Q&A

相关问题