---
layout: docs
page_title: Restore soft deleted data
description: >-
   Revert soft deletes to restore versioned key/value data in the kv v2 plugin.
---

# Restore soft deleted key/value data

You can restore data from soft deletes in the `kv` v2 plugin as long as the
`destroyed` metadata field for the targeted version is `false`.

<Tip title="Assumptions">

- You have [set up a `kv` v2 plugin](/vault/docs/secrets/kv/kv-v2/setup). 
- Your authentication token has `create` and `update` permissions for the `kv`
  v2 plugin.

</Tip>

<Tabs>

<Tab heading="CLI" group="cli">

Use [`vault kv undelete`](/vault/docs/command/kv/undelete) with the `-versions`
flag to restore soft deleted version of key/value data:

```shell-session
$ vault kv undelete             \
   -mount <mount_path>          \
   -versions <target_versions>  \
   <secret_path>
```

For example:

<CodeBlockConfig hideClipboard="true">

```shell-session
$ vault kv undelete -mount shared -versions 1,4 dev/square-api

Success! Data deleted (if it existed) at: shared/data/dev/square-api
```

</CodeBlockConfig>

The `deletion_time` metadata field for versions 1 and 4 is now `n/a`:

<CodeBlockConfig hideClipboard="true" highlight="22,31">

```shell-session
$ vault kv metadata get -mount shared dev/square-api

======== Metadata Path ========
shared/metadata/dev/square-api

========== Metadata ==========
Key                     Value
---                     -----
cas_required            false
created_time            2024-11-13T21:51:50.898782695Z
current_version         4
custom_metadata         <nil>
delete_version_after    0s
max_versions            5
oldest_version          0
updated_time            2024-11-14T22:32:42.29534643Z

====== Version 1 ======
Key              Value
---              -----
created_time     2024-11-13T21:51:50.898782695Z
deletion_time    n/a
destroyed        false

...

====== Version 4 ======
Key              Value
---              -----
created_time     2024-11-14T22:32:42.29534643Z
deletion_time    n/a
destroyed        false
```

</CodeBlockConfig>


</Tab>

<Tab heading="GUI" group="gui">

@include 'gui-instructions/plugins/kv/open-overview.mdx'

- Select the **Secret** tab.
- Select the appropriate data version from the **Version** dropdown.
- Click **Undelete**.

![Partial screenshot of the Vault GUI showing the deleted version message](/img/gui/kv/undelete-data.png)

</Tab>

<Tab heading="API" group="api">

Make a `POST` call to
[`/{plugin_mount_path}/undelete/{secret_path}`](/vault/api-docs/secret/kv/kv-v2#undelete-secret-versions)
with the data versions you want to restore:

```shell-session
$ curl                                       \
   --request POST                            \
   --header "X-Vault-Token: ${VAULT_TOKEN}"  \
   --data '{"versions":[<target_versions>]}  \
   ${VAULT_ADDR}/v1/<plugin_mount_path>/undelete/<secret_path>
```

For example:

<CodeBlockConfig hideClipboard="true">

```shell-session
$ curl                                       \
    --request POST                           \
    --header "X-Vault-Token: ${VAULT_TOKEN}" \
    --data '{"versions":[5,8]}'              \
    ${VAULT_ADDR}/v1/shared/undelete/dev/square-api | jq

```

`/{plugin_mount_path}/undelete/{secret_path}` does not return data on success.

</CodeBlockConfig>

</Tab>

</Tabs>