Home > Mobile >  Azure Blob copy folder from one container to another after zipping it
Azure Blob copy folder from one container to another after zipping it

Time:02-26

Inside a blob storage I have two containers Source and Target. I need to copy the folders from Source to target but one condition is that the folders need to be zipped before I copy them into the Target container. I am using Python. I have managed to copy the folders but I haven't been able to find a way to zip them.

blob_service_client = BlobServiceClient(account_url='https://blob_storage.blob.core.windows.net/',credential='access_key')

source_container_name = "Source"
source_file_path = "1644579641903/data_0_0_0.csv"

source_blob = f"https://blob_storage.blob.core.windows.net/{source_container_name}/{source_file_path}"

target_container_name = "Target"
target_file_path = "1644579641903/data_0_0_0.csv"

copied_blob = blob_service_client.get_blob_client(target_container_name, target_file_path)
copied_blob.start_copy_from_url(source_blob)

CodePudding user response:

I have tested in my environment

As suggested by Joel Cochran, we can use Copy Activity in Azure Data Factory to copy the folder from one container to another container after zipping it

You need to create a Linked service with your Azure Blob Storage account details in Azure Data Factory

Create a pipeline with Copy Data Activity. Select Source as Azure Blob Storage binary dataset with source container and compression type as None

Select Sink as Azure Blob Storage binary dataset with your target container and compression type as ZipDeflate

Publish and Run the Pipeline. A zip file with all the files and folders in source container will be copied to the target container

  • Related