Azure / azure-powershell

Microsoft Azure PowerShell
Other
4.21k stars 3.81k forks source link

Restore-AzRecoveryServicesBackupItem's "-RestoreOnlyOSDisk" does not function as designed. #25943

Open cdiskan opened 2 weeks ago

cdiskan commented 2 weeks ago

Description

When using Restore-AzRecoveryServicesBackupItem the -RestoreOnlyOSDisk does not function as designed.

Using the switch is accepted in Powershell, however the restore jobs that are created include all virtual disks associated with the restore point, not just the OS disk.

This can be confirmed by the JSON files created in the storage account used as a restore cache, which shows all disks included.

{ "plan": null, "properties.hardwareProfile": { "vmSize": "Standard_D2as_v5", "vmSizeProperties": null }, "properties.storageProfile": { "imageReference": null, "osDisk": { "osType": "Windows", "encryptionSettings": null, "name": "VMNAME-osdisk-20240826-184151", "vhd": { "uri": "https://STORAGEACCOUNTNAME.blob.core.windows.net/VMNAME-9ad779b5449840b79093574a90fd5eac/VMNAME-osdisk-20240826-184151.vhd" }, "image": null, "caching": "ReadWrite", "writeAcceleratorEnabled": null, "diffDiskSettings": null, "createOption": "Attach", "diskSizeGB": null, "managedDisk": null, "deleteOption": null }, "dataDisks": [ { "lun": 0, "name": "VMNAME-datadisk-000-20240826-184151", "vhd": { "uri": "https://STORAGEACCOUNTNAME.blob.core.windows.net/VMNAME-9ad779b5449840b79093574a90fd5eac/VMNAME-datadisk-000-20240826-184151.vhd" }, "image": null, "caching": "None", "writeAcceleratorEnabled": null, "createOption": "Attach", "diskSizeGB": null, "managedDisk": null, "toBeDetached": null, "diskIOPSReadWrite": null, "diskMBpsReadWrite": null, "detachOption": null, "deleteOption": null } ], "diskControllerType": null }, "properties.additionalCapabilities": null, "properties.osProfile": null, "properties.networkProfile": { "networkInterfaces": [ { "properties.primary": true, "properties.deleteOption": null, "id": "/subscriptions/SUBID/resourceGroups/RGNAME/providers/Microsoft.Network/networkInterfaces/nic-VMNAME-00" } ], "networkApiVersion": null, "networkInterfaceConfigurations": null }, "properties.securityProfile": null, "properties.diagnosticsProfile": null, "properties.availabilitySet": null, "properties.virtualMachineScaleSet": null, "properties.proximityPlacementGroup": null, "properties.priority": null, "properties.evictionPolicy": null, "properties.billingProfile": null, "properties.host": null, "properties.hostGroup": null, "properties.provisioningState": null, "properties.instanceView": null, "properties.licenseType": null, "properties.vmId": null, "properties.extensionsTimeBudget": null, "properties.platformFaultDomain": null, "properties.scheduledEventsProfile": null, "properties.userData": null, "properties.capacityReservation": null, "properties.applicationProfile": null, "properties.timeCreated": null, "resources": null, "identity": null, "zones": null, "extendedLocation": null, "id": null, "name": null, "type": null, "location": "eastus", "tags": { } }

Issue script & Debug output

#Need to connect-azaccount and select right subscription first.

# Set variables based on your provided values
$vaultName = "VAULTNAME"
$resourceGroupName = "RGNAME"
$vmName = "VMNAME"
$targetResourceGroupName = "RGNAME"  # Adjust if the target resource group differs
$storageAccountName = "STORAGEACCOUNTNAME" 
$storageAccountResourceGroupName = "STORAGEACCOUNTRGNAME"
# Set Recovery Services Vault context

$vault = Get-AzRecoveryServicesVault -ResourceGroupName $resourceGroupName -Name $vaultName

# Get the Backup Item (VM)
$BackupItem = Get-AzRecoveryServicesBackupItem -BackupManagementType "AzureVM" -WorkloadType "AzureVM" -Name $vmName -VaultId $vault.ID

# Get all available recovery points for the VM
$RP = Get-AzRecoveryServicesBackupRecoveryPoint -Item $BackupItem -VaultId $vault.ID

# Find the oldest recovery point by sorting the RecoveryPointTime
$OldestRP = $RP | Sort-Object RecoveryPointTime | Select-Object -First 1

# Restore only OS disk from the oldest recovery point
$RestoreJob = Restore-AzRecoveryServicesBackupItem -RecoveryPoint $OldestRP -TargetResourceGroupName $targetResourceGroupName -StorageAccountName $storageAccountName -StorageAccountResourceGroupName $storageAccountResourceGroupName -RestoreOnlyOSDisk -VaultId $vault.ID -VaultLocation $vault.Location 

# Output the status of the restore job
$RestoreJob | Format-Table WorkloadName, Operation, Status, StartTime, EndTime

Environment data

$PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.4.4
PSEdition                      Core
GitCommitId                    7.4.4
OS                             Microsoft Windows 10.0.22631
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Module versions

.

Error output

No error provided in Powershell.
microsoft-github-policy-service[bot] commented 2 weeks ago

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @Daya-Patil.

microsoft-github-policy-service[bot] commented 2 weeks ago

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @Daya-Patil.

hiaga commented 2 weeks ago

Please share the the debug logs for Restore-AzRecoveryServicesBackupItem command after adding -Debug parameter