|
| 1 | +--- |
| 2 | +title: Backup and restore an Azure Managed CCF resource |
| 3 | +description: Learn to back up and restore an Azure Managed CCF resource |
| 4 | +services: managed-ccf |
| 5 | +author: pallabpaul |
| 6 | +ms.service: confidential-ledger |
| 7 | +ms.topic: how-to |
| 8 | +ms.date: 09/07/2023 |
| 9 | +ms.author: pallabpaul |
| 10 | +#Customer intent: As a developer, I want to know how to perform a backup and restore of my Managed CCF app so that I can can access backups of my app files and restore my app in another region in the case of a disaster recovery. |
| 11 | +--- |
| 12 | + |
| 13 | +# Perform a backup and restore |
| 14 | + |
| 15 | +In this article, you'll learn to perform backup of an Azure Managed CCF (Managed CCF) resource and restore it to create a copy of the original Managed CCF resource. Here are some of the use cases that warrant this capability: |
| 16 | + |
| 17 | +- A Managed CCF resource is an append only ledger at the core. It is impossible to delete few erroneous transactions without impacting the integrity of the ledger. To keep the data clean, a business could decide to recreate the resource sans the erroneous transactions. |
| 18 | +- A developer could add reference data into a Managed CCF resource and create a back of it. The developer can use the copy later to create a fresh Managed CCF resource and save time. |
| 19 | + |
| 20 | +This article uses the commands found at the [Managed CCF's REST API Docs](/rest/api/confidentialledger/managed-ccf). |
| 21 | + |
| 22 | +## Prerequisites |
| 23 | + |
| 24 | +- Install the [Azure CLI](/cli/azure/install-azure-cli). |
| 25 | +- An Azure Storage Account. |
| 26 | + |
| 27 | +## Setup |
| 28 | + |
| 29 | +### Generate an access token |
| 30 | + |
| 31 | +An access token is required to use the Managed CCF REST API. Execute the following command to generate an access token. |
| 32 | + |
| 33 | +> [!NOTE] |
| 34 | +> An access token has a finite lifetime after which it is unusable. Generate a new token if the API request fails due to a HTTP 401 Unauthorized error. |
| 35 | +
|
| 36 | +```bash |
| 37 | +az account get-access-token –subscription <subscription_id> |
| 38 | +``` |
| 39 | + |
| 40 | +### Generate a Shared Access Signature token |
| 41 | + |
| 42 | +The backup is stored in an Azure Storage Fileshare that is owned and controlled by you. The backup and restore API requests require a [Shared Access Signature](../storage/common/storage-sas-overview.md) token to grant temporary read and write access to the Fileshare. Follow these steps: |
| 43 | + |
| 44 | +> [!NOTE] |
| 45 | +> A Shared Access Signature(SAS) token has a finite lifetime after which it is unusable. We recommend using short lived tokens to avoid tokens being leaked into the public and misused. |
| 46 | +
|
| 47 | +1. Navigate to the Azure Storage Account where the backups will be stored. |
| 48 | +2. Navigate to the `Security + networking` -> `Shared access signature` blade. |
| 49 | +3. Generate a SAS token with the following configuration: |
| 50 | + |
| 51 | + :::image type="content" source="./media/how-to/cedr-sas-uri.png" lightbox="./media/how-to/cedr-sas-uri.png" alt-text="Screenshot of the Azure portal in a web browser, showing the required SAS Generation configuration."::: |
| 52 | +4. Save the `File service SAS URL`. |
| 53 | + |
| 54 | +## Backup |
| 55 | + |
| 56 | +### Create a backup |
| 57 | + |
| 58 | +Creating a backup of the Managed CCF resource creates a Fileshare in the storage account. This backup can be used to restore the Managed CCF resource at a later time. |
| 59 | + |
| 60 | +Follow these steps to perform a backup. |
| 61 | + |
| 62 | +1. [Generate and save a bearer token](#generate-an-access-token) generated for the subscription that your Managed CCF resource is located in. |
| 63 | +1. [Generate a SAS token](#generate-a-shared-access-signature-token) for the Storage Account to store the backup. |
| 64 | +1. Execute the following command to trigger a backup. You must supply a few parameters: |
| 65 | + - **subscription_id**: The subscription where the Managed CCF resource is deployed. |
| 66 | + - **resource_group**: The resource group name of the Managed CCF resource. |
| 67 | + - **app_name**: The name of the Managed CCF resource. |
| 68 | + - **sas_token**: The Shared Access Signature token. |
| 69 | + - **restore_region**: An optional parameter to indicate a region where the backup would be restored. It can be ignored if you expect to restore the backup in the same region as the Managed CCF resource. |
| 70 | + ```bash |
| 71 | + curl --request POST 'https://management.azure.com/subscriptions/<subscription_id>/resourceGroups/<resource_group>/providers/Microsoft.ConfidentialLedger/ManagedCCFs/<app_name>/backup?api-version=2023-06-28-preview' \ |
| 72 | + --header 'Authorization: Bearer <bearer_token>' \ |
| 73 | + --header 'Content-Type: application/json' \ |
| 74 | + --data-raw '{ |
| 75 | + "uri": "<sas_token>", |
| 76 | + "restoreRegion": "<restore_region>" |
| 77 | + }' |
| 78 | + ``` |
| 79 | +1. A Fileshare is created in the Azure Storage Account with the name `<mccf_app_name>-<timestamp>`. |
| 80 | + |
| 81 | +### Explore the backup files |
| 82 | + |
| 83 | +After the backup completes, you can view the files stored in your Azure Storage Fileshare. |
| 84 | + |
| 85 | +:::image type="content" source="./media/how-to/cedr-backup-file-share.png" lightbox="./media/how-to/cedr-backup-file-share.png" alt-text="Screenshot of the Azure portal in a web browser, showing a sample Fileshare folder structure."::: |
| 86 | + |
| 87 | +Refer to the following articles to explore the backup files. |
| 88 | + |
| 89 | +- [Understanding your Ledger and Snapshot Files](https://microsoft.github.io/CCF/main/operations/ledger_snapshot.html) |
| 90 | +- [Viewing your Ledger and Snapshot Files](https://microsoft.github.io/CCF/main/audit/python_library.html) |
| 91 | + |
| 92 | +## Restore |
| 93 | + |
| 94 | +### Create a Managed CCF resource using the backup files |
| 95 | + |
| 96 | +This restores the Managed CCF resource using a copy of the files in the backup Fileshare. The resource will be restored to the same state and transaction ID at the time of the backup. |
| 97 | + |
| 98 | +> [!IMPORTANT] |
| 99 | +> The restore will fail if the backup files are older than 90 days. |
| 100 | + |
| 101 | +> [!NOTE] |
| 102 | +> The original Managed CCF resource must be deleted before a restore is initiated. The restore command will fail if the original instance exists. [Delete your original Managed CCF resource](/cli/azure/confidentialledger/managedccfs?#az-confidentialledger-managedccfs-delete). |
| 103 | +> |
| 104 | +> The **app_name** should be the same as the original Managed CCF resource. |
| 105 | + |
| 106 | +Follow these steps to perform a restore. |
| 107 | + |
| 108 | +1. [Generate a Bearer token](#generate-an-access-token) for the subscription that the Managed CCF resource is located in. |
| 109 | +2. [Generate a SAS token](#generate-a-shared-access-signature-token) for the storage account that has the backup files. |
| 110 | +3. Execute the following command to trigger a restore. You must supply a few parameters. |
| 111 | + - **subscription_id**: The subscription where the Managed CCF resource is deployed. |
| 112 | + - **resource_group**: The resource group name of the Managed CCF resource. |
| 113 | + - **app_name**: The name of the Managed CCF resource. |
| 114 | + - **sas_token**: The Shared Access Signature token. |
| 115 | + - **restore_region**: An optional parameter to indicate a region where the backup would be restored. It can be ignored if you expect to restore the backup in the same region as the Managed CCF resource. |
| 116 | + - **fileshare_name**: The name of the Fileshare where the backup files are located. |
| 117 | + |
| 118 | + ```bash |
| 119 | + curl --request POST 'https://management.azure.com/subscriptions/<subscription_id>/resourceGroups/<resource_group>/providers/Microsoft.ConfidentialLedger/ManagedCCFs/<app_name>/restore?api-version=2023-06-28-preview' \ |
| 120 | + --header 'Authorization: Bearer <bearer_token>' \ |
| 121 | + --header 'Content-Type: application/json' \ |
| 122 | + --data-raw '{ |
| 123 | + "uri": "<sas_token>", |
| 124 | + "restoreRegion": "<restore_region>", |
| 125 | + "fileShareName": "<fileshare_name>" |
| 126 | + }' |
| 127 | + ``` |
| 128 | +1. At the end of the command, the Managed CCF resource is restored. |
| 129 | + |
| 130 | +## Next steps |
| 131 | + |
| 132 | +- [Azure Managed CCF overview](overview.md) |
| 133 | +- [Quickstart: Azure portal](quickstart-portal.md) |
| 134 | +- [Quickstart: Azure CLI](quickstart-python.md) |
0 commit comments