【问题标题】:Copy files within Azure ADLS gen2 using Azure CLI, Rest API or Python使用 Azure CLI、Rest API 或 Python 在 Azure ADLS gen2 中复制文件
【发布时间】:2020-01-20 12:39:45
【问题描述】:

是否有任何简单的方法可以使用 Azure CLI、Rest API 或 Python 在 Azure ADLS gen2 中复制数据?

Azure ADLS gen2 API 文档目前非常有限... https://docs.microsoft.com/en-us/rest/api/storageservices/data-lake-storage-gen2

【问题讨论】:

  • 这里有同样的问题

标签: python azure azure-data-lake-gen2


【解决方案1】:

根据我的研究,我们可以使用 Azure CLI 或 python 来移动目录或移动文件。更多详情请参考document

例如

  1. 安装存储 CLI 扩展。请注意,CLI 版本应大于 2.0.67
az extension add -n storage-preview
  1. 脚本
# move directory
az storage blob directory move -c my-file-system -d my-new-directory -s my-directory --account-name mystorageaccount

# move a file
az storage blob move -c my-file-system -d my-file-new.txt -s my-file.txt --account-name mystorageaccount

Python

try:

       file_system_client = service_client.get_file_system_client(file_system="my-file-system")
       directory_client = file_system_client.get_directory_client("my-directory")

       new_dir_name = "my-directory-renamed"
       directory_client.rename_directory(rename_destination=directory_client.file_system_name + '/' + new_dir_name)

    except Exception as e:
     print(e) 

【讨论】:

  • 谢谢,您在 python 示例中使用了什么库?
  • @fuggy_yama 关于python sdk,请参考docs.microsoft.com/en-us/azure/storage/blobs/…
  • @fuggy_yama 您还有其他顾虑吗?
  • @fuggy_yamaf 既然您没有其他顾虑,请accept the answer。它可能会帮助更多的人。
  • 我刚刚意识到这是 MOVE 操作,我实际上需要在 ADLS gen2 中复制文件。
猜你喜欢
  • 2020-09-15
  • 2021-08-03
  • 2022-08-02
  • 2019-11-26
  • 1970-01-01
  • 2022-01-13
  • 2021-11-25
  • 2019-12-09
  • 1970-01-01
相关资源
最近更新 更多