我目前有以下脚本:
$azPath = "C:\temp"
Set-Location $azPath
$StorageAccountName = "#"
$StorageAccountKey = "#"
$ContainerName = "sqlbackups"
$SourceFolder = "C:\temp"
$DestURL = "https://$StorageAccountName.blob.core.windows.net/$ContainerName"
$Result = .\AzCopy.exe /source:$SourceFolder /dest:$DestURL /BlobType:block /destkey:$StorageAccountKey /Y
$Result
,我收到以下错误消息:
PS C:\temp> .\load-backups2.ps1
Error: unknown command "/source:C:\\temp" for "azcopy"
Run 'azcopy --help' for usage.
unknown command "/source:C:\\temp" for "azcopy"
我想知道是否有人在这里看到我在做错什么>
答案 0 :(得分:1)
我可以重现您的问题,假设您的azcopy.exe
位于C:\temp
文件夹中。
要解决此问题,只需删除.\
中的$Result = .\AzCopy.exe /source:$SourceFolder /dest:$DestURL /BlobType:block /destkey:$StorageAccountKey /Y
。
应为$Result = AzCopy.exe /source:$SourceFolder /dest:$DestURL /BlobType:block /destkey:$StorageAccountKey /Y
,但它还将上载azcopy.exe
,因此,我建议您将azcopy.exe
移动到另一个文件夹,例如C:\test
。
然后该脚本将如下所示,在我这边工作正常。
$azPath = "C:\test"
Set-Location $azPath
$StorageAccountName = "#"
$StorageAccountKey = "#"
$ContainerName = "sqlbackups"
$SourceFolder = "C:\temp"
$DestURL = "https://$StorageAccountName.blob.core.windows.net/$ContainerName"
$Result = AzCopy.exe /source:$SourceFolder /dest:$DestURL /BlobType:block /destkey:$StorageAccountKey /Y
更新:
在上一个答复中,我直接使用AzCopy.exe
,但实际上我已经在PC中安装了AzCopy v8.1
,并将其设置为系统环境变量。因此,结果是v8.1
。我想您正在使用AzCopy v10
,如果我使用AzCopy v10
,我可以重现您的问题,您可能需要尝试AzCopy v8.1
,它可以工作。您可以按照以下步骤操作。
1。下载AzCopy v8.1
,安装它,默认路径为C:\Program Files (x86)\Microsoft SDKs\Azure\AzCopy\
,我使用默认路径。
2。用Path
设置系统环境变量C:\Program Files (x86)\Microsoft SDKs\Azure\AzCopy\
,保存它。详细信息请参见此link。
3。然后打开一个新的powershell会话,尝试命令。无需Set-Location
,因为我们已经设置了环境变量。
$StorageAccountName = "#"
$StorageAccountKey = "#"
$ContainerName = "sqlbackups"
$SourceFolder = "C:\temp"
$DestURL = "https://$StorageAccountName.blob.core.windows.net/$ContainerName"
$Result = AzCopy.exe /source:$SourceFolder /dest:$DestURL /BlobType:block /destkey:$StorageAccountKey /Y
答案 1 :(得分:0)
$azPath = "C:\temp"
Set-Location $azPath
Try This:
$StorageAccountName = "#"
$StorageAccountKey = "#"
$ContainerName = "sqlbackups"
$SourceFolder = "C:\temp"
$DestURL = "https://$StorageAccountName.blob.core.windows.net/$ContainerName"
$Result = .\AzCopy.exe copy "$SourceFolder" "$DestURL" --BlobType:blockblob --destkey:$StorageAccountKey /Y
$Result