AzCopy Sync 命令失败

AzCopy Sync command is failing

我正在发出这个命令:

azcopy sync "D:\Releases\Test\MyApp" "http://server3:10000/devstoreaccount1/myapp?sv=2019-02-02&st=2020-06-24T03%3A19%3A44Z&se=2020-06-25T03%3A19%3A44Z&sr=c&sp=racwdl&sig=REDACTED"

...我收到此错误:

error parsing the input given by the user. Failed with error Unable to infer the source 'D:\Releases\Test\MyApp' / destination 'http://server3:10000/devstoreaccount1/myapp?sv=2019-02-02&st=2020-06-24T03%3A19%3A44Z&se=2020-06-25T03%3A19%3A44Z&sr=c&sp=racwdl&sig=-REDACTED-

我本以为我的来源很清楚。

有人能看出我的语法有什么问题吗?

命令行需要--recursive选项。参见 https://docs.microsoft.com/en-us/azure/storage/common/storage-use-azcopy-blobs?toc=/azure/storage/blobs/toc.json

我相信您 运行 遇到了 azcopy 不支持本地模拟器的问题(至少对于 sync 命令)。 Github 上有一个未解决的问题:https://github.com/Azure/azure-storage-azcopy/issues/554.

基本上,问题出在 code 的以下几行中,其中 returns 在存储模拟器 URL 的情况下定位为 Unknown

func inferArgumentLocation(arg string) common.Location {
    if arg == pipeLocation {
        return common.ELocation.Pipe()
    }
    if startsWith(arg, "http") {
        // Let's try to parse the argument as a URL
        u, err := url.Parse(arg)
        // NOTE: sometimes, a local path can also be parsed as a url. To avoid thinking it's a URL, check Scheme, Host, and Path
        if err == nil && u.Scheme != "" && u.Host != "" {
            // Is the argument a URL to blob storage?
            switch host := strings.ToLower(u.Host); true {
            // Azure Stack does not have the core.windows.net
            case strings.Contains(host, ".blob"):
                return common.ELocation.Blob()
            case strings.Contains(host, ".file"):
                return common.ELocation.File()
            case strings.Contains(host, ".dfs"):
                return common.ELocation.BlobFS()
            case strings.Contains(host, benchmarkSourceHost):
                return common.ELocation.Benchmark()
                // enable targeting an emulator/stack
            case IPv4Regex.MatchString(host):
                return common.ELocation.Unknown()//This is what gets returned in case of storage emulator URL.
            }

            if common.IsS3URL(*u) {
                return common.ELocation.S3()
            }
        }
    }

    return common.ELocation.Local()
}

好的 - 经过大量的 futzing 我终于能够使用 Azurite 和 PowerShell 让它工作。很明显,AzureCLI 和 AzCopy 都没有在仿真下经过良好测试。

这是一个可以从管道调用的粗略脚本:

[CmdletBinding()]
param(
  [Parameter(Mandatory)][string] $Container,
  [Parameter(Mandatory)][string] $Source
)

$Context = New-AzureStorageContext -Local
$BlobNames = Get-AzureStorageBlob -Context $Context -Container $Container | % { $_.Name }
$FilesToSync = gci $Source\* -Include RELEASES, Setup.exe
$Packages = gci $Source -Filter *.nupkg

$Packages | % {
  If (!($BlobNames.Contains($_.Name))) {
    $FilesToSync += $_
  }
}

$FilesToSync | Set-AzureStorageBlobContent -Context $Context -Container $Container -Force

请注意,这是针对我的 Squirrel 部署(*.nupkg、RELEASES、Setup.exe)高度定制的,因此人们会希望根据自己的环境进行相应调整。

Azurite 可以设置为始终开启,使用计划任务每​​小时 运行 此命令:

powershell -command "Start-Process azurite-blob.cmd -PassThru -ArgumentList '--blobHost 0.0.0.0'"

该参数将 Azurite 设置为侦听任何 IP,以便可以从网络上的其他计算机访问它。我在防火墙上为端口 10000-10002 打了一个洞。

注意在用于安装 Azurite 的同一帐户下将任务设置为 运行,否则任务将无法看到 azurite-blob.cmd(它位于 %AppData%\npm,在安装过程中添加到 PATH)。

我在尝试从本地计算机同步到 Azure Blob 存储时遇到了同样的问题。

这是我的命令 运行:

azcopy sync "C:\AzureStorageTest\my-app\*" "https://myapptest.z16.web.core.windows.net/$web"

但是我得到以下错误:

INFO: The parameters you supplied were Source: 'c:\AzureStorageTest\my-app' of type Local, and Destination: 'https:// myapptest.z16.web.core.windows.net/' of type Local

INFO: Based on the parameters supplied, a valid source-destination combination could not automatically be found. Please check the parameters you supplied. If they are correct, please specify an exact source and destination type using the - -from-to switch. Valid values are two-word phases of the form BlobLocal, LocalBlob etc. Use the word 'Blob' for Blob St orage, 'Local' for the local file system, 'File' for Azure Files, and 'BlobFS' for ADLS Gen2. If you need a combination that is not supported yet, please log an issue on the AzCopy GitHub issues list.

error parsing the input given by the user. Failed with error Unable to infer the source 'C:\AzureStorageTest\my-app' / destination 'https://myapptest.z16.web.core.windows.net.z16.web.core.windows.net/'. PS C:\Users\promise> azcopy sync "C:\AzureStorageTest\my-app" "https://myapptest.z16.web.core.windows.net.z16.web.core.window s.net/$web" -from-to localblob Error: unknown shorthand flag: 'f' in -from-to

我是这样解决的:

我在 Blob 存储位置末尾缺少 ?[SAS] 参数。此外,在撰写本文时,azccopy sync 命令似乎不支持 --from-to switch。所以不是这个:

azcopy sync "C:\AzureStorageTest\my-app" "https://myapptest.z16.web.core.windows.net/$web"

我有这个:

azcopy sync "C:\AzureStorageTest\my-app" "https://myapptest.blob.core.windows.net/%24web?[SAS]" --recursive

:

  1. 格式为azcopy sync "/path/to/dir" "https://[account].blob.core.windows.net/[container]/[path/to/directory]?[SAS]" --recursive。您只需要修改"/path/to/dir"[account][container]/[path/to/directory]。其他一切都保持原样。
  2. 我实际的Blob存储位置是https://myapptest.blob.core.windows.net/web but I used https://myapptest.blob.core.windows.net/%24web,因为$在使用的时候会报错,所以用了%24
  3. 不要像我那样使用 blob 网站地址 https://myapptest.z16.web.core.windows.net/ 这让我对很多错误感到沮丧,而是使用 blob 存储地址 https://myapptest.blob.core.windows.net
  4. --recursive 标志已在此目录同步操作中推断出来,因此您可以考虑将其删除。为了清楚起见,我把它放了。

就这些了。

希望对您有所帮助