Azure / Azure/azure-powershell

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

Open
#25,943 4 comments 0 reactions 0 assignees View on GitHub
act-observability-squad bug customer-reported Recovery Services Backup Service Attention
Dominant language
C#
Stars
4.8k
Forks
4.3k
Avg merge
2d 17h
Merged PRs (30d)
51

Description

### 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

```PowerShell
#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

```PowerShell
$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

```PowerShell
.
```

### Error output

```PowerShell
No error provided in Powershell.
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.