Recover deleted files in OneLake

OneLake soft delete protects your data by retaining deleted files before permanent removal. Soft delete is turned on for each workspace by default with a seven-day retention period. Workspace admins can configure file-level soft delete or turn it off.

You can restore a soft-deleted file during the retention period that was active when the file was deleted. After that period ends, the file is permanently removed and can't be recovered. You pay for soft-deleted data at the same rate as active data.

Restore soft-deleted files

You can restore soft-deleted files by using Azure Storage Explorer, Azure PowerShell, or Azure Storage REST APIs. You need write access to the files to restore them.

Restore files by using Azure Storage Explorer

Azure Storage Explorer provides a visual interface to browse and restore soft-deleted files.

To restore files by using Azure Storage Explorer, make sure you have:

Use the following steps to restore files:

  1. Open Azure Storage Explorer and connect to your OneLake workspace.

  2. Go to the lakehouse or data item that contained the deleted files.

  3. Select the dropdown button next to the path bar, and then select Active and soft deleted blobs instead of the default Active blobs.

  4. Browse to the folder that contained the deleted file.

  5. Right-click the soft-deleted file, and then select Undelete.

  6. The file is restored to its original location and is immediately available.

Restore files by using PowerShell

Use Azure PowerShell to list and restore soft-deleted files programmatically.

To restore files by using PowerShell, make sure you have:

Use the following script to list soft-deleted files in a specific path:

# Connect to OneLake
$ctx = New-AzStorageContext -StorageAccountName "onelake" -UseConnectedAccount -endpoint "fabric.microsoft.com"

# List soft-deleted blobs in a container (workspace)
$workspaceName = "your-workspace-name"
$path = "your-lakehouse.Lakehouse/Files/"

Get-AzStorageBlob -Container $workspaceName -Context $ctx -Prefix $path -IncludeDeleted | 
    Where-Object { $_.IsDeleted } |
    Select-Object Name, DeletedTime, RemainingDaysBeforePermanentDelete

Use the following script to restore a soft-deleted file:

# Connect to OneLake
$ctx = New-AzStorageContext -StorageAccountName "onelake" -UseConnectedAccount -endpoint "fabric.microsoft.com"

# Restore a specific blob
$workspaceName = "your-workspace-name"
$blobPath = "your-lakehouse.Lakehouse/Files/deleted-file.parquet"

$deletedItems = Get-AzDataLakeGen2DeletedItem -Context $ctx -FileSystem $workspaceName -Path $blobPath
$deletedItems | Restore-AzDataLakeGen2DeletedItem

For more PowerShell examples, see Restore soft-deleted blobs and directories by using PowerShell.

Restore files by using REST APIs

You can also restore soft-deleted files by using Azure Blob Storage REST APIs and SDKs. The Undelete Blob operation restores the contents and metadata of a soft-deleted blob.

For more information, see Undelete Blob REST API.