Skip to content

Commit c587fdf

Browse files
authored
Merge pull request #237474 from pauljewellmsft/pauljewell-move-adls-samples
Move sample for restoring soft-deleted directory
2 parents 016d6d4 + 206c80a commit c587fdf

File tree

2 files changed

+17
-69
lines changed

2 files changed

+17
-69
lines changed

articles/storage/blobs/data-lake-storage-directory-file-acl-dotnet.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,22 @@ This example deletes a directory named `my-directory`.
103103

104104
:::code language="csharp" source="~/azure-storage-snippets/blobs/howto/dotnet/dotnet-v12/CRUD_DataLake.cs" id="Snippet_DeleteDirectory":::
105105

106+
## Restore a soft-deleted directory
107+
108+
You can use the Azure Storage client libraries to restore a soft-deleted directory. Use the following method to list deleted paths for a [DataLakeFileSystemClient](/dotnet/api/azure.storage.files.datalake.datalakefilesystemclient) instance:
109+
110+
- [GetDeletedPathsAsync](/dotnet/api/azure.storage.files.datalake.datalakefilesystemclient.getdeletedpathsasync)
111+
112+
Use the following method to restore a soft-deleted directory:
113+
114+
- [UndeletePathAsync](/dotnet/api/azure.storage.files.datalake.datalakefilesystemclient.undeletepathasync)
115+
116+
The following code example shows how to list deleted paths and restore a soft-deleted directory:
117+
118+
:::code language="csharp" source="~/azure-storage-snippets/blobs/howto/dotnet/dotnet-v12/CRUD_DataLake.cs" id="Snippet_RestoreDirectory":::
119+
120+
If you rename the directory that contains the soft-deleted items, those items become disconnected from the directory. If you want to restore those items, you'll have to revert the name of the directory back to its original name or create a separate directory that uses the original directory name. Otherwise, you'll receive an error when you attempt to restore those soft-deleted items.
121+
106122
## Upload a file to a directory
107123

108124
First, create a file reference in the target directory by creating an instance of the [DataLakeFileClient](/dotnet/api/azure.storage.files.datalake.datalakefileclient) class. Upload a file by calling the [DataLakeFileClient.AppendAsync](/dotnet/api/azure.storage.files.datalake.datalakefileclient.appendasync) method. Make sure to complete the upload by calling the [DataLakeFileClient.FlushAsync](/dotnet/api/azure.storage.files.datalake.datalakefileclient.flushasync) method.

articles/storage/blobs/storage-blob-delete.md

Lines changed: 1 addition & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ To restore deleted blobs when versioning is not enabled, call either of the foll
5252
These methods restore soft-deleted blobs and any deleted snapshots associated with them. Calling either of these methods for a blob that has not been deleted has no effect. The following example restores all soft-deleted blobs and their snapshots in a container:
5353

5454
```csharp
55-
public static async Task UnDeleteBlobs(BlobContainerClient container)
55+
public static async Task UndeleteBlobs(BlobContainerClient container)
5656
{
5757
foreach (BlobItem blob in container.GetBlobs(BlobTraits.None, BlobStates.Deleted))
5858
{
@@ -115,74 +115,6 @@ public static void RestoreBlobsWithVersioning(BlobContainerClient container, Blo
115115
}
116116
```
117117

118-
## Restore soft-deleted blobs and directories (hierarchical namespace)
119-
120-
> [!IMPORTANT]
121-
> This section applies only to accounts that have a hierarchical namespace.
122-
123-
1. Open a command prompt and change directory (`cd`) into your project folder For example:
124-
125-
```console
126-
cd myProject
127-
```
128-
129-
2. Install the `Azure.Storage.Files.DataLake -v 12.7.0` version or greater of the [Azure.Storage.Files.DataLake](https://www.nuget.org/packages/Azure.Storage.Files.DataLake/) NuGet package by using the `dotnet add package` command.
130-
131-
```console
132-
dotnet add package Azure.Storage.Files.DataLake -v -v 12.7.0 -s https://pkgs.dev.azure.com/azure-sdk/public/_packaging/azure-sdk-for-net/nuget/v3/index.json
133-
```
134-
135-
3. Then, add these using statements to the top of your code file.
136-
137-
```csharp
138-
using Azure;
139-
using Azure.Storage;
140-
using Azure.Storage.Files.DataLake;
141-
using Azure.Storage.Files.DataLake.Models;
142-
using NUnit.Framework;
143-
using System;
144-
using System.Collections.Generic;
145-
using System.Threading.Tasks;
146-
```
147-
148-
4. The following code deletes a directory, and then restores a soft-deleted directory.
149-
150-
This method assumes that you've created a [DataLakeServiceClient](/dotnet/api/azure.storage.files.datalake.datalakeserviceclient) instance. To learn how to create a [DataLakeServiceClient](/dotnet/api/azure.storage.files.datalake.datalakeserviceclient) instance, see [Connect to the account](data-lake-storage-directory-file-acl-dotnet.md#connect-to-the-account).
151-
152-
```csharp
153-
public void RestoreDirectory(DataLakeServiceClient serviceClient)
154-
{
155-
DataLakeFileSystemClient fileSystemClient =
156-
serviceClient.GetFileSystemClient("my-container");
157-
158-
DataLakeDirectoryClient directory =
159-
fileSystem.GetDirectoryClient("my-directory");
160-
161-
// Delete the Directory
162-
await directory.DeleteAsync();
163-
164-
// List Deleted Paths
165-
List<PathHierarchyDeletedItem> deletedItems = new List<PathHierarchyDeletedItem>();
166-
await foreach (PathHierarchyDeletedItem deletedItem in fileSystemClient.GetDeletedPathsAsync())
167-
{
168-
deletedItems.Add(deletedItem);
169-
}
170-
171-
Assert.AreEqual(1, deletedItems.Count);
172-
Assert.AreEqual("my-directory", deletedItems[0].Path.Name);
173-
Assert.IsTrue(deletedItems[0].IsPath);
174-
175-
// Restore deleted directory.
176-
Response<DataLakePathClient> restoreResponse = await fileSystemClient.RestorePathAsync(
177-
deletedItems[0].Path.Name,
178-
deletedItems[0].Path.DeletionId);
179-
180-
}
181-
182-
```
183-
184-
If you rename the directory that contains the soft-deleted items, those items become disconnected from the directory. If you want to restore those items, you'll have to revert the name of the directory back to its original name or create a separate directory that uses the original directory name. Otherwise, you'll receive an error when you attempt to restore those soft-deleted items.
185-
186118
## Resources
187119

188120
To learn more about how to delete blobs and restore deleted blobs using the Azure Blob Storage client library for .NET, see the following resources.

0 commit comments

Comments
 (0)