Reputation: 31
I'm experimenting with Azure Resource Manager backups and restores using Recovery Services vaults in "Pay-As-You-Go" subscriptions. I am using very simple code that as far as I can tell is right out of MS documentation. I can get a vault object and I can get a container, but when I attempt to get any items out of any container, Get-AzureRmRecoveryServicesBackupItem always returns nothing, even when I know there are items in there and the Azure RM GUI confirms this. "Returns nothing" means if I assign the result to a variable it is empty/null, and if I try to output to the console there is no output.
I have had the same result with two different subscriptions, with different vaults, vm's and backup items, and from two different computers. I have re-installed modules on one machine and installed modules from scratch on the other. Using the -Debug switch for the Get-AzureRmRecoveryServicesBackupItem command appears to show the items being returned, with an OK result and no errors. Powershell code appears below, and -Debug output appears after that. The kicker is, this exact code was working on 2/7/17, no kidding. I'm about out of ideas at this point so any help would be appreciated.
Update: We have found that when we use the -FriendlyName parameter for the Get-AzureRmRecoveryServicesBackupContainer the problem occurs, but if we pipe the output through | Where-Object { $_.FriendlyName -eq $vmName } the problem does not occur. We have opened a case with MSFT.
$vaultName = 'somevault'
$resourceGroupName = 'somerg'
$vmName = 'testvm'
$vault = Get-AzureRmRecoveryServicesVault -Name $vaultName -ResourceGroupName $resourceGroupName;
Set-AzureRmRecoveryServicesVaultContext -Vault $vault
$container = Get-AzureRmRecoveryServicesBackupContainer -ContainerType AzureVM –Status Registered -FriendlyName $vmName
#output of this cmdlet is empty
Get-AzureRmRecoveryServicesBackupItem –Container $container -Debug
Debug output:
DEBUG: ============================ HTTP RESPONSE ============================
Status Code:
OK
Headers:
Pragma : no-cache
x-ms-request-id : xxx
x-ms-client-request-id : xxx
Strict-Transport-Security : max-age=31536000; includeSubDomains
x-ms-ratelimit-remaining-subscription-reads: 14930
x-ms-correlation-request-id : xxx
x-ms-routing-request-id : WESTUS:xxx
Cache-Control : no-cache
Date : Sat, 11 Feb 2017 19:39:07 GMT
Server : Microsoft-IIS/8.0
X-Powered-By : ASP.NET
Body:
{
"value": [
{
"id": "/Subscriptions/xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxxx/resourceGroups/VS-xxxxxxxxxxxxx-Group/providers/Microsoft.RecoveryServices/vaults/vault273/backupFabrics/Azure/protectionContainers/IaasVM
Container;iaasvmcontainerv2;VS-xxxxxxxxxxxxx-Group;testvm/protectedItems/VM;iaasvmcontainerv2;VS-xxxxxxxxxxxxx-Group;testvm",
"name": "iaasvmcontainerv2;VS-xxxxxxxxxxxxx-Group;testvm",
"type": "Microsoft.RecoveryServices/vaults/backupFabrics/protectionContainers/protectedItems",
"properties": {
"friendlyName": "testvm",
"virtualMachineId": "/subscriptions/xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxxx/resourceGroups/VS-xxxxxxxxxxxxx-Group/providers/Microsoft.Compute/virtualMachines/testvm",
"protectionStatus": "Healthy",
"protectionState": "Protected",
"healthStatus": "Passed",
"healthDetails": [
{
"code": 400239,
"title": "IaasVmHealthGreenDefault",
"message": "Backup pre-check status of this virtual machine is OK.",
"recommendations": []
}
],
"lastBackupStatus": "Completed",
"lastBackupTime": "2017-02-11T15:11:12.2071619Z",
"protectedItemDataId": "70368936803029",
"protectedItemType": "Microsoft.Compute/virtualMachines",
"backupManagementType": "AzureIaasVM",
"workloadType": "VM",
"containerName": "iaasvmcontainerv2;VS-xxxxxxxxxxxxx-Group;testvm",
"sourceResourceId": "/subscriptions/xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxxx/resourceGroups/VS-xxxxxxxxxxxxx-Group/providers/Microsoft.Compute/virtualMachines/testvm",
"policyId": "/Subscriptions/xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxxx/resourceGroups/VS-xxxxxxxxxxxxx-Group/providers/Microsoft.RecoveryServices/vaults/vault273/backupPolicies/DailyPolicy",
"policyName": "DailyPolicy",
"lastRecoveryPoint": "2017-02-11T15:12:16.7410628Z"
}
}
]
}
DEBUG: AzureQoSEvent: CommandName - Get-AzureRmRecoveryServicesBackupItem; IsSuccess - True; Duration - 00:00:02.3527163; Exception - ;
Upvotes: 1
Views: 1115
Reputation: 1032
Had the same issue (also on various PCs) and worked around it by passing a different parameters set. I'm not using the Get-AzureRmRecoveryServicesBackupContainer to get a reference to the container. Instead, I'm directly calling Get-AzureRmRecoveryServicesBackupItem with the container name. This only works when you pass the parameter -BackupManagementType AzureVM.
Login-AzureRmAccount
Select-AzureRmSubscription -SubscriptionId <myguid>
Get-AzureRmRecoveryServicesVault -Name "myvaultname" | Set-AzureRmRecoveryServicesVaultContext
$item = Get-AzureRmRecoveryServicesBackupItem -BackupManagementType AzureVM -WorkloadType AzureVM -Name "myname"
$latestRecoveryPoint = Get-AzureRmRecoveryServicesBackupRecoveryPoint -Item $item | Sort-Object RecoveryPointTime -Descending | Select-Object -First 1
If you leave out -Name, you get a list returned with all names.
Upvotes: 1