Skip to content

Commit 6b38ba7

Browse files
authored
Merge pull request #252320 from pauljewellmsft/delete-refresh
Dev guide delete blobs refresh
2 parents f21553c + e2c1af5 commit 6b38ba7

File tree

3 files changed

+32
-72
lines changed

3 files changed

+32
-72
lines changed

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,19 @@ This article shows how to delete blobs with the [Azure Storage client library fo
3030

3131
To delete a blob, call one of these methods:
3232

33-
- [delete](/java/api/com.azure.storage.blob.specialized.blobclientbase)
34-
- [deleteIfExists](/java/api/com.azure.storage.blob.specialized.blobclientbase)
33+
- [delete](/java/api/com.azure.storage.blob.specialized.blobclientbase#method-summary)
34+
- [deleteIfExists](/java/api/com.azure.storage.blob.specialized.blobclientbase#method-summary)
3535

3636
The following example deletes a blob:
3737

3838
:::code language="java" source="~/azure-storage-snippets/blobs/howto/Java/blob-devguide/blob-devguide-blobs/src/main/java/com/blobs/devguide/blobs/BlobDelete.java" id="Snippet_DeleteBlob":::
3939

40-
The following example deletes a blob and its snapshots with a response:
40+
If the blob has any associated snapshots, you must delete all of its snapshots to delete the blob. The following example deletes a blob and its snapshots with a response:
4141

4242
:::code language="java" source="~/azure-storage-snippets/blobs/howto/Java/blob-devguide/blob-devguide-blobs/src/main/java/com/blobs/devguide/blobs/BlobDelete.java" id="Snippet_DeleteBlobSnapshots":::
4343

44+
To delete *only* the snapshots and not the blob itself, you can pass the parameter `DeleteSnapshotsOptionType.ONLY`.
45+
4446
## Restore a deleted blob
4547

4648
Blob soft delete protects an individual blob and its versions, snapshots, and metadata from accidental deletes or overwrites by maintaining the deleted data in the system for a specified period of time. During the retention period, you can restore the blob to its state at deletion. After the retention period has expired, the blob is permanently deleted. For more information about blob soft delete, see [Soft delete for blobs](soft-delete-blob-overview.md).
@@ -56,17 +58,17 @@ How you restore a soft-deleted blob depends on whether or not your storage accou
5658

5759
To restore deleted blobs, call the following method:
5860

59-
- [undelete](/java/api/com.azure.storage.blob.specialized.blobclientbase)
61+
- [undelete](/java/api/com.azure.storage.blob.specialized.blobclientbase#method-summary)
6062

6163
This method restores the content and metadata of a soft-deleted blob and any associated soft-deleted snapshots. Calling this method for a blob that hasn't been deleted has no effect.
6264

6365
:::code language="java" source="~/azure-storage-snippets/blobs/howto/Java/blob-devguide/blob-devguide-blobs/src/main/java/com/blobs/devguide/blobs/BlobDelete.java" id="Snippet_RestoreBlob":::
6466

6567
#### Restore soft-deleted objects when versioning is enabled
6668

67-
To restore a soft-deleted blob when versioning is enabled, copy a previous version over the base blob. You can use the following method:
69+
If a storage account is configured to enable blob versioning, deleting a blob causes the current version of the blob to become the previous version. To restore a soft-deleted blob when versioning is enabled, copy a previous version over the base blob. You can use the following method:
6870

69-
- [copyFromUrl](/java/api/com.azure.storage.blob.specialized.blobclientbase)
71+
- [copyFromUrl](/java/api/com.azure.storage.blob.specialized.blobclientbase#method-summary)
7072

7173
This method restores the content and metadata of a soft-deleted blob and any associated soft-deleted snapshots. Calling this method for a blob that hasn't been deleted has no effect.
7274

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ To delete a blob, call the following method:
3434

3535
The following example deletes a blob:
3636

37-
:::code language="python" source="~/azure-storage-snippets/blobs/howto/python/blob-devguide-py/blob-devguide-blobs.py" id="Snippet_delete_blob":::
37+
:::code language="python" source="~/azure-storage-snippets/blobs/howto/python/blob-devguide-py/blob-devguide-delete-blobs.py" id="Snippet_delete_blob":::
3838

3939
If the blob has any associated snapshots, you must delete all of its snapshots to delete the blob. The following example deletes a blob and its snapshots:
4040

41-
:::code language="python" source="~/azure-storage-snippets/blobs/howto/python/blob-devguide-py/blob-devguide-blobs.py" id="Snippet_delete_blob_snapshots":::
41+
:::code language="python" source="~/azure-storage-snippets/blobs/howto/python/blob-devguide-py/blob-devguide-delete-blobs.py" id="Snippet_delete_blob_snapshots":::
4242

4343
To delete *only* the snapshots and not the blob itself, you can pass the parameter `delete_snapshots="only"`.
4444

@@ -61,17 +61,17 @@ To restore deleted blobs when versioning is disabled, call the following method:
6161

6262
This method restores the content and metadata of a soft-deleted blob and any associated soft-deleted snapshots. Calling this method for a blob that hasn't been deleted has no effect.
6363

64-
:::code language="python" source="~/azure-storage-snippets/blobs/howto/python/blob-devguide-py/blob-devguide-blobs.py" id="Snippet_restore_blob":::
64+
:::code language="python" source="~/azure-storage-snippets/blobs/howto/python/blob-devguide-py/blob-devguide-delete-blobs.py" id="Snippet_restore_blob":::
6565

6666
#### Restore soft-deleted objects when versioning is enabled
6767

68-
To restore a soft-deleted blob when versioning is enabled, copy a previous version over the base blob. You can use the following method:
68+
If a storage account is configured to enable blob versioning, deleting a blob causes the current version of the blob to become the previous version. To restore a soft-deleted blob when versioning is enabled, copy a previous version over the base blob. You can use the following method:
6969

7070
- [start_copy_from_url](/python/api/azure-storage-blob/azure.storage.blob.blobclient#azure-storage-blob-blobclient-start-copy-from-url)
7171

7272
The following code example gets the latest version of a deleted blob, and restores the latest version by copying it to the base blob:
7373

74-
:::code language="python" source="~/azure-storage-snippets/blobs/howto/python/blob-devguide-py/blob-devguide-blobs.py" id="Snippet_restore_blob_version":::
74+
:::code language="python" source="~/azure-storage-snippets/blobs/howto/python/blob-devguide-py/blob-devguide-delete-blobs.py" id="Snippet_restore_blob_version":::
7575

7676
## Resources
7777

@@ -86,7 +86,7 @@ The Azure SDK for Python contains libraries that build on top of the Azure REST
8686

8787
### Code samples
8888

89-
- [View code samples from this article (GitHub)](https://github.com/Azure-Samples/AzureStorageSnippets/blob/master/blobs/howto/python/blob-devguide-py/blob-devguide-blobs.py)
89+
- [View code samples from this article (GitHub)](https://github.com/Azure-Samples/AzureStorageSnippets/blob/master/blobs/howto/python/blob-devguide-py/blob-devguide-delete-blobs.py)
9090

9191
[!INCLUDE [storage-dev-guide-resources-python](../../../includes/storage-dev-guides/storage-dev-guide-resources-python.md)]
9292

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

Lines changed: 18 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,15 @@ To delete a blob, call either of these methods:
3535
- [DeleteIfExists](/dotnet/api/azure.storage.blobs.specialized.blobbaseclient.deleteifexists)
3636
- [DeleteIfExistsAsync](/dotnet/api/azure.storage.blobs.specialized.blobbaseclient.deleteifexistsasync)
3737

38-
The following example deletes a blob.
38+
The following example deletes a blob:
3939

40-
```csharp
41-
public static async Task DeleteBlob(BlobClient blob)
42-
{
43-
await blob.DeleteAsync();
44-
}
45-
```
40+
:::code language="csharp" source="~/azure-storage-snippets/blobs/howto/dotnet/BlobDevGuideBlobs/DeleteBlob.cs" id="Snippet_DeleteBlob":::
41+
42+
If the blob has any associated snapshots, you must delete all of its snapshots to delete the blob. The following example deletes a blob and its snapshots:
43+
44+
:::code language="csharp" source="~/azure-storage-snippets/blobs/howto/dotnet/BlobDevGuideBlobs/DeleteBlob.cs" id="Snippet_DeleteBlobSnapshots":::
45+
46+
To delete *only* the snapshots and not the blob itself, you can pass the parameter `DeleteSnapshotsOption.OnlySnapshots`.
4647

4748
## Restore a deleted blob
4849

@@ -64,69 +65,22 @@ To restore deleted blobs when versioning is not enabled, call either of the foll
6465

6566
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:
6667

67-
```csharp
68-
public static async Task UndeleteBlobs(BlobContainerClient container)
69-
{
70-
foreach (BlobItem blob in container.GetBlobs(BlobTraits.None, BlobStates.Deleted))
71-
{
72-
await container.GetBlockBlobClient(blob.Name).UndeleteAsync();
73-
}
74-
}
75-
```
68+
:::code language="csharp" source="~/azure-storage-snippets/blobs/howto/dotnet/BlobDevGuideBlobs/DeleteBlob.cs" id="Snippet_RestoreBlob":::
7669

7770
To restore a specific soft-deleted snapshot, first call the [Undelete](/dotnet/api/azure.storage.blobs.specialized.blobbaseclient.undelete) or [UndeleteAsync](/dotnet/api/azure.storage.blobs.specialized.blobbaseclient.undeleteasync) on the base blob, then copy the desired snapshot over the base blob. The following example restores a block blob to the most recently generated snapshot:
7871

79-
```csharp
80-
public static async Task RestoreSnapshots(BlobContainerClient container, BlobClient blob)
81-
{
82-
// Restore the deleted blob.
83-
await blob.UndeleteAsync();
84-
85-
// List blobs in this container that match prefix.
86-
// Include snapshots in listing.
87-
Pageable<BlobItem> blobItems = container.GetBlobs
88-
(BlobTraits.None, BlobStates.Snapshots, prefix: blob.Name);
89-
90-
// Get the URI for the most recent snapshot.
91-
BlobUriBuilder blobSnapshotUri = new BlobUriBuilder(blob.Uri)
92-
{
93-
Snapshot = blobItems
94-
.OrderByDescending(snapshot => snapshot.Snapshot)
95-
.ElementAtOrDefault(0)?.Snapshot
96-
};
97-
98-
// Restore the most recent snapshot by copying it to the blob.
99-
blob.StartCopyFromUri(blobSnapshotUri.ToUri());
100-
}
101-
```
72+
:::code language="csharp" source="~/azure-storage-snippets/blobs/howto/dotnet/BlobDevGuideBlobs/DeleteBlob.cs" id="Snippet_RestoreSnapshot":::
10273

10374
#### Restore soft-deleted blobs when versioning is enabled
10475

105-
To restore a soft-deleted blob when versioning is enabled, copy a previous version over the base blob. You can use either of the following methods:
76+
If a storage account is configured to enable blob versioning, deleting a blob causes the current version of the blob to become the previous version. To restore a soft-deleted blob when versioning is enabled, copy a previous version over the base blob. You can use either of the following methods:
10677

10778
- [StartCopyFromUri](/dotnet/api/azure.storage.blobs.specialized.blobbaseclient.startcopyfromuri)
10879
- [StartCopyFromUriAsync](/dotnet/api/azure.storage.blobs.specialized.blobbaseclient.startcopyfromuriasync)
10980

110-
```csharp
111-
public static void RestoreBlobsWithVersioning(BlobContainerClient container, BlobClient blob)
112-
{
113-
// List blobs in this container that match prefix.
114-
// Include versions in listing.
115-
Pageable<BlobItem> blobItems = container.GetBlobs
116-
(BlobTraits.None, BlobStates.Version, prefix: blob.Name);
117-
118-
// Get the URI for the most recent version.
119-
BlobUriBuilder blobVersionUri = new BlobUriBuilder(blob.Uri)
120-
{
121-
VersionId = blobItems
122-
.OrderByDescending(version => version.VersionId)
123-
.ElementAtOrDefault(0)?.VersionId
124-
};
125-
126-
// Restore the most recently generated version by copying it to the base blob.
127-
blob.StartCopyFromUri(blobVersionUri.ToUri());
128-
}
129-
```
81+
The following code example shows how to get the latest version of a deleted blob, and restore the latest version by copying it to the base blob:
82+
83+
:::code language="csharp" source="~/azure-storage-snippets/blobs/howto/dotnet/BlobDevGuideBlobs/DeleteBlob.cs" id="Snippet_RestoreBlobWithVersioning":::
13084

13185
## Resources
13286

@@ -139,6 +93,10 @@ The Azure SDK for .NET contains libraries that build on top of the Azure REST AP
13993
- [Delete Blob](/rest/api/storageservices/delete-blob) (REST API)
14094
- [Undelete Blob](/rest/api/storageservices/undelete-blob) (REST API)
14195

96+
### Code samples
97+
98+
- [View code samples from this article (GitHub)](https://github.com/Azure-Samples/AzureStorageSnippets/blob/master/blobs/howto/dotnet/BlobDevGuideBlobs/DeleteBlob.cs)
99+
142100
[!INCLUDE [storage-dev-guide-resources-dotnet](../../../includes/storage-dev-guides/storage-dev-guide-resources-dotnet.md)]
143101

144102
### See also

0 commit comments

Comments
 (0)