简体   繁体   English

如何通过 Azure yaml 管道将数据从私有 S3 存储桶复制到 Azure Blob 存储

[英]How to copy data from private S3 bucket to Azure Blob storage via Azure yaml pipeline

I have one S3 bucket storing CSV files in it.我有一个存储 CSV 文件的 S3 存储桶。 New CSV files get added to this bucket at the beginning of each month.新的 CSV 文件会在每个月初添加到此存储桶中。 I want these new files to be uploaded automatically to the Azure blob storage at the beginning of each month.我希望在每个月初将这些新文件自动上传到 Azure blob 存储。

The way I was thinking to do this is to create a script(bash/PowerShell) that pulls data from the AWS S3 bucket to Azure blob storage via AZ Copy command.我想这样做的方法是创建一个脚本(bash/PowerShell),通过AZ Copy命令将数据从 AWS S3 存储桶提取到 Azure blob 存储。 and then plug this script into an Azure YAML pipeline which runs every start of the month to execute this script.然后将此脚本插入 Azure YAML 管道,该管道在每个月初运行以执行此脚本。 but I can't find a way to integrate this script in an Azure YAML pipeline.但我找不到将此脚本集成到 Azure YAML 管道中的方法。 Is this command feasible with the YAML pipeline?这个命令对于 YAML 管道是否可行? or is there any simple way to do this?或者有什么简单的方法可以做到这一点?

We can copy data from S3 bucket to Azure Blob Storage using azcopy.我们可以使用 azcopy 将数据从 S3 存储桶复制到 Azure Blob 存储。

azcopy copy "<s3-bucket-uri>" "https://StorageAccountName.blob.core.windows.net/container-name/?sas-token" --recursive

We can integrate the azcopy with YAML pipeline.我们可以将 azcopy 与 YAML 管道集成。

Firstly, install azcopy in pipeline agent as below :首先,在管道代理中安装 azcopy,如下所示:

- task: Bash@3
  displayName: Install azcopy
  inputs:
    targetType: 'inline'
    script: |
      curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
      mkdir $(Agent.ToolsDirectory)/azcopy
      wget -O $(Agent.ToolsDirectory)/azcopy/azcopy_v10.tar.gz https://aka.ms/downloadazcopy-v10-linux
      tar -xf $(Agent.ToolsDirectory)/azcopy/azcopy_v10.tar.gz -C $(Agent.ToolsDirectory)/azcopy --strip-components=1

Create cli-task with azcopy in pipeline to copy data from S3 bucket to Azure Blob Storage using azcopy在管道中使用 azcopy 创建 cli 任务,以使用 azcopy将数据从 S3 存储桶复制到 Azure Blob 存储

Reference code :参考代码 :

- task: AzureCLI@2
  displayName: Download using azcopy
  inputs:
    azureSubscription: 'Service-Connection'
    scriptType: 'bash'
    scriptLocation: 'inlineScript'
    inlineScript: |
      end=`date -u -d "180 minutes" '+%Y-%m-%dT%H:%M:00Z'`
      $(Agent.ToolsDirectory)/azcopy/azcopy copy "<s3-bucket-uri>" "https://StorageAccountName.blob.core.windows.net/container-name/?sas-token" --recursive --check-md5=FailIfDifferent

Reference SO thread : Azure Pipelines - Download files with azcopy - Stack Overflow参考 SO 线程: Azure Pipelines - 使用 azcopy 下载文件 - VoidCC

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM