如何处理 AZcopy 失败的文件传输

How to handle AZcopy failed file transfers

我正在将大量小文件从本地文件系统复制到 Azure blob 存储。 很少有文件无法上传。 似乎 AZcopy 只是记录了这些失败,并没有简单的方法来重试上传这些文件。 逐个搜索每个文件并手动上传是不可行的(时间方面)。 是否有任何建议来处理这些失败并重试自动上传到 Blob?

如果传输作业错误不是由 sas 令牌或身份验证导致的,您可以尝试从这个 link.

下面的命令行

显示作业失败的错误信息:

azcopy jobs show <job-id> --with-status=Failed

修复它们,然后执行恢复命令:

azcopy jobs resume <job-id> --source-sas="<sas-token>"
azcopy jobs resume <job-id> --destination-sas="<sas-token>"

请参考上面命令的声明:

When you resume a job, AzCopy looks at the job plan file. The plan file lists all the files that were identified for processing when the job was first created. When you resume a job, AzCopy will attempt to transfer all of the files that are listed in the plan file which weren't already transferred.

我遇到过进程被终止的情况(这可能发生在容器化环境中)。所以我想最简单的方法是实现重试机制(灵感来自 here)。我在下载时遇到了这个问题,但修复方法几乎相同:

function azcopyWithRetry() {
      local list_of_blobs=`echo `
      local connection_string="https://.blob.core.windows.net//*?"
      local download_path="/tmp/download"
      local max_attempts=""
      local command="azcopy copy --include-path ${list_of_blobs} ${connection_string} ${download_path}"

      local n=1
      while true; do
        ${command}  && break || {
          if [[ $n -lt $max_attempts ]]; then
            echo "WARN: Command failed, retrying. (attempt $n/$max_attempts) "
            ((n++))
            sleep 1;
          else
            echo "FAIL: Command failed after $n attempts. Nothing will happen"
            return 1
          fi
        }
      done
}

你会调用这个函数:

export LIST_BLOBS="blobs.txt"
export AZ_ACCOUNT="..."
export AZ_CONTAINER="..."
export AZ_SAS_TOKEN="..."
azcopyWithRetry ${LIST_BLOBS} ${AZ_ACCOUNT} ${AZ_CONTAINER} ${AZ_SAS_TOKEN} 5

重试 5 次

添加到此线程,因为我 运行 偶尔会出现大量故障。填充空白目录的作用域场景的一个简单解决方案是 运行 使用 --overwrite=false 命令再次执行 azcopy copy 命令。