Philip
Philip

Reputation: 2628

AzCopy Unknown /source command

I have the following script currently:

$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

and I get the following error:

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"

I'm wondering if anyone could see what I'm doing wrong here>

Upvotes: 0

Views: 7055

Answers (2)

Joy Wang
Joy Wang

Reputation: 42163

I can reproduce your issue, I suppose your azcopy.exe is located in the C:\temp folder. To fix the issue, just remove the .\ in the $Result = .\AzCopy.exe /source:$SourceFolder /dest:$DestURL /BlobType:block /destkey:$StorageAccountKey /Y.

It should be $Result = AzCopy.exe /source:$SourceFolder /dest:$DestURL /BlobType:block /destkey:$StorageAccountKey /Y, but it will also upload the azcopy.exe, so I recommend you to move the azcopy.exe to another folder, like C:\test.

Then the script will be like as below, it works fine on my side.

$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

enter image description here

Update:

In my previous reply, I use AzCopy.exe directly, but actually I have installed the AzCopy v8.1 in my PC, and I have set it to the system environment variable. So the result is for v8.1. I suppose you are using AzCopy v10, if I use AzCopy v10, I can reproduce your issue, you may need to try AzCopy v8.1, it works. You could follow the steps below.

1.Download the AzCopy v8.1, install it, the default path will be C:\Program Files (x86)\Microsoft SDKs\Azure\AzCopy\, I use the default path.

2.Set the system environment variable Path with C:\Program Files (x86)\Microsoft SDKs\Azure\AzCopy\, save it. Details see this link.

enter image description here

3.Then open a new powershell session, try the command. No need to Set-Location, because we have set the environment variable.

$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

Upvotes: 1

SKRAT31
SKRAT31

Reputation: 3

$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

Upvotes: 0

Related Questions