|
| 1 | +# Azure CLI Migration Module |
| 2 | + |
| 3 | +This module provides server discovery and replication capabilities for Azure resources and workloads through Azure CLI commands, with special focus on Azure Local (Azure Stack HCI) migrations. |
| 4 | + |
| 5 | +# Azure CLI MCC Extension # |
| 6 | +The Azure CLI extension for managing [Azure Migrate](https://aka.ms/azure-migrate) resources. |
| 7 | + |
| 8 | +## Install ## |
| 9 | +You can install the extension by running: |
| 10 | +``` sh |
| 11 | +az extension add --name migrate |
| 12 | +``` |
| 13 | + |
| 14 | +## Usage ## |
| 15 | +``` sh |
| 16 | +az migrate --help |
| 17 | +``` |
| 18 | + |
| 19 | +## Uninstall ## |
| 20 | +You can see if the extension is installed by running `az --version` or `az extension list`. You can remove the extension by running: |
| 21 | +``` sh |
| 22 | +az extension remove --name migrate |
| 23 | +``` |
| 24 | + |
| 25 | + |
| 26 | +## Features |
| 27 | + |
| 28 | +- **Server discovery**: Discover servers from various sources |
| 29 | +- **Replication management**: Initialize and create new replications for supported workloads |
| 30 | + |
| 31 | +## Prerequisites |
| 32 | + |
| 33 | +- Azure CLI 2.0+ |
| 34 | +- Valid Azure subscription |
| 35 | +- Appropriate permissions for migration operations |
| 36 | +- For Azure Local: Azure Stack HCI environment with proper networking |
| 37 | + |
| 38 | +## Command Overview |
| 39 | + |
| 40 | +The Azure CLI migrate module provides the following commands: |
| 41 | + |
| 42 | +### Server Discovery |
| 43 | +```bash |
| 44 | +# Get discovered servers |
| 45 | +az migrate get-discovered-server --resource-group myRG --project-name myProject |
| 46 | +# Create server replication |
| 47 | +az migrate server create-replication --resource-group myRG --project-name myProject --target-vm-name myVM --target-resource-group targetRG --target-network targetNet |
| 48 | + |
| 49 | +# Show replication status |
| 50 | +az migrate server show-replication-status --resource-group myRG --project-name myProject --vm-name myVM |
| 51 | + |
| 52 | +# Update replication properties |
| 53 | +az migrate server update-replication --resource-group myRG --project-name myProject --vm-name myVM |
| 54 | + |
| 55 | +# Check cross-platform environment |
| 56 | +az migrate server check-environment |
| 57 | +``` |
| 58 | +### Azure Local (Stack HCI) Migration Commands |
| 59 | +```bash |
| 60 | +# Initialize Azure Local replication infrastructure |
| 61 | +az migrate local init --resource-group myRG --project-name myProject |
| 62 | + |
| 63 | +# Create disk mapping for fine-grained control |
| 64 | +az migrate local create-disk-mapping --disk-id "disk001" --is-os-disk --size-gb 64 --format-type VHDX |
| 65 | + |
| 66 | +# Create NIC mapping for network configuration |
| 67 | +az migrate local create-nic-mapping --nic-id "nic001" \ |
| 68 | + --target-virtual-switch-id "/subscriptions/xxx/resourceGroups/xxx/providers/Microsoft.AzureStackHCI/logicalnetworks/network001" |
| 69 | + |
| 70 | +# Create basic replication |
| 71 | +az migrate local create-replication --resource-group myRG --project-name myProject \ |
| 72 | + --server-index 0 --target-vm-name migratedVM \ |
| 73 | + --target-storage-path-id "/subscriptions/xxx/providers/Microsoft.AzureStackHCI/storageContainers/container001" \ |
| 74 | + --target-virtual-switch-id "/subscriptions/xxx/providers/Microsoft.AzureStackHCI/logicalnetworks/network001" \ |
| 75 | + --target-resource-group-id "/subscriptions/xxx/resourceGroups/targetRG" |
| 76 | + |
| 77 | +# Create replication with custom disk and NIC mappings |
| 78 | +az migrate local create-replication-with-mappings --resource-group myRG --project-name myProject \ |
| 79 | + --discovered-machine-id "/subscriptions/xxx/machines/machine001" \ |
| 80 | + --target-vm-name migratedVM \ |
| 81 | + --target-storage-path-id "/subscriptions/xxx/providers/Microsoft.AzureStackHCI/storageContainers/container001" \ |
| 82 | + --target-resource-group-id "/subscriptions/xxx/resourceGroups/targetRG" \ |
| 83 | + --disk-mappings '[{"DiskID": "disk001", "IsOSDisk": true, "Size": 64, "Format": "VHDX"}]' \ |
| 84 | + --nic-mappings '[{"NicID": "nic001", "TargetVirtualSwitchId": "/subscriptions/xxx/logicalnetworks/network001"}]' |
| 85 | + |
| 86 | +# Get replication job details |
| 87 | +az migrate local get-job --resource-group myRG --project-name myProject --job-id "job-12345" |
| 88 | + |
| 89 | +# Get Azure Local specific job |
| 90 | +az migrate local get-azure-local-job --resource-group myRG --project-name myProject --job-id "job-12345" |
| 91 | + |
| 92 | +# Start migration (planned failover) |
| 93 | +az migrate local start-migration --target-object-id "/subscriptions/xxx/replicationProtectedItems/item001" \ |
| 94 | + --turn-off-source-server |
| 95 | + |
| 96 | +# Remove replication after successful migration |
| 97 | +az migrate local remove-replication --target-object-id "/subscriptions/xxx/replicationProtectedItems/item001" |
| 98 | +``` |
| 99 | + |
| 100 | +### Authentication Management |
| 101 | +```bash |
| 102 | +# Check Azure authentication status |
| 103 | +az migrate auth check |
| 104 | + |
| 105 | +# Login to Azure (interactive) |
| 106 | +az migrate auth login |
| 107 | + |
| 108 | +# Login with device code |
| 109 | +az migrate auth login --device-code |
| 110 | + |
| 111 | +# Login with service principal |
| 112 | +az migrate auth login --app-id "app-id" --secret "secret" --tenant-id "tenant-id" |
| 113 | + |
| 114 | +# Set Azure context |
| 115 | +az migrate auth set-context --subscription-id "00000000-0000-0000-0000-000000000000" |
| 116 | + |
| 117 | +# Show current context |
| 118 | +az migrate auth show-context |
| 119 | + |
| 120 | +# Logout |
| 121 | +az migrate auth logout |
| 122 | +``` |
| 123 | + |
| 124 | +### PowerShell Module Management |
| 125 | +```bash |
| 126 | +# Check PowerShell module availability |
| 127 | +az migrate powershell check-module --module-name Az.Migrate |
| 128 | + |
| 129 | +# Update PowerShell modules |
| 130 | +az migrate powershell update-modules --modules Az.Migrate |
| 131 | +``` |
| 132 | + |
| 133 | +## Architecture |
| 134 | + |
| 135 | +The migration module consists of several key components: |
| 136 | + |
| 137 | +1. **Cross-Platform PowerShell Integration**: Executes PowerShell cmdlets across Windows, Linux, and macOS |
| 138 | +2. **Azure Local Migration**: Specialized support for Azure Stack HCI migration scenarios |
| 139 | +3. **Authentication Management**: Azure authentication and context management |
| 140 | +4. **Server Discovery and Replication**: Discovery and replication of source machines |
| 141 | + |
| 142 | +## Common Workflows |
| 143 | + |
| 144 | +### Setting up Azure Local Migration |
| 145 | + |
| 146 | +```bash |
| 147 | +# 1. Check prerequisites |
| 148 | +az migrate check-prerequisites |
| 149 | + |
| 150 | +# 2. Set up environment with PowerShell |
| 151 | +az migrate setup-env --install-powershell |
| 152 | + |
| 153 | +# 3. Authenticate to Azure |
| 154 | +az migrate auth login |
| 155 | + |
| 156 | +# 4. Set subscription context |
| 157 | +az migrate auth set-context --subscription-id "your-subscription-id" |
| 158 | + |
| 159 | +# 5. Verify setup |
| 160 | +az migrate verify-setup --resource-group "migration-rg" --project-name "azure-local-migration" |
| 161 | + |
| 162 | +# 6. Initialize Azure Local replication infrastructure |
| 163 | +az migrate local init \ |
| 164 | + --resource-group "migration-rg" \ |
| 165 | + --project-name "azure-local-migration" |
| 166 | + |
| 167 | +# 7. List discovered servers |
| 168 | +az migrate server list-discovered \ |
| 169 | + --resource-group "migration-rg" \ |
| 170 | + --project-name "azure-local-migration" \ |
| 171 | + --source-machine-type VMware |
| 172 | + |
| 173 | +# 8. Create replication for a specific server |
| 174 | +az migrate local create-replication \ |
| 175 | + --resource-group "migration-rg" \ |
| 176 | + --project-name "azure-local-migration" \ |
| 177 | + --server-index 0 \ |
| 178 | + --target-vm-name "WebServer-Migrated" \ |
| 179 | + --target-storage-path-id "/subscriptions/xxx/providers/Microsoft.AzureStackHCI/storageContainers/migration-storage" \ |
| 180 | + --target-virtual-switch-id "/subscriptions/xxx/providers/Microsoft.AzureStackHCI/logicalnetworks/migration-network" \ |
| 181 | + --target-resource-group-id "/subscriptions/xxx/resourceGroups/azure-local-vms" |
| 182 | + |
| 183 | +# 9. Monitor replication progress |
| 184 | +az migrate local get-job --resource-group "migration-rg" --project-name "azure-local-migration" --job-id "job-id" |
| 185 | + |
| 186 | +# 10. Start migration when ready |
| 187 | +az migrate local start-migration --target-object-id "replication-id" --turn-off-source-server |
| 188 | + |
| 189 | +# 11. Monitor migration job |
| 190 | +az migrate local get-azure-local-job --resource-group "migration-rg" --project-name "azure-local-migration" --job-id "job-id" |
| 191 | +``` |
| 192 | + |
| 193 | +### Setting up Server Discovery and Replication |
| 194 | + |
| 195 | +```bash |
| 196 | +# 1. Check prerequisites and setup |
| 197 | +az migrate check-prerequisites |
| 198 | +az migrate setup-env --install-powershell |
| 199 | + |
| 200 | +# 2. Authenticate and set context |
| 201 | +az migrate auth login |
| 202 | +az migrate auth set-context --subscription-id "your-subscription-id" |
| 203 | + |
| 204 | +# 3. Verify setup |
| 205 | +az migrate verify-setup --resource-group "migration-rg" --project-name "server-migration-2025" |
| 206 | + |
| 207 | +# 4. List discovered servers |
| 208 | +az migrate server list-discovered --resource-group "migration-rg" --project-name "server-migration-2025" --source-machine-type VMware |
| 209 | + |
| 210 | +# 5. Find specific servers |
| 211 | +az migrate server find-by-name --resource-group "migration-rg" --project-name "server-migration-2025" --display-name "WebServer" |
| 212 | + |
| 213 | +# 6. Create server replication |
| 214 | +az migrate server create-replication --resource-group "migration-rg" --project-name "server-migration-2025" --target-vm-name "WebServer-Azure" --target-resource-group "target-rg" --target-network "target-vnet" |
| 215 | + |
| 216 | +# 7. Monitor replication status |
| 217 | +az migrate server show-replication-status --resource-group "migration-rg" --project-name "server-migration-2025" --vm-name "WebServer-Azure" |
| 218 | +``` |
| 219 | + |
| 220 | +## PowerShell Integration |
| 221 | + |
| 222 | +This module provides Azure CLI equivalents to PowerShell Az.Migrate cmdlets: |
| 223 | + |
| 224 | +| PowerShell Cmdlet | Azure CLI Command | |
| 225 | +|-------------------|-------------------| |
| 226 | +| `Initialize-AzMigrateLocalReplicationInfrastructure` | `az migrate local init` | |
| 227 | +| `New-AzMigrateLocalServerReplication` | `az migrate local create-replication` | |
| 228 | +| `New-AzMigrateLocalDiskMappingObject` | `az migrate local create-disk-mapping` | |
| 229 | +| `New-AzMigrateLocalNicMappingObject` | `az migrate local create-nic-mapping` | |
| 230 | +| `Start-AzMigrateLocalServerMigration` | `az migrate local start-migration` | |
| 231 | +| `Remove-AzMigrateLocalServerReplication` | `az migrate local remove-replication` | |
| 232 | +| `Get-AzMigrateLocalJob` | `az migrate local get-azure-local-job` | |
| 233 | +| `Get-AzMigrateDiscoveredServer` | `az migrate server list-discovered` | |
| 234 | +| `New-AzMigrateServerReplication` | `az migrate server create-replication` | |
| 235 | +| `Get-AzMigrateServerReplication` | `az migrate server show-replication-status` | |
| 236 | + |
| 237 | +## Error Handling |
| 238 | + |
| 239 | +The module includes comprehensive error handling for: |
| 240 | + |
| 241 | +- Invalid project configurations |
| 242 | +- Permission and authentication issues |
| 243 | +- Resource not found scenarios |
| 244 | +- Azure service connectivity problems |
| 245 | +- PowerShell execution errors |
| 246 | +- Cross-platform compatibility issues |
| 247 | + |
| 248 | +## Troubleshooting |
| 249 | + |
| 250 | +### Common Issues |
| 251 | + |
| 252 | +**PowerShell Not Found** |
| 253 | +- On Windows: Install PowerShell Core or ensure Windows PowerShell is available |
| 254 | +- On Linux/macOS: Install PowerShell Core from https://github.com/PowerShell/PowerShell |
| 255 | +- Use `az migrate setup-env --install-powershell` for automatic installation guidance |
| 256 | + |
| 257 | +**Authentication Issues** |
| 258 | +- Use `az migrate auth check` to verify authentication status |
| 259 | +- Re-authenticate using `az migrate auth login` |
| 260 | +- Verify subscription context with `az migrate auth show-context` |
| 261 | + |
| 262 | +**Server Discovery Issues** |
| 263 | +- Confirm the appliance is properly configured |
| 264 | +- Verify network connectivity from appliance to Azure |
| 265 | +- Check that discovery is running on the appliance |
| 266 | +- Use `az migrate server list-discovered` to check for discovered servers |
| 267 | + |
| 268 | +**Permission Errors** |
| 269 | +- Ensure Azure Migrate Contributor role is assigned |
| 270 | +- Verify subscription-level permissions for creating resources |
| 271 | +- Check resource group permissions |
| 272 | + |
| 273 | +**Azure Local Specific Issues** |
| 274 | +- Verify Azure Stack HCI cluster is properly registered with Azure |
| 275 | +- Ensure proper networking between source and Azure Local target |
| 276 | +- Check that both source and target appliances are properly configured |
| 277 | +- Verify storage containers and logical networks are properly set up in Azure Local |
| 278 | +- Use `az migrate local init` to initialize infrastructure |
| 279 | + |
| 280 | +**Script Execution Errors** |
| 281 | +- Check PowerShell execution policy |
| 282 | +- Verify PowerShell module availability using `az migrate powershell check-module` |
| 283 | +- Review error messages for specific guidance |
| 284 | +- Use `az migrate check-prerequisites` to verify system requirements |
| 285 | + |
| 286 | +## Contributing |
| 287 | + |
| 288 | +When extending the migration module: |
| 289 | + |
| 290 | +1. Follow Azure CLI command naming conventions |
| 291 | +2. Implement proper error handling and validation |
| 292 | +3. Add comprehensive help documentation |
| 293 | +4. Include usage examples in help text |
| 294 | +5. Update this README with new command examples |
| 295 | +6. Ensure cross-platform PowerShell compatibility |
| 296 | +7. Add appropriate parameter validation |
| 297 | +8. Include integration tests for new commands |
| 298 | + |
| 299 | +For more information on Azure Migrate, visit: https://docs.microsoft.com/azure/migrate/ |
| 300 | + |
| 301 | +## License |
| 302 | + |
| 303 | +This project is licensed under the MIT License - see the LICENSE file for details. |
0 commit comments