# How to delete undeleted blobs on Azure

**URL:** <https://forum.rclone.org/t/how-to-delete-undeleted-blobs-on-azure/43911>\
**Category:** Help and Support\
**Created:** [January 9, 2024, 2:17pm UTC](https://forum.rclone.org/t/how-to-delete-undeleted-blobs-on-azure/43911 "2024-01-09T14:17:29Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![docuinn](https://forum.rclone.org/letter_avatar_proxy/v4/letter/d/eb8c5e/32.png) [@docuinn](https://forum.rclone.org/u/docuinn)\
**Post date:** [January 9, 2024, 2:17pm UTC](https://forum.rclone.org/t/how-to-delete-undeleted-blobs-on-azure/43911/1 "2024-01-09T14:17:30Z")

</div>

#### What is the problem you are having with rclone?

When running rclone delete on an Azure container that contains previously undeleted blobs, I get the following error:

RESPONSE 409: 409 This operation is not permitted because the blob has snapshots.  
ERROR CODE: SnapshotsPresent

The container has soft delete, but no versioning. The snapshots are down to the soft delete process - the blobs can be removed via the portal, but only if 'Also delete blob snapshots' is ticked. Is it possible to replicate this in rclone delete?

#### Run the command 'rclone version' and share the full output of the command.

rclone v1.65.1

- os/version: darwin 13.1 (64 bit)
- os/kernel: 22.2.0 (arm64)
- os/type: darwin
- os/arch: arm64 (ARMv8 compatible)
- go/version: go1.21.5
- go/linking: dynamic
- go/tags: cmount

#### Which cloud storage system are you using? (eg Google Drive)

Azure

#### The command you were trying to run (eg `rclone copy /tmp remote:tmp`)

rclone delete az:\<container\_name\>

#### Please run 'rclone config redacted' and share the full output. If you get command not found, please make sure to update rclone.

```auto
[az]
type = azureblob
env_auth = false
sas_url = XXX

```

#### A log from the command that you were trying to run with the `-vv` flag

```auto
RESPONSE 409: 409 This operation is not permitted because the blob has snapshots.
ERROR CODE: SnapshotsPresent

```

Thank you!

---

<div class="post-metadata">

**Author:** ![ncw](https://forum.rclone.org/user_avatar/forum.rclone.org/ncw/32/18_2.png) [@ncw](https://forum.rclone.org/u/ncw)\
**Post date:** [January 9, 2024, 3:09pm UTC](https://forum.rclone.org/t/how-to-delete-undeleted-blobs-on-azure/43911/2 "2024-01-09T15:09:41Z")

</div>

> [@docuinn](#):
>
> `SnapshotsPresent`

It looks like [from the azure blob docs](https://learn.microsoft.com/en-us/rest/api/storageservices/delete-blob?tabs=microsoft-entra-id#request-headers) that this is possible

> `x-ms-delete-snapshots: {include, only}` Required if the blob has associated snapshots. Specify one of the following options:
> 
> - `include`: Delete the base blob and all of its snapshots.
> - `only`: Delete only the blob's snapshots, and not the blob itself.
> 
> Specify this header only for a request against the base blob resource. If this header is specified on a request to delete an individual snapshot, Blob Storage returns status code 400 (Bad Request).
> 
> If this header isn't specified on the request and the blob has associated snapshots, Blob Storage returns status code 409 (Conflict).

This would be easy to implement. There is even a little hint in the source

> <https://github.com/rclone/rclone/blob/1045f5412804c73fb729e7d1ab0a99713aef75f9/backend/azureblob/azureblob.go#L2359-L2362>

This should probably be controlled by a flag/config option (say `--azureblob-delete-snapshots`) this could have 3 potential states:

1. `error`: give 409 error like it does now when trying to delete blob with snapshots
2. `only`: remove only the blob and not the snapshots
3. `include`: remove the blob and the snapshots

Whether we need the 1. option I don't know and what the default should be I don't know.

What do you think?

Is there any prior art from microsoft tools (azcopy or similar) that we can learn from to make the tools consistent?

---

<div class="post-metadata">

**Author:** ![docuinn](https://forum.rclone.org/letter_avatar_proxy/v4/letter/d/eb8c5e/32.png) [@docuinn](https://forum.rclone.org/u/docuinn)\
**Post date:** [January 9, 2024, 3:21pm UTC](https://forum.rclone.org/t/how-to-delete-undeleted-blobs-on-azure/43911/3 "2024-01-09T15:21:03Z")

</div>

Thanks for the quick response. Your proposed solution sounds fine to me, default to stay as-is and an option via flag to delete snapshots.

For comparison, azcopy has a flag --delete-snapshots=include

> --delete-snapshots (string) By default, the delete operation fails if a blob has snapshots. Specify 'include' to remove the root blob and all its snapshots; alternatively specify 'only' to remove only the snapshots but keep the root blob.

Reference:

> **[azcopy remove](https://learn.microsoft.com/en-us/azure/storage/common/storage-ref-azcopy-remove)**
>
> This article provides reference information for the azcopy remove command.

---

<div class="post-metadata">

**Author:** ![ncw](https://forum.rclone.org/user_avatar/forum.rclone.org/ncw/32/18_2.png) [@ncw](https://forum.rclone.org/u/ncw)\
**Post date:** [January 12, 2024, 9:48am UTC](https://forum.rclone.org/t/how-to-delete-undeleted-blobs-on-azure/43911/4 "2024-01-12T09:48:36Z")

</div>

I've had a go at implementing this - please give it a go 🙂

[v1.66.0-beta.7603.52e4e150d.fix-azure-delete-snapshots](https://beta.rclone.org/branch/fix-azure-delete-snapshots/v1.66.0-beta.7603.52e4e150d.fix-azure-delete-snapshots/) on branch [fix-azure-delete-snapshots](https://github.com/rclone/rclone/tree/fix-azure-delete-snapshots) (uploaded in 15-30 mins)

#### --azureblob-delete-snapshots

Set to specify how to deal with snapshots on blob deletion.

Properties:

- Config: delete\_snapshots
- Env Var: RCLONE\_AZUREBLOB\_DELETE\_SNAPSHOTS
- Type: string
- Required: false
- Choices:
  - ""
    - By default, the delete operation fails if a blob has snapshots

  - "include"
    - Specify 'include' to remove the root blob and all its snapshots

  - "only"
    - Specify 'only' to remove only the snapshots but keep the root blob.

---

<div class="post-metadata">

**Author:** ![docuinn](https://forum.rclone.org/letter_avatar_proxy/v4/letter/d/eb8c5e/32.png) [@docuinn](https://forum.rclone.org/u/docuinn)\
**Post date:** [January 12, 2024, 11:39am UTC](https://forum.rclone.org/t/how-to-delete-undeleted-blobs-on-azure/43911/5 "2024-01-12T11:39:00Z")

</div>

I tried the beta, and both the "only" and "include" options work exactly as expected (and default fails with the same error as before). This is excellent, thanks so much for the quick fix!

---

<div class="post-metadata">

**Author:** ![ncw](https://forum.rclone.org/user_avatar/forum.rclone.org/ncw/32/18_2.png) [@ncw](https://forum.rclone.org/u/ncw)\
**Post date:** [January 13, 2024, 2:29pm UTC](https://forum.rclone.org/t/how-to-delete-undeleted-blobs-on-azure/43911/6 "2024-01-13T14:29:16Z")

</div>

Thanks for testing 🙂

I've merged this to master now which means it will be in [the latest beta](https://beta.rclone.org/) in 15-30 minutes and released in v1.66

---

<div class="post-metadata">

**Author:** ![system](https://forum.rclone.org/uploads/default/original/2X/3/39ad3235f6ffec76ccd0c81616bd55697b4c300d.png) [@system](https://forum.rclone.org/u/system)\
**Post date:** [January 16, 2024, 2:29pm UTC](https://forum.rclone.org/t/how-to-delete-undeleted-blobs-on-azure/43911/7 "2024-01-16T14:29:56Z")

</div>

Closed on January 16, 2024, 2:29pm UTC

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.
