-1

I need some help with copying Blobs from one container in blob storage to another container. I have csv files in one container which i load into Azure database, after that these csv files are replaced with new files next day, however i want to create runbook in which when the files are loaded to Azure DB using ADF, a copy of these files should also be saved to another container for archiving, this runbook should create a sub-folder in the container with date stamp and save the csv files into it automatically.

Can someone please help me with this?

enter image description here

AKG
  • 13
  • 3
  • 10

1 Answers1

1

Try the PowerShell snippet to copy a blob from one container to a folder named with date in another container:

param(
[Parameter(Mandatory=$True, Position=0, ValueFromPipeline=$false)]
[string] $csvFileName 
)

$storageAccount = "<storage account name>"
$resourceGroup = "<resource group name>"
$containerName = "<source container name>"
$backupContainerName = "<dest container name>"
$folderName = (get-date).ToString("yyyy_MM_dd")

$storage = Get-AzStorageAccount -Name $storageAccount -ResourceGroupName $resourceGroup
Start-AzStorageBlobCopy -SrcBlob $csvFileName   -SrcContainer $containerName -DestBlob ($folderName+"/"+$csvFileName) -DestContainer $backupContainerName -Context $storage.Context

Result :

enter image description here

Hope it helps.

Update:

This error is due to you haven't installed Az module, pls go to your Azure Automation => Modules => Browse Gallery to install Az related packages :

enter image description here

Stanley Gong
  • 11,522
  • 1
  • 8
  • 16
  • Sorry about delayed response, I was able to get it working with the help of an article found on GIT. your solution was close but i needed a solution where there is no parameter needed, it should pick up the blob from source by its own and save it into dest. one by one. Thanks! a lot for your time and help. – AKG Jan 30 '20 at 09:48