To create a snapshot of a Azure managed disk, you make a POST request with the block device ID of the managed disk. Using the snapshot ID created, you can list a snapshot or delete a snapshot of a managed disk.

Prerequisites

Procedure

  1. Assign the block device ID variable.
    block_device_id='<your_block_device_id>'
  2. Create a snapshot of the managed disk.
    curl -X POST \
      $url/iaas/api/block-devices/$block_device_id/operations/snapshots?apiVersion=$api_version \
      -H 'Content-Type: application/json' \
      -H "Authorization: Bearer $access_token" \
      -d '{
        "name": "example_name"
      }' | jq "."
    In addition to the required snapshot name, you can include optional snapshot properties that can be used independently or combined as in the following example.
    curl -X POST \
      $url/iaas/api/block-devices/$block_device_id/operations/snapshots?apiVersion=$api_version \
      -H 'Content-Type: application/json' \
      -H "Authorization: Bearer $access_token" \
      -d '{
        "name": "example_name"  
        "snapshotProperties": {
           "incremental": "true",
           "resourceGroupName": "newRG",
           "encryptionSetId" : "'"$encryption_key"'"
     },
      }' | jq "."
    • To create a snapshot that only consists of changes since the last snapshot, set incremental to true.
    • To specify a target resource group for the snapshot, include the resourceGroupName property. You can look up existing resource group names in the Azure portal, or specify a name for a new resource group, If not specified, Automation creates the snapshot in the same resource group as the block device by default.
    • To encrypt the snapshot with a customer-managed key, include the encryptionSetId property.
      To get the encryptionSetId property for a particular region ID, use the following API request:
      curl -X GET -H 'Content-Type: application/json' -H "Authorization: Bearer $access_token" $url/iaas/api/fabric-azure-disk-encryption-sets?regionId=$region_id&apiVersion=$api_version | jq "."
      Examine the response for the id as in the following example.
          {
            "name": "test-encryption-1.1",
            "id": "/subscriptions/b8ef63a7-a5e3-44fa-8745-1ead33fa1f25/resourceGroups/DISKRG67970/providers/Microsoft.Compute/diskEncryptionSets/test-encryption-1.1",
            "regionId": "eastus",
            "key": "key1234",
            "vault": "KeyVault1234"
          },
      Assign the encryption key variable.
      $encryption_key='/subscriptions/b8ef63a7-a5e3-44fa-8745-1ead33fa1f25/resourceGroups/DISKRG67970/providers/Microsoft.Compute/diskEncryptionSets/test-encryption-1.1'
  3. Examine the response for the selfLink value.
    {
      "progress": 0,
      "status": "INPROGRESS",
      "name": "Provisioning",
      "id": "example-selfLink-alphanumeric-string",
      "selfLink": "/iaas/api/request-tracker/example-selfLink-alphanumeric-string"
    }
  4. Assign the selfLink variable.
    selfLink_id='example-selfLink-alphanumeric-string'
  5. Use the selfLink to track the progress of the snapshot creation.
    curl -X GET -H 'Content-Type: application/json' -H "Authorization: Bearer $access_token" $url/iaas/api/request-tracker/$selfLink_id?apiVersion=$api_version | jq "."
    
    The response indicates if the snapshot is successful.
    {
      "progress": 100,
      "message": "success",
      "status": "FINISHED",
      "resources": [
        "/iaas/api/block-devices/your-block-device-id"
      ],
      ...
    }
  6. To get a snapshot ID, list all snapshots.
    curl -X GET -H 'Content-Type: application/json' -H "Authorization: Bearer $access_token" $url/iaas/api/block-devices/$block_device_id/snapshots?apiVersion=$api_version | jq "."
    
    If you created multiple snapshots, the response lists multiple snapshot IDs.
  7. Examine the response and select a snapshot ID to assign as a variable.
    snapshot_id=<your_snapshot_id_1>
  8. (Optional) You can list an individual snapshot.
    curl -X GET -H 'Content-Type: application/json' -H "Authorization: Bearer $access_token" $url/iaas/api/block-devices/$block_device_id/snapshots/$snapshot_id?apiVersion=$api_version | jq "."
    
  9. (Optional) You can delete a snapshot.
    curl -X DELETE -H 'Content-Type: application/json' -H "Authorization: Bearer $access_token" $url/iaas/api/block-devices/$block_device_id/snapshots/$snapshot_id?apiVersion=$api_version | jq "."
    

Example: Create snapshots of a managed disk

With the block device ID, create multiple snapshots of a managed disk.

$ url='https://appliance.domain.com'
$ api_version='2021-07-15'
$ block_device_id='41d600c2-429e-4c90-98d4-638e77724101'

Create a snapshot of the managed disk.

$ curl -X POST \
  $url/iaas/api/block-devices/$block_device_id/operations/snapshots?apiVersion=$api_version \
  -H 'Content-Type: application/json' \
  -H "Authorization: Bearer $access_token" \
  -d '{
    "name": "demo-snapshot-1"
  }' | jq "."

The response provides a selfLink to the request.

{
  "progress": 0,
  "status": "INPROGRESS",
  "name": "Provisioning",
  "id": "66123d15-8e5a-42b0-a0b4-e9ed8e21180a",
  "selfLink": "/iaas/api/request-tracker/66123d15-8e5a-42b0-a0b4-e9ed8e21180a"
}

Assign the selfLink ID variable.

$ selfLink_id='66123d15-8e5a-42b0-a0b4-e9ed8e21180a'

Track the progress of the request.

$ curl -X GET -H 'Content-Type: application/json' -H "Authorization: Bearer $access_token" $url/iaas/api/request-tracker/$selfLink_id?apiVersion=$api_version | jq "."

Create a second snapshot of the managed disk.

$ curl -X POST \
  $url/iaas/api/block-devices/$block_device_id/operations/snapshots?apiVersion=$api_version \
  -H 'Content-Type: application/json' \
  -H "Authorization: Bearer $access_token" \
  -d '{
    "name": "demo-snapshot-2"
  }' | jq "."

List all the snapshots of the managed disk.

$ curl -X GET -H 'Content-Type: application/json' -H "Authorization: Bearer $access_token" $url/iaas/api/block-devices/$block_device_id/snapshots?apiVersion=$api_version | jq "."

Examine the response to see all snapshot IDs.

[
  {
    "name": "demo-snapshot-1",
    "snapshotProperties": {
      "incremental": "false"
    },
    "id": "38348991-00a1-48be-80d6-00d62afcd280",
    "createdAt": "2022-04-02",
    "updatedAt": "2022-04-02",
    "owner": "[email protected]",
    "organizationId": "1b6fd77b-f5d9-466b-88d3-97c0d9eb70c9",
    "orgId": "1b6fd77b-f5d9-466b-88d3-97c0d9eb70c9",
    "_links": {
      "self": {
        "href": "/iaas/api/block-devices/41d600c2-429e-4c90-98d4-638e77724101/snapshots/38348991-00a1-48be-80d6-00d62afcd280"
      }
    }
  },
  {
    "name": "demo-snapshot-2",
    "snapshotProperties": {
      "incremental": "false"
    },
    "id": "80407f78-7f90-4d9f-83f4-10d3a1e982ac",
    "createdAt": "2022-04-02",
    "updatedAt": "2022-04-02",
    "owner": "[email protected]",
    "organizationId": "1b6fd77b-f5d9-466b-88d3-97c0d9eb70c9",
    "orgId": "1b6fd77b-f5d9-466b-88d3-97c0d9eb70c9",
    "_links": {
      "self": {
        "href": "/iaas/api/block-devices/41d600c2-429e-4c90-98d4-638e77724101/snapshots/80407f78-7f90-4d9f-83f4-10d3a1e982ac"
      }
    }
  }
]

Assign a snapshot ID variable.

$ snapshot_id='80407f78-7f90-4d9f-83f4-10d3a1e982ac'

List information about the snapshot.

$ curl -X GET -H 'Content-Type: application/json' -H "Authorization: Bearer $access_token" $url/iaas/api/block-devices/$block_device_id/snapshots/$snapshot_id?apiVersion=$api_version | jq "."

The response shows information about the single snapshot.

{
  "name": "demo-snapshot-2",
  "snapshotProperties": {
    "incremental": "false"
  },
  "id": "80407f78-7f90-4d9f-83f4-10d3a1e982ac",
  "createdAt": "2022-04-02",
  "updatedAt": "2022-04-02",
  "owner": "[email protected]",
  "organizationId": "1b6fd77b-f5d9-466b-88d3-97c0d9eb70c9",
  "orgId": "1b6fd77b-f5d9-466b-88d3-97c0d9eb70c9",
  "_links": {
    "self": {
      "href": "/iaas/api/block-devices/41d600c2-429e-4c90-98d4-638e77724101/snapshots/80407f78-7f90-4d9f-83f4-10d3a1e982ac"
    }
  }
}