You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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).
440
440
441
441
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.
Copy file name to clipboardExpand all lines: articles/iot-hub/migrate-hub-state-cli.md
+36-6Lines changed: 36 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -82,7 +82,7 @@ Any IoT Hub property or configuration not listed here may not be exported or imp
82
82
83
83
## Export the state of an IoT hub
84
84
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.
86
86
87
87
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).
88
88
@@ -93,9 +93,21 @@ When you export the state of an IoT hub, you can choose which aspects to export.
93
93
|`--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. |
94
94
|`--state-file -f`| The path to the file where the state information will be written. |
95
95
|`--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. |
97
97
|`--resource-group -g`| The name of the resource group for the origin IoT hub. |
98
98
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
+
99
111
### Export endpoints
100
112
101
113
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
113
125
|`--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. |
114
126
|`--state-file -f`| The path to the exported state file. |
115
127
|`--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. |
117
129
|`--resource-group -g`| The name of the resource group for the destination IoT hub. |
118
130
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
+
119
143
### Create a new IoT Hub with state import
120
144
121
145
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
134
158
* Data residency
135
159
* Features
136
160
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.
138
162
139
163
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:
140
164
@@ -154,11 +178,17 @@ If you are migrating a device registry with many devices (for example, a few hun
154
178
| --------- | ------- |
155
179
|`--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. |
156
180
|`--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. |
158
182
|`--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. |
160
184
|`--origin-resource-group --og`| The name of the resource group for the origin IoT hub. |
161
185
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
+
162
192
## Troubleshoot a migration
163
193
164
194
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