Skip to content

Commit 4c6e25a

Browse files
committed
formatting, add examples
1 parent 2248c92 commit 4c6e25a

File tree

2 files changed

+37
-7
lines changed

2 files changed

+37
-7
lines changed

articles/iot-hub/iot-hub-bulk-identity-mgmt.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,6 @@ static string GetContainerSasUri(CloudBlobContainer container)
436436

437437
## Next steps
438438

439-
In this article, you learned how to perform bulk operations against the identity registry in an IoT hub. Many of these operations, including how to move devices from one hub to another, are used in the [Manage devices registered to the IoT hub section of How to Clone an IoT Hub](iot-hub-how-to-clone.md#managing-the-devices-registered-to-the-iot-hub).
439+
In this article, you learned how to perform bulk operations against the identity registry in an IoT hub. Many of these operations, including how to move devices from one hub to another, are used in the [Manage devices registered to the IoT hub section of How to Clone an IoT Hub](iot-hub-how-to-clone.md#manage-the-devices-registered-to-the-iot-hub).
440440

441441
The cloning article has a working sample associated with it, which is located in the IoT C# samples on this page: [Azure IoT hub service samples for C#](https://github.com/Azure/azure-iot-sdk-csharp/tree/main/iothub/service/samples/how%20to%20guides), with the project being ImportExportDevicesSample. You can download the sample and try it out; there are instructions in the [How to Clone an IoT Hub](iot-hub-how-to-clone.md) article.

articles/iot-hub/migrate-hub-state-cli.md

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ Any IoT Hub property or configuration not listed here may not be exported or imp
8282

8383
## Export the state of an IoT hub
8484

85-
Use the [az iot hub state export](/cli/azure/iot/hub/state#az-iot-hub-state-export) command to export the state of an IoT hub to a file.
85+
Use the [az iot hub state export](/cli/azure/iot/hub/state#az-iot-hub-state-export) command to export the state of an IoT hub to a JSON file.
8686

8787
If you want to run both the export and import steps in one command, refer to the section later in this article to [Migrate an IoT hub](#migrate-an-iot-hub).
8888

@@ -93,9 +93,21 @@ When you export the state of an IoT hub, you can choose which aspects to export.
9393
| `--aspects` | The state aspects to export. Specify one or more of the accepted values: **arm**, **configurations**, or **devices**. If this parameter is left out, then all three aspects will be exported. |
9494
| `--state-file -f` | The path to the file where the state information will be written. |
9595
| `--replace -r` | If this parameter is included, then the export command will overwrite the contents of the state file. |
96-
| `--hub-name -n`<br><br>**or**<br><br>`--login -l` | The name of the origin IoT hub (`-n`) or the connection string for the origin IoT hub (`-l`). If both are provided, then the connection string takes priority. |
96+
| `--hub-name -n`<br>**or**<br>`--login -l` | The name of the origin IoT hub (`-n`) or the connection string for the origin IoT hub (`-l`). If both are provided, then the connection string takes priority. |
9797
| `--resource-group -g` | The name of the resource group for the origin IoT hub. |
9898

99+
The following example exports all aspects of an IoT hub's state to a file named **myHub-state**:
100+
101+
```azurecli
102+
az iot hub state export --hub-name myHub --state-file ./myHub-state.json
103+
```
104+
105+
The following example exports only the devices and ARM aspects of an IoT hub's state, and overwrites the content of the existing file:
106+
107+
```azurecli
108+
az iot hub state export --hub-name myHub --state-file ./myHub-state.json --aspects arm devices --replace
109+
```
110+
99111
### Export endpoints
100112

101113
If you choose to export the Azure Resource Manager aspect of an IoT hub, the export command will retrieve the connection strings for any endpoints that have key-based authentication and include them in the output ARM template.
@@ -113,9 +125,21 @@ If you want to run both the export and import steps in one command, refer to the
113125
| `--aspects` | The state aspects to import. Specify one or more of the accepted values: **arm**, **configurations**, or **devices**. If this parameter is left out, then all three aspects will be imported. |
114126
| `--state-file -f` | The path to the exported state file. |
115127
| `--replace -r` | If this parameter is included, then the import command will delete the current state of the destination hub. |
116-
| `--hub-name -n`<br><br>**or**<br><br>`--login -l` | The name of the destination IoT hub (`-n`) or the connection string for the destination IoT hub (`-l`). If both are provided, then the connection string takes priority. |
128+
| `--hub-name -n`<br>**or**<br>`--login -l` | The name of the destination IoT hub (`-n`) or the connection string for the destination IoT hub (`-l`). If both are provided, then the connection string takes priority. |
117129
| `--resource-group -g` | The name of the resource group for the destination IoT hub. |
118130

131+
The following example imports all aspects to a new IoT hub, which will be created if it doesn't already exist:
132+
133+
```azurecli
134+
az iot hub state import --hub-name myNewHub --state-file ./myHub-state.json
135+
```
136+
137+
The following example imports only the devices and configurations aspects to a new IoT hub, which must exist already, and overwrites any existing devices and configurations:
138+
139+
```azurecli
140+
az iot hub state import --hub-name myNewHub --state-file ./myHub-state.json --aspects devices configurations --replace
141+
```
142+
119143
### Create a new IoT Hub with state import
120144

121145
You can use the `az iot hub state import` command to create a new IoT hub or to write to an existing IoT hub.
@@ -134,7 +158,7 @@ If the destination IoT hub already exists, then the `arm` aspect is not required
134158
* Data residency
135159
* Features
136160

137-
If the `--resource-group`
161+
If the `--resource-group` is specified in the import command and is different than IoT hub's current resource group, the hub will be moved.
138162

139163
If you include the `--replace` flag in the import command, then the following IoT hub aspects will be removed from the destination hub before the hub state is uploaded:
140164

@@ -154,11 +178,17 @@ If you are migrating a device registry with many devices (for example, a few hun
154178
| --------- | ------- |
155179
| `--aspects` | The state aspects to migrate. Specify one or more of the accepted values: **arm**, **configurations**, or **devices**. If this parameter is left out, then all three aspects will be migrated. |
156180
| `--replace -r` | If this parameter is included, then the migrate command will delete the current state of the destination hub. |
157-
| `--destination-hub --dh`<br><br>**or**<br><br>`--destination-hub-login --dl` | The name of the destination IoT hub (`--dh`) or the connection string for the destination IoT hub (`--dl`). If both are provided, then the connection string takes priority. |
181+
| `--destination-hub --dh`<br>**or**<br>`--destination-hub-login --dl` | The name of the destination IoT hub (`--dh`) or the connection string for the destination IoT hub (`--dl`). If both are provided, then the connection string takes priority. |
158182
| `--destination-resource-group --dg` | Name of the resource group for the destination IoT hub. |
159-
| `--origin-hub --oh`<br><br>**or**<br><br>`--origin-hub-login --ol` | The name of the origin IoT hub (`--oh`) or the connection string for the origin IoT hub (`--ol`). If both are provided, then the connection string takes priority. Use the connection string to avoid having to log in to the Azure CLI session. |
183+
| `--origin-hub --oh`<br>**or**<br>`--origin-hub-login --ol` | The name of the origin IoT hub (`--oh`) or the connection string for the origin IoT hub (`--ol`). If both are provided, then the connection string takes priority. Use the connection string to avoid having to log in to the Azure CLI session. |
160184
| `--origin-resource-group --og` | The name of the resource group for the origin IoT hub. |
161185

186+
The following example migrates all aspects of the origin hub to the destination hub, which will be created if it doesn't exist:
187+
188+
```azurecli
189+
az iot hub state migrate --origin-hub myHub --destination-hub myNewHub
190+
```
191+
162192
## Troubleshoot a migration
163193

164194
If you can't export or import devices or configurations, check that you have access to those properties. One way to verify this is by running the `az iot hub device-identity list` or `az iot hub configuration list` commands.

0 commit comments

Comments
 (0)