Are you tired of manually moving files and folders between blob containers in different storage accounts? Do you want to automate this process and save time and effort? Look no further! In this article, we will show you how to use a Logic app to move multiple folder structures along with files from one blob container to another in different storage accounts.
- Prerequisites
- Step 1: Create a Logic app
- Step 2: Add a Trigger
- Step 3: Add an Action
- Step 4: Add a Loop
- Step 5: Add a Condition
- Step 6: Add a List Blobs Action
- Step 7: Add a For Each Loop
- Step 8: Add a Condition (File or Folder)
- Step 9: Move File or Create Folder
- Step 10: Add a Delay
- Step 11: Save and Test
- Conclusion
Prerequisites
Before we dive into the process, make sure you have the following:
- A Azure Storage account with a blob container containing the files and folders you want to move.
- A second Azure Storage account with a blob container where you want to move the files and folders.
- An Azure Logic app.
- Basic knowledge of Azure Logic apps and Azure Storage.
Step 1: Create a Logic app
Go to the Azure portal and create a new Logic app resource. Give your Logic app a name, select a subscription, resource group, and location. Click “Create” to create the Logic app.
Resource Type: Logic app
Name: MoveFilesAndFolders
Subscription: Your Subscription
Resource Group: Your Resource Group
Location: Your Location
Step 2: Add a Trigger
In the Logic app designer, click on the “Add a trigger” button. Search for “Blob storage” and select the “When a blob is added or modified” trigger.
Configure the trigger to point to your source blob container. Select the container, and set the blob type to “Folder”. This will trigger the Logic app whenever a folder is added or modified in the source container.
Trigger: When a blob is added or modified
Container: sourcecontainer
Blob type: Folder
Step 3: Add an Action
Click on the “Add an action” button. Search for “Blob storage” and select the “Create a blob” action.
Configure the action to point to your destination blob container. Select the container, and set the blob type to “Folder”. This will create a new folder in the destination container.
Action: Create a blob
Container: destinationcontainer
Blob type: Folder
Step 4: Add a Loop
To move multiple folders and files, we need to add a loop that iterates through the folder structure. Click on the “Add an action” button, and search for “Until” loop. Select the “Until” loop action.
Loop: Until
Step 5: Add a Condition
Inside the loop, add a condition to check if the folder has files or subfolders. Click on the “Add a condition” button, and select the “Is true” condition.
Condition: Is true
Step 6: Add a List Blobs Action
Inside the condition, add a “List blobs” action to get the list of blobs (files and folders) in the current folder. Configure the action to point to the source blob container, and set the prefix to the current folder path.
Action: List blobs
Container: sourcecontainer
Prefix: /path/to/current/folder
Step 7: Add a For Each Loop
Inside the “List blobs” action, add a “For each” loop to iterate through the list of blobs. Click on the “Add an action” button, and select the “For each” loop action.
Loop: For each
Step 8: Add a Condition (File or Folder)
Inside the “For each” loop, add a condition to check if the blob is a file or a folder. Click on the “Add a condition” button, and select the “Is true” condition.
Condition: Is true
Step 9: Move File or Create Folder
If the blob is a file, add a “Create a blob” action to move the file to the destination container. If the blob is a folder, add a “Create a blob” action to create a new folder in the destination container.
If file:
Action: Create a blob
Container: destinationcontainer
Blob type: File
If folder:
Action: Create a blob
Container: destinationcontainer
Blob type: Folder
Step 10: Add a Delay
Finally, add a delay action to wait for 1 minute before checking the folder again. This is to prevent the Logic app from running indefinitely.
Action: Delay
Duration: 1 minute
Step 11: Save and Test
Save the Logic app, and test it by adding a new folder or file to the source blob container. The Logic app should move the folder structure along with files to the destination blob container.
Source Blob Container | Destination Blob Container |
---|---|
/path/to/source/folder | /path/to/destination/folder |
/path/to/source/folder/file.txt | /path/to/destination/folder/file.txt |
/path/to/source/folder/subfolder | /path/to/destination/folder/subfolder |
/path/to/source/folder/subfolder/file.txt | /path/to/destination/folder/subfolder/file.txt |
Conclusion
In this article, we showed you how to use a Logic app to move multiple folder structures along with files from one blob container to another in different storage accounts. This process can be automated and customized to fit your specific requirements. By following these steps, you can save time and effort, and ensure that your files and folders are moved efficiently and accurately.
Remember to test your Logic app thoroughly to ensure that it meets your requirements. You can also add additional actions, conditions, and loops to customize the process to fit your specific needs.
Troubleshooting Tips
If you encounter any issues with your Logic app, check the following:
- Make sure the Logic app has the necessary permissions to access the blob containers.
- Check the blob container names and paths to ensure they are correct.
- Verify that the folder structure is correct and consistent across both blob containers.
- Test the Logic app with a small dataset to ensure it is working correctly before running it on a large scale.
We hope this article has been helpful in showing you how to move multiple folder structures along with files from one blob container to another in different storage accounts using Logic app. If you have any questions or need further assistance, please don’t hesitate to ask.
Frequently Asked Question
Got stuck while moving multiple folder structures along with files from one blob container to another in different storage accounts using Logic App? Don’t worry, we’ve got you covered!
Q1: What is the best approach to move multiple folder structures along with files from one blob container to another in different storage accounts using Logic App?
The best approach is to use the “List blobs” action to retrieve the list of files and folders, and then use a “For each” loop to iterate through the list. Inside the loop, use the “Get blob content” action to retrieve the file content, and then the “Create blob” action to upload the file to the target container.
Q2: How can I preserve the original folder structure while moving files from one container to another?
You can preserve the original folder structure by using the “List blobs” action with the “Recursive” option enabled. This will retrieve the list of files and folders recursively, and then you can use the “For each” loop to iterate through the list and upload the files to the target container, maintaining the original folder structure.
Q3: Can I use the “Copy blob” action to move files from one container to another?
No, the “Copy blob” action is not recommended for moving files from one container to another, especially when dealing with large files or a large number of files. Instead, use the “Get blob content” and “Create blob” actions to ensure a more reliable and efficient file transfer process.
Q4: How can I handle errors and exceptions while moving files from one container to another using Logic App?
You can handle errors and exceptions by using the “Try-catch” block in the Logic App workflow. This allows you to catch and handle any exceptions that occur during the file transfer process, and take appropriate actions to retry or notify stakeholders.
Q5: What are the potential performance considerations when moving large files or a large number of files from one container to another using Logic App?
Potential performance considerations include the size and number of files, network bandwidth, and the performance of the storage accounts and Logic App instance. To optimize performance, consider using chunking for large files, batching for a large number of files, and scaling up the Logic App instance as needed.