Reputation: 27
Is there an AzCopy parameter to ensure the destination folder is empty?
If not, how should I check to ensure the folder is empty in a VSTS build pipeline?
Upvotes: 0
Views: 2078
Reputation: 556
What's your destination for the transfer, is it Blob or Local file?
If it's blob, use following script can check if the folder if empty
$ctx=New-AzureStorageContext -StorageAccountName $StorageAccountName -StorageAccountKey $key
$blob = Get-AzureStorageBlob -Container $containerName -Prefix dir1/dir2/ -Context $ctx -MaxCount 1
if ($blob -eq $null)
{
# container/dir1/dir2/ Don't have blob, so do AzCopy transfer
}
If it's localfile, using following script:
$file = Get-ChildItem c:\dir1\dir2\
if ($file -eq $null)
{
# c:\dir1\dir2\ Don't have file, so do AzCopy transfer
}
Upvotes: 1
Reputation: 42123
AFAIK, Azcopy has a feature that can only copy data that doesn't exist in the destination, if you want to prevent AzCopy.exe when destination folder exists already, it seems not necessary to check the destination folder if empty.
The
/XO
and/XN
parameters allow you to exclude older or newer source resources from being copied, respectively. If you only want to copy source resources that don't exist in the destination, you can specify both parameters in the AzCopy command
Upvotes: 0