I have been trying to find the best way to do the following:
I need to move a large amount of json files that are named following the format "yyyymmdd-hhmmss.json" from one blob container to another that’s in another storage account. These files are nested inside several different folders.
I only have to move the files that were created (or are named) before a certain date, for example: move all files that were created/are named before 01/01/2022.
What would be the best way to do so quickly? This is a one-time migration so it won’t be recurring.
2
Answers
You can iterate each blob in the source container (No matter how the folder structure is, as blob folders are simply virtual), and you can parse the name of the blob to filter blobs matching the pattern "yyyymmdd-hhmmss" and find the date and if it is older than the date that you wish to choose as a condition, you can easily copy the blob from your source to destination container, and finally delete the blob from the source container. Not sure about power shell, but its easy with any supported programming language.
Here’s an example of doing this with
.Net
:To copy files in bulk from a Source to a Destination Blob Container:
REF: https://www.jorgebernhardt.com/copy-blob-powershell/
Since you need to do individual files based on Date, instead of the
Start-AzStorageBlobCopy
the best is following the Microsoft Documentation with Asyncaz storage file copy
:REF: https://learn.microsoft.com/en-us/cli/azure/storage/file/copy?view=azure-cli-latest
The code to loop through the files based on date I’ll leave to the reader, eg: