> ## Documentation Index
> Fetch the complete documentation index at: https://docs.cockroachlabs.com/llms.txt
> Use this file to discover all available pages before exploring further.

# ALTER BACKUP

The `ALTER BACKUP` statement allows for new KMS encryption keys to be applied to an existing chain of encrypted backups ([full](/docs/stable/take-full-and-incremental-backups.md#full-backups) and [incremental](/docs/stable/take-full-and-incremental-backups.md#incremental-backups)). Each `ALTER BACKUP` statement must include the new KMS encryption key with `NEW_KMS`, and use `WITH OLD_KMS` to refer to at least one of the KMS URIs that were originally used to encrypt the backup.

After an `ALTER BACKUP` statement successfully completes, subsequent [`BACKUP`](/docs/stable/backup), [`RESTORE`](/docs/stable/restore), and [`SHOW BACKUP`](/docs/stable/show-backup) statements can use any of the existing or new KMS URIs to decrypt the backup.

CockroachDB supports AWS, Azure, and Google Cloud KMS keys. For more detail on encrypted backups and restores, see [Take and Restore Encrypted Backups](/docs/stable/take-and-restore-encrypted-backups.md).

## Synopsis

![alter\_backup syntax diagram](https://mintcdn.com/cockroachlabs/VQ_w3c6MHYdiS7Tn/images/sql-diagrams/common/alter_backup.svg?fit=max\&auto=format\&n=VQ_w3c6MHYdiS7Tn\&q=85\&s=3570b8da01f9b73e2b9bb1bac6923169)

## Parameters

| Parameter | Description |
| - | - |
| `subdirectory` | The subdirectory containing the target **full** backup at the given `collectionURI`. |
| `LATEST` | The most recent backup at the given `collectionURI`. |
| `collectionURI` | The URI that holds the backup collection. |
| `ADD NEW_KMS` | Apply the new KMS encryption key to the target backup. |
| `WITH OLD_KMS` | Reference one of the existing KMS URI(s) originally used to encrypt the backup. |
| `kmsURI` | The [URI](/docs/stable/take-and-restore-encrypted-backups.md#uri-formats) for the KMS key. |

## Required privileges

* `ALTER BACKUP` can only be run by members of the [`admin` role](/docs/stable/security-reference/authorization#admin-role). By default, the `root` user belongs to the `admin` role.
* `ALTER BACKUP` requires full read and write permissions to the target cloud storage bucket.

The backup collection's URI does **not** require the [`admin` role](/docs/stable/security-reference/authorization#admin-role) when using `s3`, `azure`, or `gs` with [`specified`](/docs/stable/cloud-storage-authentication) credentials. The backup collection's URI **does** require the [`admin` role](/docs/stable/security-reference/authorization#admin-role) when using `s3`, `azure`, or `gs` with [`implicit`](/docs/stable/cloud-storage-authentication) credentials.

We recommend using [cloud storage](/docs/stable/use-cloud-storage.md).

## Examples

`ALTER BACKUP` will apply the new encryption information to the entire chain of backups ([full](/docs/stable/take-full-and-incremental-backups.md#full-backups) and [incremental](/docs/stable/take-full-and-incremental-backups.md#incremental-backups)).

> [!NOTE]
>
> When running `ALTER BACKUP` with a subdirectory, the statement must point to a [full backup](/docs/stable/take-full-and-incremental-backups.md#full-backups) in the backup collection.

See [Cloud Storage Authentication](/docs/stable/cloud-storage-authentication.md) for more detail on authenticating to your cloud storage bucket.

### Add an AWS KMS key to an encrypted backup

To add a new KMS key to the most recent backup:

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
ALTER BACKUP LATEST IN 's3://{BUCKET NAME}?AWS_ACCESS_KEY_ID={KEY ID}&AWS_SECRET_ACCESS_KEY={SECRET ACCESS KEY}'
    ADD NEW_KMS = 'aws:///{new-key}?AWS_ACCESS_KEY_ID={KEY ID}&AWS_SECRET_ACCESS_KEY={SECRET ACCESS KEY}&REGION={location}'
    WITH OLD_KMS = 'aws:///{old-key}?AWS_ACCESS_KEY_ID={KEY ID}&AWS_SECRET_ACCESS_KEY={SECRET ACCESS KEY}&REGION={location}';
```

To add a new KMS key to a specific backup, issue an `ALTER BACKUP` statement that points to the full backup:

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
ALTER BACKUP '2022/03/23-213101.37' IN 's3://{BUCKET NAME}?AWS_ACCESS_KEY_ID={KEY ID}&AWS_SECRET_ACCESS_KEY={SECRET ACCESS KEY}'
    ADD NEW_KMS = 'aws:///{new-key}?AWS_ACCESS_KEY_ID={KEY ID}&AWS_SECRET_ACCESS_KEY={SECRET ACCESS KEY}&REGION={location}'
    WITH OLD_KMS = 'aws:///{old-key}?AWS_ACCESS_KEY_ID={KEY ID}&AWS_SECRET_ACCESS_KEY={SECRET ACCESS KEY}&REGION={location}';
```

To list backup directories at a collection's URI, see [`SHOW BACKUP`](/docs/stable/show-backup).

### Add an Azure KMS key to an encrypted backup

To add a new KMS key to the most recent backup:

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
ALTER BACKUP LATEST IN 'azure-blob://{container name}?AUTH=specified&AZURE_ACCOUNT_NAME={account name}&AZURE_CLIENT_ID={client ID}&AZURE_CLIENT_SECRET={client secret}&AZURE_TENANT_ID={tenant ID}'
    ADD NEW_KMS = 'azure-kms:///{new key}/{new key version}?AZURE_TENANT_ID={tenant ID}&AZURE_CLIENT_ID={client ID}&AZURE_CLIENT_SECRET={client secret}&AZURE_VAULT_NAME={key vault name}'
    WITH OLD_KMS = 'azure-kms:///{old key}/{old key version}?AZURE_TENANT_ID={tenant ID}&AZURE_CLIENT_ID={client ID}&AZURE_CLIENT_SECRET={client secret}&AZURE_VAULT_NAME={key vault name}';
```

To add a new KMS key to a specific backup, issue an `ALTER BACKUP` statement that points to the full backup:

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
ALTER BACKUP '2023/03/14-203808.29' IN 'azure-blob://{container name}?AUTH=specified&AZURE_ACCOUNT_NAME={account name}&AZURE_CLIENT_ID={client ID}&AZURE_CLIENT_SECRET={client secret}&AZURE_TENANT_ID={tenant ID}'
    ADD NEW_KMS = 'azure-kms:///{new key}/{new key version}?AZURE_TENANT_ID={tenant ID}&AZURE_CLIENT_ID={client ID}&AZURE_CLIENT_SECRET={client secret}&AZURE_VAULT_NAME={key vault name}'
    WITH OLD_KMS = 'azure-kms:///{old key}/{old key version}?AZURE_TENANT_ID={tenant ID}&AZURE_CLIENT_ID={client ID}&AZURE_CLIENT_SECRET={client secret}&AZURE_VAULT_NAME={key vault name}';
```

To list backup directories at a collection's URI, see [`SHOW BACKUP`](/docs/stable/show-backup).

### Add a Google Cloud KMS key to an encrypted backup

To add a new KMS key to the most recent backup:

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
ALTER BACKUP LATEST IN 'gs://{BUCKET NAME}?AUTH=specified&CREDENTIALS={ENCODED KEY}'
    ADD NEW_KMS = 'gs:///projects/{project name}/locations/{location}/keyRings/{key ring name}/cryptoKeys/{new key}?AUTH=specified&CREDENTIALS={encoded key}'
    WITH OLD_KMS = 'gs:///projects/{project name}/locations/{location}/keyRings/{key ring name}/cryptoKeys/{old key}?AUTH=specified&CREDENTIALS={encoded key}';
```

To add a new KMS key to a specific backup, issue an `ALTER BACKUP` statement that points to the full backup:

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
ALTER BACKUP '2022/03/23-213101.37' IN 'gs://{BUCKET NAME}?AUTH=specified&CREDENTIALS={ENCODED KEY}'
    ADD NEW_KMS = 'gs:///projects/{project name}/locations/{location}/keyRings/{key ring name}/cryptoKeys/{new key}?AUTH=specified&CREDENTIALS={encoded key}'
    WITH OLD_KMS = 'gs:///projects/{project name}/locations/{location}/keyRings/{key ring name}/cryptoKeys/{old key}?AUTH=specified&CREDENTIALS={encoded key}';
```

To list backup directories at a collection's URI, see [`SHOW BACKUP`](/docs/stable/show-backup).

## See also

* [Take and Restore Encrypted Backups](/docs/stable/take-and-restore-encrypted-backups.md)
* [`BACKUP`](/docs/stable/backup)
* [`RESTORE`](/docs/stable/restore)
* [Use Cloud Storage](/docs/stable/use-cloud-storage.md)
