How to delete files from source storage after sharing through Azure Data Share

DEEPANSHU CHAUHAN 0 Reputation points
2024-07-24T12:47:37.2433333+00:00

Is there a way to delete files from the source storage after sharing them through data share? I'd like to clean up the storage, but since data share doesn't have a feature for deleting shared files, I'm not sure how to do it. Any suggestions?

Azure Data Share
Azure Data Share
An Azure service that is used to share data from multiple sources with other organizations.
55 questions
Azure Blob Storage
Azure Blob Storage
An Azure service that stores unstructured data in the cloud as blobs.
2,926 questions
Azure Data Factory
Azure Data Factory
An Azure service for ingesting, preparing, and transforming data at scale.
10,854 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Sina Salam 12,011 Reputation points
    2024-07-24T13:13:11.4066667+00:00

    Hello DEEPANSHU CHAUHAN,

    Welcome to the Microsoft Q&A and thank you for posting your questions here.

    Problem

    I understand that you would like to delete files from the source storage after sharing them through data share.

    Solution

    You can achieve this by using other Azure services or manual deletion.

    Solution 1: Create a time-triggered Azure Function or Logic App. For example, use the following Azure CLI script to delete files from your file share or modify to the source storage:

     $myshare = "<<Share Name>>"
         $accountName = "<<Storage Account Name>>"
         $accountKey = "<<Storage Account Access Key1>>"
         $filelist = az storage file list -s $myshare --account-name $accountName --account-key $accountKey
         $fileArray = $filelist | ConvertFrom-Json
         foreach ($file in $fileArray | Where-Object {$_.properties.lastModified.DateTime -lt ((Get-Date).AddDays(-90))}) {
             $removefile = $file.name
             if ($removefile -ne $null) {
                 Write-Host "Removing file $removefile"
                 az storage file delete -s $myshare -p $removefile --account-name $accountName --account-key $accountKey
             }
         }
    

    Solution 2: Manual Deletion or cleanup. Periodically review the shared files and manually delete the ones you no longer need.

    Accept Answer

    I hope this is helpful! Do not hesitate to let me know if you have any other questions.

    ** Please don't forget to close up the thread here by upvoting and accept it as an answer if it is helpful ** so that others in the community facing similar issues can easily find the solution.

    Best Regards,

    Sina Salam


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.